[MM-25268] Implement prefix/suffix searching on teams and channel page in system console (#14698)
* Implement prefix/suffix search on teams page * Make Channel Page prefix/suffix search as well * address PR comments * add tests * fix styling * take postgres into account * add more api tests * update test * add team store test * write store test for team and channel * fix lint * update description * revert go mod Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
92c98dac3e
Коммит
2c9c58ff50
@@ -1152,11 +1152,91 @@ func TestSearchAllChannels(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
|
||||
search := &model.ChannelSearch{Term: th.BasicChannel.Name}
|
||||
channel := &model.Channel{
|
||||
DisplayName: "FOOBAR",
|
||||
Name: "whatever",
|
||||
Type: model.CHANNEL_OPEN,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
}
|
||||
|
||||
// Testing Mixed Case (Ensure we get results for partial word searches)
|
||||
|
||||
// Search by using display name
|
||||
foobarchannel, err := th.SystemAdminClient.CreateChannel(channel)
|
||||
CheckNoError(t, err)
|
||||
|
||||
search := &model.ChannelSearch{Term: "oob"}
|
||||
|
||||
channels, resp := th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, foobarchannel.Id, (*channels)[0].Id)
|
||||
|
||||
search = &model.ChannelSearch{Term: "foo"}
|
||||
|
||||
channels, resp = th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, foobarchannel.Id, (*channels)[0].Id)
|
||||
|
||||
search = &model.ChannelSearch{Term: "bar"}
|
||||
|
||||
channels, resp = th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, foobarchannel.Id, (*channels)[0].Id)
|
||||
|
||||
// Search by using Name
|
||||
search = &model.ChannelSearch{Term: "what"}
|
||||
|
||||
channels, resp = th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, foobarchannel.Id, (*channels)[0].Id)
|
||||
|
||||
search = &model.ChannelSearch{Term: "ever"}
|
||||
|
||||
channels, resp = th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
// Seach by partial word search and testing case sensitivty
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, foobarchannel.Id, (*channels)[0].Id)
|
||||
|
||||
search = &model.ChannelSearch{Term: th.BasicChannel.Name[2:14]}
|
||||
|
||||
channels, resp = th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, th.BasicChannel.Id, (*channels)[0].Id)
|
||||
|
||||
search = &model.ChannelSearch{Term: strings.ToUpper(th.BasicChannel.Name)}
|
||||
|
||||
channels, resp = th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, th.BasicChannel.Id, (*channels)[0].Id)
|
||||
|
||||
search = &model.ChannelSearch{Term: th.BasicChannel.Name[0:2] + strings.ToUpper(th.BasicChannel.Name[2:5]) + th.BasicChannel.Name[5:]}
|
||||
|
||||
channels, resp = th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, th.BasicChannel.Id, (*channels)[0].Id)
|
||||
|
||||
// Testing Non-Mixed Case test cases
|
||||
search = &model.ChannelSearch{Term: th.BasicChannel.Name}
|
||||
|
||||
channels, resp = th.SystemAdminClient.SearchAllChannels(search)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
assert.Len(t, *channels, 1)
|
||||
assert.Equal(t, th.BasicChannel.Id, (*channels)[0].Id)
|
||||
|
||||
|
||||
@@ -1220,18 +1220,74 @@ func TestSearchAllTeamsPaged(t *testing.T) {
|
||||
teams[i] = newTeam
|
||||
}
|
||||
|
||||
foobarTeam, err := th.App.CreateTeam(&model.Team{
|
||||
DisplayName: "FOOBAR",
|
||||
Name: "whatever",
|
||||
Type: model.TEAM_OPEN,
|
||||
Email: th.GenerateTestEmail(),
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Search *model.TeamSearch
|
||||
ExpectedTeams []string
|
||||
ExpectedTotalCount int64
|
||||
}{
|
||||
{
|
||||
Name: "Get foobar channel",
|
||||
Search: &model.TeamSearch{Term: "oob", Page: model.NewInt(0), PerPage: model.NewInt(100)},
|
||||
ExpectedTeams: []string{foobarTeam.Id},
|
||||
ExpectedTotalCount: 1,
|
||||
},
|
||||
{
|
||||
Name: "Get foobar channel",
|
||||
Search: &model.TeamSearch{Term: "foo", Page: model.NewInt(0), PerPage: model.NewInt(100)},
|
||||
ExpectedTeams: []string{foobarTeam.Id},
|
||||
ExpectedTotalCount: 1,
|
||||
},
|
||||
{
|
||||
Name: "Get foobar channel",
|
||||
Search: &model.TeamSearch{Term: "bar", Page: model.NewInt(0), PerPage: model.NewInt(100)},
|
||||
ExpectedTeams: []string{foobarTeam.Id},
|
||||
ExpectedTotalCount: 1,
|
||||
},
|
||||
{
|
||||
Name: "Get foobar channel",
|
||||
Search: &model.TeamSearch{Term: "what", Page: model.NewInt(0), PerPage: model.NewInt(100)},
|
||||
ExpectedTeams: []string{foobarTeam.Id},
|
||||
ExpectedTotalCount: 1,
|
||||
},
|
||||
{
|
||||
Name: "Get foobar channel",
|
||||
Search: &model.TeamSearch{Term: "ever", Page: model.NewInt(0), PerPage: model.NewInt(100)},
|
||||
ExpectedTeams: []string{foobarTeam.Id},
|
||||
ExpectedTotalCount: 1,
|
||||
},
|
||||
{
|
||||
Name: "Get all teams on one page",
|
||||
Search: &model.TeamSearch{Term: commonRandom, Page: model.NewInt(0), PerPage: model.NewInt(100)},
|
||||
ExpectedTeams: []string{teams[0].Id, teams[1].Id, teams[2].Id},
|
||||
ExpectedTotalCount: 3,
|
||||
},
|
||||
{
|
||||
Name: "Get all teams on one page with partial word",
|
||||
Search: &model.TeamSearch{Term: commonRandom[11:18]},
|
||||
ExpectedTeams: []string{teams[0].Id, teams[1].Id, teams[2].Id},
|
||||
ExpectedTotalCount: 3,
|
||||
},
|
||||
{
|
||||
Name: "Get all teams on one page with term upper cased",
|
||||
Search: &model.TeamSearch{Term: strings.ToUpper(commonRandom)},
|
||||
ExpectedTeams: []string{teams[0].Id, teams[1].Id, teams[2].Id},
|
||||
ExpectedTotalCount: 3,
|
||||
},
|
||||
{
|
||||
Name: "Get all teams on one page with some of term upper and some lower",
|
||||
Search: &model.TeamSearch{Term: commonRandom[0:11] + strings.ToUpper(commonRandom[11:18]+commonRandom[18:])},
|
||||
ExpectedTeams: []string{teams[0].Id, teams[1].Id, teams[2].Id},
|
||||
ExpectedTotalCount: 3,
|
||||
},
|
||||
{
|
||||
Name: "Get 2 teams on the first page",
|
||||
Search: &model.TeamSearch{Term: commonRandom, Page: model.NewInt(0), PerPage: model.NewInt(2)},
|
||||
|
||||
Ссылка в новой задаче
Block a user