[MM-58562] View Members search matches entire string for the Position field instead of each word (#27384)

Этот коммит содержится в:
Matheus
2024-08-19 04:19:18 -07:00
коммит произвёл GitHub
родитель e666f7ccfc
Коммит db626377bf
3 изменённых файлов: 55 добавлений и 1 удалений

Просмотреть файл

@@ -28,6 +28,7 @@ describe('Selectors.Users', () => {
const group2 = TestHelper.fakeGroupWithId('');
const user1 = TestHelper.fakeUserWithId('');
user1.position = 'Software Engineer at Mattermost';
user1.notify_props = {mention_keys: 'testkey1,testkey2'} as UserProfile['notify_props'];
user1.roles = 'system_admin system_user';
const user2 = TestHelper.fakeUserWithId();
@@ -402,6 +403,7 @@ describe('Selectors.Users', () => {
it('searchProfilesInCurrentChannel', () => {
expect(Selectors.searchProfilesInCurrentChannel(testState, user1.username)).toEqual([user1]);
expect(Selectors.searchProfilesInCurrentChannel(testState, 'engineer at mattermost')).toEqual([user1]);
expect(Selectors.searchProfilesInCurrentChannel(testState, user1.username, true)).toEqual([]);
});

Просмотреть файл

@@ -9,6 +9,7 @@ import {
getSuggestionsSplitByMultiple,
includesAnAdminRole,
applyRolesFilters,
nameSuggestionsForUser,
} from 'mattermost-redux/utils/user_utils';
import TestHelper from '../../test/test_helper';
@@ -59,6 +60,56 @@ describe('user utils', () => {
});
});
describe('nameSuggestionsForUser', () => {
const userObj = TestHelper.getUserMock({
username: 'test.user',
nickname: 'tester',
first_name: 'Test',
last_name: 'UsEr NaMe',
position: 'Software Engineer at Mattermost',
email: 'test.user_name@example.com',
});
it('should return correct suggestions for user', () => {
const suggestions = nameSuggestionsForUser(userObj);
const expectedSuggestions = [
'test.user', '.user', 'user',
'test', 'user name', 'test user name', 'tester',
'software engineer at mattermost', 'engineer at mattermost', 'at mattermost', 'mattermost',
'test.user_name@example.com', 'example.com',
];
expect(suggestions).toEqual(expectedSuggestions);
});
it('should gracefully handle missing values for fields', () => {
const suggestions: string[] = nameSuggestionsForUser({...userObj,
username: '',
nickname: '',
first_name: '',
last_name: '',
position: '',
email: '',
});
expect(suggestions).toEqual(expect.arrayContaining(['']));
});
it('should handle different split username characters correctly', () => {
const suggestions: string[] = nameSuggestionsForUser({...userObj, username: 'john-doe_jr'});
const expectedUsernameSuggestions: string[] = [
'john-doe_jr', '-doe_jr', 'doe_jr', '_jr', 'jr',
];
expect(suggestions).toEqual(expect.arrayContaining(expectedUsernameSuggestions));
});
it('should split position on whitespace', () => {
const suggestions: string[] = nameSuggestionsForUser({...userObj, position: 'test-position split is corre_ct'});
const expectedPositionSuggestions: string[] = [
'test-position split is corre_ct', 'split is corre_ct', 'is corre_ct', 'corre_ct',
];
expect(suggestions).toEqual(expect.arrayContaining(expectedPositionSuggestions));
});
});
describe('filterProfilesStartingWithTerm', () => {
const userA = TestHelper.getUserMock({
id: '100',

Просмотреть файл

@@ -158,7 +158,8 @@ export function nameSuggestionsForUser(user: UserProfile): string[] {
const full = first + ' ' + last;
profileSuggestions.push(first, last, full);
profileSuggestions.push((user.nickname || '').toLowerCase());
profileSuggestions.push((user.position || '').toLowerCase());
const positionSuggestions = getSuggestionsSplitBy((user.position || '').toLowerCase(), ' ');
profileSuggestions.push(...positionSuggestions);
const email = (user.email || '').toLowerCase();
profileSuggestions.push(email);