quote names when using recent mention search (#28119)
Этот коммит содержится в:
@@ -53,6 +53,8 @@ import type {ViewsState} from 'types/store/views';
|
||||
const currentChannelId = '123';
|
||||
const currentTeamId = '321';
|
||||
const currentUserId = 'user123';
|
||||
const currentUsername = 'user-name';
|
||||
const currentUserFirstName = 'first-name';
|
||||
const pluggableId = 'pluggableId';
|
||||
const previousSelectedPost = {
|
||||
id: 'post123',
|
||||
@@ -102,6 +104,8 @@ describe('rhs view actions', () => {
|
||||
currentUserId,
|
||||
profiles: {
|
||||
user123: {
|
||||
username: currentUsername,
|
||||
first_name: currentUserFirstName,
|
||||
timezone: {
|
||||
useAutomaticTimezone: true,
|
||||
automaticTimezone: '',
|
||||
@@ -214,22 +218,50 @@ describe('rhs view actions', () => {
|
||||
});
|
||||
|
||||
describe('performSearch', () => {
|
||||
const terms = '@here test search';
|
||||
// timezone offset in seconds
|
||||
const timeZoneOffset = getBrowserUtcOffset() * 60;
|
||||
|
||||
test('it dispatches searchPosts correctly', () => {
|
||||
const terms = '@here test search';
|
||||
store.dispatch(performSearch(terms, false));
|
||||
|
||||
// timezone offset in seconds
|
||||
const timeZoneOffset = getBrowserUtcOffset() * 60;
|
||||
|
||||
const compareStore = mockStore(initialState);
|
||||
compareStore.dispatch(SearchActions.searchPostsWithParams(currentTeamId, {include_deleted_channels: false, terms, is_or_search: false, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||
compareStore.dispatch(SearchActions.searchFilesWithParams(currentTeamId, {include_deleted_channels: false, terms, is_or_search: false, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||
|
||||
expect(store.getActions()).toEqual(compareStore.getActions());
|
||||
});
|
||||
|
||||
test('it dispatches searchFiles correctly', () => {
|
||||
store = mockStore({
|
||||
...initialState,
|
||||
views: {
|
||||
...initialState.views,
|
||||
rhs: {
|
||||
...initialState.views.rhs,
|
||||
filesSearchExtFilter: ['txt', 'jpeg'],
|
||||
},
|
||||
} as ViewsState,
|
||||
});
|
||||
|
||||
const terms = '@here test search';
|
||||
store.dispatch(performSearch(terms, false));
|
||||
|
||||
const filesExtTerms = '@here test search ext:txt ext:jpeg';
|
||||
const compareStore = mockStore(initialState);
|
||||
compareStore.dispatch(SearchActions.searchPostsWithParams(currentTeamId, {include_deleted_channels: false, terms, is_or_search: false, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||
compareStore.dispatch(SearchActions.searchFilesWithParams(currentTeamId, {include_deleted_channels: false, terms: filesExtTerms, is_or_search: false, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||
|
||||
expect(store.getActions()).toEqual(compareStore.getActions());
|
||||
});
|
||||
|
||||
test('it dispatches searchPosts correctly for Recent Mentions', () => {
|
||||
const terms = `@here test search ${currentUsername} @${currentUsername} ${currentUserFirstName}`;
|
||||
store.dispatch(performSearch(terms, true));
|
||||
compareStore.dispatch(SearchActions.searchPostsWithParams('', {include_deleted_channels: false, terms, is_or_search: true, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||
|
||||
const mentionsQuotedTerms = `@here test search "${currentUsername}" "@${currentUsername}" "${currentUserFirstName}"`;
|
||||
const compareStore = mockStore(initialState);
|
||||
compareStore.dispatch(SearchActions.searchPostsWithParams('', {include_deleted_channels: false, terms: mentionsQuotedTerms, is_or_search: true, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||
compareStore.dispatch(SearchActions.searchFilesWithParams(currentTeamId, {include_deleted_channels: false, terms, is_or_search: true, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||
|
||||
expect(store.getActions()).toEqual(compareStore.getActions());
|
||||
|
||||
@@ -202,16 +202,18 @@ export function performSearch(terms: string, isMentionSearch?: boolean): ThunkAc
|
||||
}
|
||||
|
||||
if (isMentionSearch) {
|
||||
// Username should be quoted to allow specific search
|
||||
// in case username is made with multiple words splitted by dashes or other symbols.
|
||||
// Username and FirstName should be quoted to allow specific search
|
||||
// in case the name is made with multiple words splitted by dashes or other symbols.
|
||||
const user = getCurrentUser(getState());
|
||||
const termsArr = searchTerms.split(' ').filter((t) => Boolean(t && t.trim()));
|
||||
const username = '@' + user.username;
|
||||
const quotedUsername = `"${username}"`;
|
||||
const atUsername = '@' + user.username;
|
||||
for (let i = 0; i < termsArr.length; i++) {
|
||||
if (termsArr[i] === username) {
|
||||
termsArr[i] = quotedUsername;
|
||||
break;
|
||||
if (termsArr[i] === atUsername) {
|
||||
termsArr[i] = `"${atUsername}"`;
|
||||
} else if (termsArr[i] === user.username) {
|
||||
termsArr[i] = `"${user.username}"`;
|
||||
} else if (termsArr[i] === user.first_name) {
|
||||
termsArr[i] = `"${user.first_name}"`;
|
||||
}
|
||||
}
|
||||
searchTerms = termsArr.join(' ');
|
||||
|
||||
Ссылка в новой задаче
Block a user