Skip to content

Commit 34ddb9d

Browse files
committed
Test(web): cover edge cases in search highlightMatch
Signed-off-by: mday-io <mdaytn@gmail.com>
1 parent 9337af5 commit 34ddb9d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎web/client/src/library/components/search/tests/SearchList.spec.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ describe('highlightMatch', () => {
1212
])
1313
})
1414

15+
it('should handle adjacent matches and matches at the edges', () => {
16+
expect(highlightMatch('abab', 'ab')).toEqual([
17+
{ text: 'ab', isMatch: true },
18+
{ text: 'ab', isMatch: true },
19+
])
20+
expect(highlightMatch('xab', 'ab')).toEqual([
21+
{ text: 'x', isMatch: false },
22+
{ text: 'ab', isMatch: true },
23+
])
24+
})
25+
26+
it('should return no parts for an empty source', () => {
27+
expect(highlightMatch('', 'ab')).toEqual([])
28+
})
29+
1530
it('should return the whole source when there is no match', () => {
1631
expect(highlightMatch('abc', '')).toEqual([{ text: 'abc', isMatch: false }])
1732
expect(highlightMatch('abc', 'x')).toEqual([

0 commit comments

Comments
 (0)