MM-55208 allow search prefixes (#28146)
* Ignore at and tilde for username and channel searches. * allow using tilde in search suggestions --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5d8bf5f97b
Коммит
41bca03270
@@ -1767,6 +1767,48 @@ func TestSearchPostsForUser(t *testing.T) {
|
||||
assert.Equal(t, []string{}, results.Order)
|
||||
es.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("should return the same results if there is a tilde in the channel name", func(t *testing.T) {
|
||||
th, _ := setup(t, false)
|
||||
defer th.TearDown()
|
||||
|
||||
page := 0
|
||||
|
||||
searchQueryWithPrefix := fmt.Sprintf("in:~%s %s", th.BasicChannel.Name, searchTerm)
|
||||
|
||||
resultsWithPrefix, err := th.App.SearchPostsForUser(th.Context, searchQueryWithPrefix, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
assert.Nil(t, err)
|
||||
assert.Greater(t, len(resultsWithPrefix.PostList.Posts), 0, "searching using a tilde in front of a channel should return results")
|
||||
searchQueryWithoutPrefix := fmt.Sprintf("in:%s %s", th.BasicChannel.Name, searchTerm)
|
||||
|
||||
resultsWithoutPrefix, err := th.App.SearchPostsForUser(th.Context, searchQueryWithoutPrefix, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, len(resultsWithPrefix.Posts), len(resultsWithoutPrefix.Posts), "searching using a tilde in front of a channel should return the same number of results")
|
||||
for k, v := range resultsWithPrefix.Posts {
|
||||
assert.Equal(t, v, resultsWithoutPrefix.Posts[k], "post at %s was different", k)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should return the same results if there is an 'at' in the user", func(t *testing.T) {
|
||||
th, _ := setup(t, false)
|
||||
defer th.TearDown()
|
||||
|
||||
page := 0
|
||||
|
||||
searchQueryWithPrefix := fmt.Sprintf("from:@%s %s", th.BasicUser.Username, searchTerm)
|
||||
|
||||
resultsWithPrefix, err := th.App.SearchPostsForUser(th.Context, searchQueryWithPrefix, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
assert.Nil(t, err)
|
||||
assert.Greater(t, len(resultsWithPrefix.PostList.Posts), 0, "searching using a 'at' symbol in front of a channel should return results")
|
||||
searchQueryWithoutPrefix := fmt.Sprintf("from:@%s %s", th.BasicUser.Username, searchTerm)
|
||||
|
||||
resultsWithoutPrefix, err := th.App.SearchPostsForUser(th.Context, searchQueryWithoutPrefix, th.BasicUser.Id, th.BasicTeam.Id, false, false, 0, page, perPage)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, len(resultsWithPrefix.Posts), len(resultsWithoutPrefix.Posts), "searching using an 'at' symbol in front of a channel should return the same number of results")
|
||||
for k, v := range resultsWithPrefix.Posts {
|
||||
assert.Equal(t, v, resultsWithoutPrefix.Posts[k], "post at %s was different", k)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCountMentionsFromPost(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user