Include @mentioned names in search results
This commit is contained in:
parent
e3c6b4d9b1
commit
9c6fb29edb
14 changed files with 1052 additions and 126 deletions
56
ts/test-both/util/searchConversationTitles_test.ts
Normal file
56
ts/test-both/util/searchConversationTitles_test.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { getDefaultConversation } from '../helpers/getDefaultConversation';
|
||||
import { searchConversationTitles } from '../../util/searchConversationTitles';
|
||||
|
||||
describe('searchContactTitles', () => {
|
||||
const conversations = [
|
||||
getDefaultConversation({
|
||||
title: 'Ally Apple',
|
||||
}),
|
||||
getDefaultConversation({
|
||||
title: 'Betty Banana',
|
||||
}),
|
||||
getDefaultConversation({
|
||||
title: 'Catty Cantaloupe',
|
||||
}),
|
||||
getDefaultConversation({
|
||||
title: 'Debby Dancing Date',
|
||||
}),
|
||||
];
|
||||
|
||||
function assertSearchEquals(
|
||||
terms: Array<string>,
|
||||
expectedTitles: Array<string>,
|
||||
message?: string
|
||||
) {
|
||||
const titles = searchConversationTitles(conversations, terms).map(
|
||||
contact => contact.title
|
||||
);
|
||||
|
||||
assert.sameMembers(titles, expectedTitles, message);
|
||||
}
|
||||
|
||||
it('matches full name components', () => {
|
||||
assertSearchEquals(['ally'], ['Ally Apple'], 'first name');
|
||||
assertSearchEquals(['apple'], ['Ally Apple'], 'last name');
|
||||
assertSearchEquals(['danc'], ['Debby Dancing Date'], 'middle name');
|
||||
});
|
||||
|
||||
it('matches based on name component prefix', () => {
|
||||
assertSearchEquals(['all'], ['Ally Apple']);
|
||||
assertSearchEquals(['app'], ['Ally Apple']);
|
||||
});
|
||||
|
||||
it('does not return single character matches', () => {
|
||||
assertSearchEquals(['a'], []);
|
||||
assertSearchEquals([], []);
|
||||
});
|
||||
|
||||
it('only returns prefix matches', () => {
|
||||
assertSearchEquals(['lly'], []);
|
||||
assertSearchEquals(['anana'], []);
|
||||
});
|
||||
});
|
53
ts/test-both/util/search_test.ts
Normal file
53
ts/test-both/util/search_test.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { generateSnippetAroundMention } from '../../util/search';
|
||||
|
||||
describe('generateSnippetAroundMention', () => {
|
||||
it('generates snippet around mention at start of body', () => {
|
||||
const snippet = generateSnippetAroundMention({
|
||||
body: ' can you sing that again but in the voice of Mr. Snuffleupagus?',
|
||||
mentionStart: 0,
|
||||
mentionLength: 1,
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
snippet,
|
||||
'<<left>> <<right>> can you sing that again but in the voice of Mr<<truncation>>'
|
||||
);
|
||||
});
|
||||
it('generates snippet around mention in middle of body', () => {
|
||||
const snippet = generateSnippetAroundMention({
|
||||
body: 'Stevie can you sing that again with but in the voice of Mr. Snuffleupagus?',
|
||||
mentionStart: 36,
|
||||
mentionLength: 1,
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
snippet,
|
||||
'<<truncation>>you sing that again with <<left>> <<right>> but in the voice of Mr<<truncation>>'
|
||||
);
|
||||
});
|
||||
it('generates snippet around mention at end of body', () => {
|
||||
const snippet = generateSnippetAroundMention({
|
||||
body: 'Stevie can you sing that again but in the voice of ',
|
||||
mentionStart: 51,
|
||||
mentionLength: 1,
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
snippet,
|
||||
'<<truncation>>again but in the voice of <<left>> <<right>>'
|
||||
);
|
||||
});
|
||||
it('generates snippet around mention-only body', () => {
|
||||
const snippet = generateSnippetAroundMention({
|
||||
body: ' ',
|
||||
mentionStart: 0,
|
||||
mentionLength: 1,
|
||||
});
|
||||
|
||||
assert.strictEqual(snippet, '<<left>> <<right>>');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue