Skip to content

Commit a63c9bf

Browse files
committed
Add test for matching with default tags
1 parent 0292c15 commit a63c9bf

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

packages/autocomplete-client/src/search/__tests__/fetchMeilisearchResults.test.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
dataset,
55
meilisearchClient,
66
} from '../../../__tests__/test.utils'
7+
import { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG } from '../../constants'
78

89
beforeAll(async () => {
910
await meilisearchClient.deleteIndex('testUid')
@@ -49,9 +50,55 @@ describe('fetchMeilisearchResults', () => {
4950
})
5051

5152
expect(results[0].hits[0].id).toEqual(2)
53+
})
54+
55+
test('with highlighting metadata', async () => {
56+
const results = await fetchMeilisearchResults({
57+
searchClient,
58+
queries: [
59+
{
60+
indexName: 'testUid',
61+
query: 'Hit',
62+
},
63+
],
64+
})
65+
5266
expect(results[0].hits[0]._highlightResult).toEqual({
53-
id: { value: '2' },
54-
label: { value: '<test>Hit</test> 2' },
67+
id: {
68+
value: '1',
69+
fullyHighlighted: false,
70+
matchLevel: 'none',
71+
matchedWords: [],
72+
},
73+
label: {
74+
value: `${HIGHLIGHT_PRE_TAG}Hit${HIGHLIGHT_POST_TAG} 1`,
75+
fullyHighlighted: false,
76+
matchLevel: 'partial',
77+
matchedWords: ['Hit'],
78+
},
5579
})
5680
})
81+
82+
// test('with fully highlighted match', async () => {
83+
// const results = await fetchMeilisearchResults({
84+
// searchClient,
85+
// queries: [
86+
// {
87+
// indexName: 'testUid',
88+
// query: 'Hit 2',
89+
// params: {
90+
// highlightPreTag: '<test>',
91+
// highlightPostTag: '</test>',
92+
// },
93+
// },
94+
// ],
95+
// })
96+
97+
// expect(results[0].hits[0]._highlightResult?.label).toEqual({
98+
// value: '<test>Hit</test> <test>2</test>',
99+
// fullyHighlighted: true,
100+
// matchLevel: 'full',
101+
// matchedWords: ['Hit', '2'],
102+
// })
103+
// })
57104
})

0 commit comments

Comments
 (0)