-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
408: Add snippet/highlight/pagination integration tests r=bidoubiwa a=bidoubiwa see #389 Unit tests have also been added see: #387 Co-authored-by: Charlotte Vermandel <charlottevermandel@gmail.com>
- Loading branch information
Showing
6 changed files
with
502 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
import { searchClient, dataset } from './assets/utils' | ||
|
||
describe('Highlight Browser test', () => { | ||
beforeAll(async () => { | ||
try { | ||
await searchClient.MeiliSearchClient.deleteIndex('movies') | ||
} catch (e) { | ||
// movies does not exist | ||
} | ||
await searchClient.MeiliSearchClient.index( | ||
'movies' | ||
).updateAttributesForFaceting(['genres']) | ||
const moviesUpdate = await searchClient.MeiliSearchClient.index( | ||
'movies' | ||
).addDocuments(dataset) | ||
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate( | ||
moviesUpdate.updateId | ||
) | ||
}) | ||
|
||
test('Test one attributesToHighlight on placeholder', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: '', | ||
attributesToHighlight: ['name'], | ||
}, | ||
}, | ||
]) | ||
const resKeys = Object.keys(response.results[0].hits[0]._highlightResult) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
}) | ||
|
||
test('Test no attributesToHighlight on placeholder', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: '', | ||
attributesToHighlight: [], | ||
}, | ||
}, | ||
]) | ||
const resKeys = Object.keys(response.results[0].hits[0]._highlightResult) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
}) | ||
|
||
test('Test one attributesToHighlight on specific query', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: 'Ar', | ||
attributesToHighlight: ['title'], | ||
}, | ||
}, | ||
]) | ||
// | ||
const highlightedResults = response.results[0].hits[0]._highlightResult | ||
const resKeys = Object.keys(highlightedResults) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
expect(highlightedResults.title?.value).toEqual( | ||
'__ais-highlight__Ar__/ais-highlight__iel' | ||
) | ||
}) | ||
|
||
test('Test two attributesToHighlight on specific query', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: 'S', | ||
attributesToHighlight: ['title', 'overview'], | ||
}, | ||
}, | ||
]) | ||
|
||
const highlightedResults = response.results[0].hits[0]._highlightResult | ||
const resKeys = Object.keys(highlightedResults) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
expect(highlightedResults.title?.value).toEqual( | ||
'__ais-highlight__S__/ais-highlight__tar Wars' | ||
) | ||
expect(highlightedResults.overview?.value).toEqual( | ||
expect.stringMatching('__ais-highlight__S__/ais-highlight__kywalker') | ||
) | ||
}) | ||
|
||
test('Test two attributesToHighlight on specific query with empty string value', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: 'Magnetic', | ||
attributesToHighlight: ['title', 'overview'], | ||
}, | ||
}, | ||
]) | ||
|
||
const highlightedResults = response.results[0].hits[0]._highlightResult | ||
const resKeys = Object.keys(highlightedResults) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
expect(highlightedResults.title?.value).toEqual( | ||
'__ais-highlight__Magnetic__/ais-highlight__ Rose' | ||
) | ||
expect(highlightedResults.overview?.value).toEqual( | ||
expect.not.stringMatching('__ais-highlight__Magnetic__/ais-highlight__') | ||
) | ||
}) | ||
|
||
test('Test two attributesToHighlight on specific query with null value', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: 'Magnetic', | ||
attributesToHighlight: ['title', 'overview'], | ||
}, | ||
}, | ||
]) | ||
const highlightedResults = response.results[0].hits[0]._highlightResult | ||
const resKeys = Object.keys(highlightedResults) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
expect(highlightedResults.title?.value).toEqual( | ||
'__ais-highlight__Magnetic__/ais-highlight__ Rose' | ||
) | ||
expect(highlightedResults.overview?.value).toEqual( | ||
expect.not.stringMatching('__ais-highlight__Magnetic__/ais-highlight__') | ||
) | ||
}) | ||
|
||
test('Test two attributesToHighlight on specific query with null value', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: 'Magnetic', | ||
attributesToHighlight: ['title', 'overview'], | ||
}, | ||
}, | ||
]) | ||
const highlightedResults = response.results[0].hits[0]._highlightResult | ||
const resKeys = Object.keys(highlightedResults) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
expect(highlightedResults.title?.value).toEqual( | ||
'__ais-highlight__Magnetic__/ais-highlight__ Rose' | ||
) | ||
expect(highlightedResults.overview?.value).toEqual( | ||
expect.not.stringMatching('__ais-highlight__Magnetic__/ais-highlight__') | ||
) | ||
}) | ||
|
||
test('Test two attributesToHighlight on wild card', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: 'S', | ||
attributesToHighlight: ['title', 'overview'], | ||
}, | ||
}, | ||
]) | ||
|
||
const highlightedResults = response.results[0].hits[0]._highlightResult | ||
const resKeys = Object.keys(highlightedResults) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
expect(highlightedResults.title?.value).toEqual( | ||
'__ais-highlight__S__/ais-highlight__tar Wars' | ||
) | ||
expect(highlightedResults.overview?.value).toEqual( | ||
expect.stringMatching('__ais-highlight__S__/ais-highlight__kywalker') | ||
) | ||
}) | ||
|
||
test('Test two attributesToHighlight with different tags', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: 'S', | ||
attributesToHighlight: ['title', 'overview'], | ||
highlightPreTag: '<p>', | ||
highlightPostTag: '</p>', | ||
}, | ||
}, | ||
]) | ||
|
||
const highlightedResults = response.results[0].hits[0]._highlightResult | ||
const resKeys = Object.keys(highlightedResults) | ||
expect(resKeys).toEqual(expect.arrayContaining(Object.keys(dataset[0]))) | ||
expect(highlightedResults.title?.value).toEqual('<p>S</p>tar Wars') | ||
expect(highlightedResults.overview?.value).toEqual( | ||
expect.stringMatching('<p>S</p>olo') | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { searchClient, dataset } from './assets/utils' | ||
|
||
describe('Pagination browser test', () => { | ||
beforeAll(async () => { | ||
try { | ||
await searchClient.MeiliSearchClient.deleteIndex('movies') | ||
} catch (e) { | ||
// movies does not exist | ||
} | ||
await searchClient.MeiliSearchClient.index( | ||
'movies' | ||
).updateAttributesForFaceting(['genres']) | ||
const moviesUpdate = await searchClient.MeiliSearchClient.index( | ||
'movies' | ||
).addDocuments(dataset) | ||
await searchClient.MeiliSearchClient.index('movies').waitForPendingUpdate( | ||
moviesUpdate.updateId | ||
) | ||
}) | ||
|
||
test('Test 1 hitsPerPage', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: '', | ||
hitsPerPage: 1, | ||
}, | ||
}, | ||
]) | ||
const hits = response.results[0].hits | ||
expect(hits.length).toBe(1) | ||
expect(hits[0].title).toBe('Ariel') | ||
}) | ||
|
||
test('Test 1 hitsPerPage w/ page 0 ', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: '', | ||
hitsPerPage: 1, | ||
page: 0, | ||
}, | ||
}, | ||
]) | ||
const hits = response.results[0].hits | ||
expect(hits.length).toBe(1) | ||
expect(hits[0].title).toBe('Ariel') | ||
}) | ||
|
||
test('Test 1 hitsPerPage w/ page 1 ', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: '', | ||
hitsPerPage: 1, | ||
page: 1, | ||
}, | ||
}, | ||
]) | ||
const hits = response.results[0].hits | ||
expect(hits.length).toBe(1) | ||
expect(hits[0].title).toBe('Four Rooms') | ||
}) | ||
|
||
test('Test 100 hitsPerPage w/ page 1 ', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: '', | ||
hitsPerPage: 100, | ||
page: 1, | ||
}, | ||
}, | ||
]) | ||
const hits = response.results[0].hits | ||
expect(hits.length).toBe(0) | ||
expect(hits).toEqual([]) | ||
}) | ||
|
||
test('Test 0 hitsPerPage w/ page 0 ', async () => { | ||
const response = await searchClient.search([ | ||
{ | ||
indexName: 'movies', | ||
params: { | ||
query: '', | ||
hitsPerPage: 0, | ||
page: 0, | ||
}, | ||
}, | ||
]) | ||
const hits = response.results[0].hits | ||
expect(hits.length).toBe(0) | ||
expect(hits).toEqual([]) | ||
}) | ||
}) |
Oops, something went wrong.