Highlight multiple words in search result snippet

This commit is contained in:
trevor-signal
2023-06-21 12:35:48 -04:00
committed by GitHub
parent 83c1acedd8
commit 0afe124c68
3 changed files with 59 additions and 16 deletions

View File

@@ -727,6 +727,27 @@ describe('BodyRanges', () => {
});
});
it('returns proper bodyRange surrounding multiple keywords', () => {
const { cleanedSnippet, bodyRanges } = processBodyRangesForSearchResult({
snippet: "What's <<left>>going<<right>> <<left>>on<<right>>?",
body: "What's going on?",
bodyRanges: [],
});
assert.strictEqual(cleanedSnippet, "What's going on?");
assert.lengthOf(bodyRanges, 2);
assert.deepEqual(bodyRanges[0], {
start: 7,
length: 5,
displayStyle: DisplayStyle.SearchKeywordHighlight,
});
assert.deepEqual(bodyRanges[1], {
start: 13,
length: 2,
displayStyle: DisplayStyle.SearchKeywordHighlight,
});
});
it('returns proper bodyRange surrounding keyword, with trailing ...', () => {
const { cleanedSnippet, bodyRanges } = processBodyRangesForSearchResult({
snippet: "What's <<left>>going<<right>> on<<truncation>>",