diff --git a/README.md b/README.md index 6bdce4b7..59e8ce06 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ Usage: ### Finite Pagination -Finite pagination is used when you want to add a numbered pagination at the bottom of your hits (for example: `< << 1, 2, 3 > >>`). +Finite pagination is used when you want to add a numbered pagination at the bottom of your hits (for example: `<< < 1, 2, 3 > >>`). To be able to know the amount of page numbers you have, a search is done requesting `paginationTotalHits` documents (default: `200`). With the amount of documents returned, instantsearch is able to render the correct amount of numbers in the pagination widget. diff --git a/src/adapter/search-request-adapter/__tests__/facets-distribution-assigns.tests.ts b/src/adapter/search-request-adapter/__tests__/facets-distribution-assigns.tests.ts index 87c733f8..7fa929d1 100644 --- a/src/adapter/search-request-adapter/__tests__/facets-distribution-assigns.tests.ts +++ b/src/adapter/search-request-adapter/__tests__/facets-distribution-assigns.tests.ts @@ -5,11 +5,13 @@ test('One field in cache present in distribution', () => { { genre: ['comedy'] }, { genre: { comedy: 1 } } ) + expect(returnedDistribution).toMatchObject({ genre: { comedy: 1 } }) }) test('One field in cache not present in distribution', () => { const returnedDistribution = addMissingFacets({ genre: ['comedy'] }, {}) + expect(returnedDistribution).toMatchObject({ genre: { comedy: 0 } }) }) @@ -18,6 +20,7 @@ test('two field in cache only one present in distribution', () => { { genre: ['comedy'], title: ['hamlet'] }, { genre: { comedy: 12 } } ) + expect(returnedDistribution).toMatchObject({ genre: { comedy: 12 }, title: { hamlet: 0 }, @@ -29,6 +32,7 @@ test('two field in cache w/ different facet name none present in distribution', { genre: ['comedy'], title: ['hamlet'] }, {} ) + expect(returnedDistribution).toMatchObject({ genre: { comedy: 0 }, title: { hamlet: 0 }, @@ -40,6 +44,7 @@ test('two field in cache w/ different facet name both present in distribution', { genre: ['comedy'], title: ['hamlet'] }, { genre: { comedy: 12 }, title: { hamlet: 1 } } ) + expect(returnedDistribution).toMatchObject({ genre: { comedy: 12 }, title: { hamlet: 1 }, @@ -51,6 +56,7 @@ test('Three field in cache w/ different facet name two present in distribution', { genre: ['comedy', 'horror'], title: ['hamlet'] }, { genre: { comedy: 12 }, title: { hamlet: 1 } } ) + expect(returnedDistribution).toMatchObject({ genre: { comedy: 12, horror: 0 }, title: { hamlet: 1 }, @@ -61,25 +67,30 @@ test('Cache is undefined and facets distribution is not', () => { const returnedDistribution = addMissingFacets(undefined, { genre: { comedy: 12 }, }) + expect(returnedDistribution).toMatchObject({ genre: { comedy: 12 } }) }) test('Cache is empty object and facets distribution is not', () => { const returnedDistribution = addMissingFacets({}, { genre: { comedy: 12 } }) + expect(returnedDistribution).toMatchObject({ genre: { comedy: 12 } }) }) test('Cache is empty object and facets distribution empty object', () => { const returnedDistribution = addMissingFacets({}, {}) + expect(returnedDistribution).toMatchObject({}) }) test('Cache is undefined and facets distribution empty object', () => { const returnedDistribution = addMissingFacets(undefined, {}) + expect(returnedDistribution).toMatchObject({}) }) test('Cache is undefined and facets distribution is undefined', () => { const returnedDistribution = addMissingFacets(undefined, undefined) + expect(returnedDistribution).toMatchObject({}) }) diff --git a/src/adapter/search-request-adapter/__tests__/filter-cache.tests.ts b/src/adapter/search-request-adapter/__tests__/filter-cache.tests.ts index 7f644cb6..6a59fb5d 100644 --- a/src/adapter/search-request-adapter/__tests__/filter-cache.tests.ts +++ b/src/adapter/search-request-adapter/__tests__/filter-cache.tests.ts @@ -64,6 +64,7 @@ describe.each(facetCacheData)( { keepZeroFacets: false, defaultFacetDistribution: {} }, { filter: filters } ) + expect(cache).toEqual(expectedCache) }) } diff --git a/src/adapter/search-request-adapter/__tests__/geo-rules.tests.ts b/src/adapter/search-request-adapter/__tests__/geo-rules.tests.ts index d535a2a5..b9a6e8de 100644 --- a/src/adapter/search-request-adapter/__tests__/geo-rules.tests.ts +++ b/src/adapter/search-request-adapter/__tests__/geo-rules.tests.ts @@ -17,6 +17,7 @@ test('Adapt geoPoints rules with integer geo points', () => { const rules = adaptGeoPointsRules({ insideBoundingBox: '1,2,3,4', }) + expect(rules?.filter).toBe('_geoRadius(3.17650, 3.19394, 157201.47551181243)') }) @@ -24,6 +25,7 @@ test('Try geoContext with only a radius', () => { const rules = adaptGeoPointsRules({ aroundRadius: 1, }) + expect(rules).toBeUndefined() }) @@ -31,6 +33,7 @@ test('Try geoContext with an aroundLatLng', () => { const rules = adaptGeoPointsRules({ aroundLatLng: '51.1241999, 9.662499900000057', }) + expect(rules?.filter).toBeUndefined() }) @@ -39,6 +42,7 @@ test('Try geoContext with an aroundLatLng and a radius', () => { aroundLatLng: '51.1241999, 9.662499900000057', aroundRadius: 1, }) + expect(rules?.filter).toBe('_geoRadius(51.12420, 9.66250, 1)') }) @@ -47,6 +51,7 @@ test('Try geoContext with an aroundLatLng and a 0 radius', () => { aroundLatLng: '51.1241999, 9.662499900000057', aroundRadius: 0, }) + expect(rules?.filter).toBe('_geoRadius(51.12420, 9.66250, 0)') }) @@ -56,6 +61,7 @@ test('Try geoContext with aroundLatLng, radius and insideBoundingBox', () => { aroundRadius: 1, insideBoundingBox: '1,2,3,4', }) + expect(rules?.filter).toBe('_geoRadius(3.17650, 3.19394, 157201.47551181243)') }) test('Try geoContext with a radius and insideBoundingBox', () => { @@ -63,6 +69,7 @@ test('Try geoContext with a radius and insideBoundingBox', () => { aroundRadius: 1, insideBoundingBox: '1,2,3,4', }) + expect(rules?.filter).toBe('_geoRadius(3.17650, 3.19394, 157201.47551181243)') }) test('Try geoContext with aroundLatLng and insideBoundingBox', () => { @@ -70,5 +77,6 @@ test('Try geoContext with aroundLatLng and insideBoundingBox', () => { aroundLatLng: '51.1241999, 9.662499900000057', insideBoundingBox: '1,2,3,4', }) + expect(rules?.filter).toBe('_geoRadius(3.17650, 3.19394, 157201.47551181243)') }) diff --git a/src/adapter/search-request-adapter/__tests__/search-params.tests.ts b/src/adapter/search-request-adapter/__tests__/search-params.tests.ts index 280a7f1f..067cd4e7 100644 --- a/src/adapter/search-request-adapter/__tests__/search-params.tests.ts +++ b/src/adapter/search-request-adapter/__tests__/search-params.tests.ts @@ -1,211 +1,194 @@ import { adaptSearchParams } from '../search-params-adapter' -test('Adapt basic SearchContext ', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, - defaultFacetDistribution: {}, - finitePagination: false, +const DEFAULT_CONTEXT = { + indexUid: 'test', + pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, + defaultFacetDistribution: {}, +} + +describe('Parameters adapter', () => { + test('adapting a basic searchContext ', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + finitePagination: false, + }) + + expect(searchParams.attributesToHighlight).toContain('*') + expect(searchParams.attributesToHighlight?.length).toBe(1) }) - expect(searchParams.attributesToHighlight).toContain('*') - expect(searchParams.attributesToHighlight?.length).toBe(1) -}) -test('Adapt SearchContext with filters, sort and no geo rules ', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, - facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']], - sort: 'id < 1', - defaultFacetDistribution: {}, - finitePagination: false, + test('adapting a searchContext with filters and sort', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']], + sort: 'id < 1', + finitePagination: false, + }) + + expect(searchParams.filter).toStrictEqual([ + ['genres="Drama"', 'genres="Thriller"'], + ['title="Ariel"'], + ]) + expect(searchParams.sort).toStrictEqual(['id < 1']) + expect(searchParams.attributesToHighlight).toContain('*') + expect(searchParams.attributesToHighlight?.length).toBe(1) }) - - expect(searchParams.filter).toStrictEqual([ - ['genres="Drama"', 'genres="Thriller"'], - ['title="Ariel"'], - ]) - expect(searchParams.sort).toStrictEqual(['id < 1']) - expect(searchParams.attributesToHighlight).toContain('*') - expect(searchParams.attributesToHighlight?.length).toBe(1) }) -test('Adapt SearchContext with filters, sort and geo rules ', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, - facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']], - insideBoundingBox: '0,0,0,0', - sort: 'id < 1', - defaultFacetDistribution: {}, - finitePagination: false, +describe('Geo rules adapter', () => { + test('adapting a searchContext with filters, sort and geo rules ', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']], + insideBoundingBox: '0,0,0,0', + sort: 'id < 1', + finitePagination: false, + }) + + expect(searchParams.filter).toStrictEqual([ + '_geoRadius(0.00000, 0.00000, 0)', + ['genres="Drama"', 'genres="Thriller"'], + ['title="Ariel"'], + ]) + expect(searchParams.sort).toStrictEqual(['id < 1']) + expect(searchParams.attributesToHighlight).toContain('*') + expect(searchParams.attributesToHighlight?.length).toBe(1) }) - expect(searchParams.filter).toStrictEqual([ - '_geoRadius(0.00000, 0.00000, 0)', - ['genres="Drama"', 'genres="Thriller"'], - ['title="Ariel"'], - ]) - expect(searchParams.sort).toStrictEqual(['id < 1']) - expect(searchParams.attributesToHighlight).toContain('*') - expect(searchParams.attributesToHighlight?.length).toBe(1) -}) - -test('Adapt SearchContext with only facetFilters and geo rules ', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, - facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']], - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: false, + test('adapting a searchContext with only facetFilters and geo rules ', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']], + insideBoundingBox: '0,0,0,0', + finitePagination: false, + }) + + expect(searchParams.filter).toEqual([ + '_geoRadius(0.00000, 0.00000, 0)', + ['genres="Drama"', 'genres="Thriller"'], + ['title="Ariel"'], + ]) + expect(searchParams.attributesToHighlight).toContain('*') + expect(searchParams.attributesToHighlight?.length).toBe(1) }) - expect(searchParams.filter).toEqual([ - '_geoRadius(0.00000, 0.00000, 0)', - ['genres="Drama"', 'genres="Thriller"'], - ['title="Ariel"'], - ]) - expect(searchParams.attributesToHighlight).toContain('*') - expect(searchParams.attributesToHighlight?.length).toBe(1) -}) - -test('Adapt SearchContext with only sort and geo rules ', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - sort: 'id < 1', - defaultFacetDistribution: {}, - finitePagination: false, + test('adapting a searchContext with only sort and geo rules ', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + insideBoundingBox: '0,0,0,0', + sort: 'id < 1', + finitePagination: false, + }) + + expect(searchParams.filter).toEqual(['_geoRadius(0.00000, 0.00000, 0)']) + expect(searchParams.sort).toStrictEqual(['id < 1']) + expect(searchParams.attributesToHighlight).toContain('*') + expect(searchParams.attributesToHighlight?.length).toBe(1) }) - expect(searchParams.filter).toEqual(['_geoRadius(0.00000, 0.00000, 0)']) - expect(searchParams.sort).toStrictEqual(['id < 1']) - expect(searchParams.attributesToHighlight).toContain('*') - expect(searchParams.attributesToHighlight?.length).toBe(1) -}) + test('adapting a searchContext with no sort and no filters and geo rules ', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + insideBoundingBox: '0,0,0,0', + finitePagination: false, + }) -test('Adapt SearchContext with no sort and no filters and geo rules ', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: false, + expect(searchParams.filter).toEqual(['_geoRadius(0.00000, 0.00000, 0)']) + expect(searchParams.attributesToHighlight).toContain('*') + expect(searchParams.attributesToHighlight?.length).toBe(1) }) - - expect(searchParams.filter).toEqual(['_geoRadius(0.00000, 0.00000, 0)']) - expect(searchParams.attributesToHighlight).toContain('*') - expect(searchParams.attributesToHighlight?.length).toBe(1) }) -test('Adapt SearchContext with finite pagination', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: true, +describe('Pagination adapter', () => { + test('adapting a searchContext with finite pagination', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + finitePagination: true, + }) + + expect(searchParams.limit).toBe(20) }) - expect(searchParams.limit).toBe(20) -}) + test('adapting a searchContext with finite pagination on a later page', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + pagination: { paginationTotalHits: 20, page: 10, hitsPerPage: 6 }, + finitePagination: true, + }) -test('Adapt SearchContext with finite pagination on a later page', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 10, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: true, + expect(searchParams.limit).toBe(20) }) - expect(searchParams.limit).toBe(20) -}) + test('adapting a searchContext with finite pagination and pagination total hits lower than hitsPerPage', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 }, + finitePagination: true, + }) -test('Adapt SearchContext with finite pagination and pagination total hits lower than hitsPerPage', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: true, + expect(searchParams.limit).toBe(4) }) - expect(searchParams.limit).toBe(4) -}) + test('adapting a searchContext with no finite pagination', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + finitePagination: false, + }) -test('Adapt SearchContext with no finite pagination', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 0, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: false, + expect(searchParams.limit).toBe(7) }) - expect(searchParams.limit).toBe(7) -}) + test('adapting a searchContext with no finite pagination on page 2', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + pagination: { paginationTotalHits: 20, page: 1, hitsPerPage: 6 }, + finitePagination: false, + }) -test('Adapt SearchContext with no finite pagination on page 2', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 1, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: false, + expect(searchParams.limit).toBe(13) }) - expect(searchParams.limit).toBe(13) -}) + test('adapting a searchContext with no finite pagination on page higher than paginationTotalHits', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + pagination: { paginationTotalHits: 20, page: 40, hitsPerPage: 6 }, + finitePagination: false, + }) -test('Adapt SearchContext with no finite pagination on page higher than paginationTotalHits', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 20, page: 40, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: false, + expect(searchParams.limit).toBe(20) }) - expect(searchParams.limit).toBe(20) -}) + test('adapting a searchContext with no finite pagination and pagination total hits lower than hitsPerPage', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 }, + finitePagination: false, + }) -test('Adapt SearchContext with no finite pagination and pagination total hits lower than hitsPerPage', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 }, - insideBoundingBox: '0,0,0,0', - defaultFacetDistribution: {}, - finitePagination: false, + expect(searchParams.limit).toBe(4) }) - expect(searchParams.limit).toBe(4) -}) + test('adapting a searchContext placeholderSearch set to false', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + query: '', + pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 }, + finitePagination: false, + placeholderSearch: false, + }) -test('Adapt SearchContext placeholderSearch set to false', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - query: '', - pagination: { paginationTotalHits: 4, page: 0, hitsPerPage: 6 }, - defaultFacetDistribution: {}, - finitePagination: false, - placeholderSearch: false, + expect(searchParams.limit).toBe(0) }) - expect(searchParams.limit).toBe(0) -}) + test('adapting a searchContext placeholderSearch set to false', () => { + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + query: '', + pagination: { paginationTotalHits: 200, page: 0, hitsPerPage: 6 }, + finitePagination: false, + placeholderSearch: true, + }) -test('Adapt SearchContext placeholderSearch set to false', () => { - const searchParams = adaptSearchParams({ - indexUid: 'test', - query: '', - pagination: { paginationTotalHits: 200, page: 0, hitsPerPage: 6 }, - defaultFacetDistribution: {}, - finitePagination: false, - placeholderSearch: true, + expect(searchParams.limit).toBe(7) }) - - expect(searchParams.limit).toBe(7) }) diff --git a/src/adapter/search-response-adapter/__tests__/pagination-adapter.tests.ts b/src/adapter/search-response-adapter/__tests__/pagination-adapter.tests.ts index 904ecdc6..f0fdad98 100644 --- a/src/adapter/search-response-adapter/__tests__/pagination-adapter.tests.ts +++ b/src/adapter/search-response-adapter/__tests__/pagination-adapter.tests.ts @@ -129,6 +129,7 @@ describe.each(numberPagesTestParameters)( ({ hitsPerPage, hitsLength, numberPages }) => { it(`Should return ${numberPages} pages when hitsPerPage is ${hitsPerPage} and hits length is ${hitsLength}`, () => { const response = ceiledDivision(hitsLength, hitsPerPage) + expect(response).toBe(numberPages) }) } @@ -143,6 +144,7 @@ describe.each(paginateHitsTestsParameters)( hits )}`, () => { const response = adaptPagination(hits, page, hitsPerPage) + expect(response).toEqual(returnedHits) }) } @@ -153,6 +155,7 @@ it('Should throw when hitsPerPage is negative', () => { const hits: string[] = [] const hitsPerPage = -1 const page = 0 + adaptPagination(hits, page, hitsPerPage) } catch (e: any) { expect(e.message).toBe( diff --git a/src/cache/__tests__/search-cache.tests.ts b/src/cache/__tests__/search-cache.tests.ts index 1abff0c7..4cbc3ed6 100644 --- a/src/cache/__tests__/search-cache.tests.ts +++ b/src/cache/__tests__/search-cache.tests.ts @@ -2,35 +2,35 @@ import { SearchCache } from '../search-cache' import { searchResponse } from './assets/utils' describe('Tests on entries in cache', () => { - test('Test to getEntry on empty cache', () => { + test('to getEntry on empty cache', () => { const cache = SearchCache() const key = cache.getEntry('') expect(key).toBeUndefined() }) - test('Test to getEntry on invalid json', () => { + test('to getEntry on invalid json', () => { const cache = SearchCache({ myKey: 'myValue' }) const key = cache.getEntry('myKey') expect(key).toEqual('myValue') }) - test('Test to getEntry on valid json string', () => { + test('to getEntry on valid json string', () => { const cache = SearchCache({ myKey: '"myValue"' }) const key = cache.getEntry('myKey') expect(key).toEqual('myValue') }) - test('Test to getEntry on valid json object', () => { + test('to getEntry on valid json object', () => { const cache = SearchCache({ myKey: '{ "id": 1 }' }) const key = cache.getEntry('myKey') expect(key).toHaveProperty('id', 1) }) - test('Test to getEntry on invalid json object', () => { + test('to getEntry on invalid json object', () => { const cache = SearchCache({ myKey: '{ id: 1 }' }) const key = cache.getEntry('myKey') @@ -39,32 +39,37 @@ describe('Tests on entries in cache', () => { }) describe('Tests on key format', () => { - test('Test to format an empty string', () => { + test('to format an empty string', () => { const cache = SearchCache() const key = cache.formatKey(['']) + expect(key).toEqual('""') }) - test('Test to format a number', () => { + test('to format a number', () => { const cache = SearchCache() const key = cache.formatKey([1]) + expect(key).toEqual('1') }) - test('Test to format multiple empty strings', () => { + test('to format multiple empty strings', () => { const cache = SearchCache() const key = cache.formatKey(['', '', '']) + expect(key).toEqual('""""""') }) - test('Test to format empty string', () => { + test('to format empty string', () => { const cache = SearchCache() const key = cache.formatKey([]) + expect(key).toEqual('') }) - test('Test to format undefined', () => { + test('to format undefined', () => { const cache = SearchCache() const key = cache.formatKey([undefined]) + expect(key).toEqual('undefined') }) }) diff --git a/tests/configure.attributes-to-retrieve.tests.ts b/tests/configure.attributes-to-retrieve.tests.ts index ac618f86..99726cf7 100644 --- a/tests/configure.attributes-to-retrieve.tests.ts +++ b/tests/configure.attributes-to-retrieve.tests.ts @@ -16,7 +16,7 @@ describe('Instant Meilisearch Browser test', () => { await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid) }) - test('Test attributesToRetrieve on no attributes', async () => { + test('attributesToRetrieve on no attributes', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -26,6 +26,7 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hit = response.results[0].hits[0] expect(hit.id).not.toBeDefined() expect(hit.overview).not.toBeDefined() @@ -34,7 +35,7 @@ describe('Instant Meilisearch Browser test', () => { expect(hit.title).not.toBeDefined() }) - test('Test attributesToRetrieve on null', async () => { + test('attributesToRetrieve on null', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -54,7 +55,7 @@ describe('Instant Meilisearch Browser test', () => { expect(hit.title).not.toBeDefined() }) - test('Test attributesToRetrieve on one non existing attribute', async () => { + test('attributesToRetrieve on one non existing attribute', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -66,7 +67,6 @@ describe('Instant Meilisearch Browser test', () => { ]) const hit = response.results[0].hits[0] - expect(hit._highlightResult?.id).toBeDefined() expect(hit._highlightResult?.overview).toBeDefined() expect(hit._highlightResult?.genres).toBeDefined() @@ -75,7 +75,7 @@ describe('Instant Meilisearch Browser test', () => { expect(hit._highlightResult?.title).toBeDefined() }) - test('Test attributesToRetrieve on one existing attribute', async () => { + test('attributesToRetrieve on one existing attribute', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -85,6 +85,7 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hit = response.results[0].hits[0] expect(hit.title).toEqual('Ariel') expect(hit.id).not.toBeDefined() @@ -95,7 +96,7 @@ describe('Instant Meilisearch Browser test', () => { expect(hit.title).toBeDefined() }) - test('Test attributesToRetrieve on default value', async () => { + test('attributesToRetrieve on default value', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -108,14 +109,12 @@ describe('Instant Meilisearch Browser test', () => { const hit = response.results[0].hits[0] expect(hit.title).toEqual('Ariel') expect(hit._highlightResult).toBeDefined() - expect(hit.id).toBeDefined() expect(hit.overview).toBeDefined() expect(hit.genres).toBeDefined() expect(hit.poster).toBeDefined() expect(hit.release_date).toBeDefined() expect(hit.title).toBeDefined() - expect(hit._highlightResult?.id).toBeDefined() expect(hit._highlightResult?.overview).toBeDefined() expect(hit._highlightResult?.genres).toBeDefined() @@ -124,7 +123,7 @@ describe('Instant Meilisearch Browser test', () => { expect(hit._highlightResult?.title).toBeDefined() }) - test('Test attributesToRetrieve on wild card', async () => { + test('attributesToRetrieve on wild card', async () => { const response = await searchClient.search([ { indexName: 'movies', diff --git a/tests/facets-distribution.tests.ts b/tests/facets-distribution.tests.ts index 06d87fc0..4a312a39 100644 --- a/tests/facets-distribution.tests.ts +++ b/tests/facets-distribution.tests.ts @@ -13,7 +13,7 @@ describe('Instant Meilisearch Browser test', () => { await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid) }) - test('Test empty array on facetDistribution', async () => { + test('empty array on facetDistribution', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -23,10 +23,11 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + expect(response.results[0].facets?.genres).toEqual(undefined) }) - test('Test one facet on facetDistribution', async () => { + test('one facet on facetDistribution', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -36,6 +37,7 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + expect(response.results[0].facets?.genres?.Action).toEqual(3) }) }) diff --git a/tests/filter.tests.ts b/tests/filter.tests.ts index 77ae04cb..87a68b90 100644 --- a/tests/filter.tests.ts +++ b/tests/filter.tests.ts @@ -18,7 +18,7 @@ describe('Instant Meilisearch Browser test', () => { await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid) }) - test('Test one string facet on filter without a query', async () => { + test('one string facet on filter without a query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -28,12 +28,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(1) expect(hits[0].title).toEqual('Star Wars') }) - test('Test one facet on filter with a query', async () => { + test('one facet on filter with a query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -43,12 +44,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(2) expect(hits[0].title).toEqual('Four Rooms') }) - test('Test one string facet on filter without a query', async () => { + test('one string facet on filter without a query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -58,12 +60,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(1) expect(hits[0].title).toEqual('Star Wars') }) - test('Test one facet on filter with a query', async () => { + test('one facet on filter with a query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -73,12 +76,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(2) expect(hits[0].title).toEqual('Four Rooms') }) - test('Test multiple on filter without a query', async () => { + test('multiple on filter without a query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -88,12 +92,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(2) expect(hits[0].title).toEqual('Ariel') }) - test('Test multiple on filter with a query', async () => { + test('multiple on filter with a query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -103,13 +108,14 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(2) expect(hits[0].title).toEqual('Ariel') }) - test('Test multiple nested on filter with a query', async () => { + test('multiple nested on filter with a query', async () => { const params = { indexName: 'movies', params: { @@ -117,12 +123,14 @@ describe('Instant Meilisearch Browser test', () => { facetFilters: [['genres:action', 'genres:Thriller'], ['genres:crime']], }, } + const response = await searchClient.search([params]) + const hits = response.results[0].hits expect(hits[0].title).toEqual('Judgment Night') }) - test('Test multiple nested array in filter without a query', async () => { + test('multiple nested array in filter without a query', async () => { const params = { indexName: 'movies', params: { @@ -130,12 +138,14 @@ describe('Instant Meilisearch Browser test', () => { facetFilters: [['genres:action', 'genres:Thriller'], ['genres:crime']], }, } + const response = await searchClient.search([params]) + const hits = response.results[0].hits expect(hits[0].title).toEqual('Judgment Night') }) - test('Test multiple nested arrays on filter with a query', async () => { + test('multiple nested arrays on filter with a query', async () => { const params = { indexName: 'movies', params: { @@ -143,12 +153,14 @@ describe('Instant Meilisearch Browser test', () => { facetFilters: [['genres:Drama', 'genres:Thriller'], ['title:Ariel']], }, } + const response = await searchClient.search([params]) + const hits = response.results[0].hits expect(hits[0].title).toEqual('Ariel') }) - test('Test multiple nested arrays on filter without a query', async () => { + test('multiple nested arrays on filter without a query', async () => { const params = { indexName: 'movies', params: { @@ -158,6 +170,7 @@ describe('Instant Meilisearch Browser test', () => { } const response = await searchClient.search([params]) + const hits = response.results[0].hits expect(hits[0].title).toEqual('Ariel') }) diff --git a/tests/geosearch.tests.ts b/tests/geosearch.tests.ts index bf386f0a..1c250dcb 100644 --- a/tests/geosearch.tests.ts +++ b/tests/geosearch.tests.ts @@ -19,7 +19,7 @@ describe('Instant Meilisearch Browser test', () => { await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid) }) - test('Test aroundRadius and aroundLatLng in geo search', async () => { + test('aroundRadius and aroundLatLng in geo search', async () => { const response = await searchClient.search([ { indexName: 'geotest', @@ -30,12 +30,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(14) expect(hits[0].city).toEqual('Lille') }) - test('Test aroundLatLng being overwritten by insideBoundingBox in geo search', async () => { + test('aroundLatLng being overwritten by insideBoundingBox in geo search', async () => { const response = await searchClient.search([ { indexName: 'geotest', @@ -48,12 +49,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(7) expect(hits[0].city).toEqual('Lille') }) - test('Test insideBoundingBox in geo search', async () => { + test('insideBoundingBox in geo search', async () => { const response = await searchClient.search([ { indexName: 'geotest', @@ -64,12 +66,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(4) expect(hits[0].city).toEqual('Ghent') }) - test('Test insideBoundingBox and aroundRadius in geo search', async () => { + test('insideBoundingBox and aroundRadius in geo search', async () => { const response = await searchClient.search([ { indexName: 'geotest', @@ -81,12 +84,13 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(4) expect(hits[0].city).toEqual('Ghent') }) - test('Test insideBoundingBox and aroundLatLng in geo search', async () => { + test('insideBoundingBox and aroundLatLng in geo search', async () => { const response = await searchClient.search([ { indexName: 'geotest', @@ -98,6 +102,7 @@ describe('Instant Meilisearch Browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toEqual(4) expect(hits[0].city).toEqual('Ghent') diff --git a/tests/highlight.tests.ts b/tests/highlight.tests.ts index fe93121e..b0e2e131 100644 --- a/tests/highlight.tests.ts +++ b/tests/highlight.tests.ts @@ -18,7 +18,7 @@ describe('Highlight Browser test', () => { await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid) }) - test('Test one attributesToHighlight on wrong attribute placeholder', async () => { + test('one attributesToHighlight on wrong attribute placeholder', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -32,7 +32,7 @@ describe('Highlight Browser test', () => { expect(resKeys).toEqual(undefined) }) - test('Test one attributesToHighlight on placeholder search', async () => { + test('one attributesToHighlight on placeholder search', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -61,7 +61,7 @@ describe('Highlight Browser test', () => { ) }) - test('Test no attributesToHighlight on placeholder', async () => { + test('no attributesToHighlight on placeholder', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -74,7 +74,7 @@ describe('Highlight Browser test', () => { expect(response.results[0]?.hits[0]).not.toHaveProperty('_highlightResult') }) - test('Test no attributesToHighlight on placeholder', async () => { + test('no attributesToHighlight on placeholder', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -91,7 +91,7 @@ describe('Highlight Browser test', () => { } }) - test('Test one attributesToHighlight on specific query', async () => { + test('one attributesToHighlight on specific query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -108,7 +108,7 @@ describe('Highlight Browser test', () => { ) }) - test('Test two attributesToHighlight on specific query', async () => { + test('two attributesToHighlight on specific query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -128,7 +128,7 @@ describe('Highlight Browser test', () => { ) }) - test('Test two attributesToHighlight on specific query with empty string value', async () => { + test('two attributesToHighlight on specific query with empty string value', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -148,7 +148,7 @@ describe('Highlight Browser test', () => { ) }) - test('Test two attributesToHighlight on specific query with null value', async () => { + test('two attributesToHighlight on specific query with null value', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -167,7 +167,7 @@ describe('Highlight Browser test', () => { ) }) - test('Test two attributesToHighlight on specific query with null value', async () => { + test('two attributesToHighlight on specific query with null value', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -186,7 +186,7 @@ describe('Highlight Browser test', () => { ) }) - test('Test two attributesToHighlight on wild card', async () => { + test('two attributesToHighlight on wild card', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -206,7 +206,7 @@ describe('Highlight Browser test', () => { ) }) - test('Test two attributesToHighlight with different tags', async () => { + test('two attributesToHighlight with different tags', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -226,7 +226,7 @@ describe('Highlight Browser test', () => { ) }) - test('Test attributes to highlight on non-string-types', async () => { + test('attributes to highlight on non-string-types', async () => { const response = await searchClient.search([ { indexName: 'movies', diff --git a/tests/pagination.tests.ts b/tests/pagination.tests.ts index d6377017..71c879e2 100644 --- a/tests/pagination.tests.ts +++ b/tests/pagination.tests.ts @@ -19,7 +19,7 @@ describe('Pagination browser test', () => { await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid) }) - test('Test 1 hitsPerPage', async () => { + test('1 hitsPerPage', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -29,11 +29,12 @@ describe('Pagination browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(1) }) - test('Test 1 hitsPerPage w/ page 0 ', async () => { + test('1 hitsPerPage w/ page 0 ', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -44,12 +45,12 @@ describe('Pagination browser test', () => { }, }, ]) - const hits = response.results[0].hits + const hits = response.results[0].hits expect(hits.length).toBe(1) }) - test('Test 1 hitsPerPage w/ page 1 ', async () => { + test('1 hitsPerPage w/ page 1 ', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -60,11 +61,12 @@ describe('Pagination browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(1) }) - test('Test 100 hitsPerPage w/ page 1 ', async () => { + test('100 hitsPerPage w/ page 1 ', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -75,12 +77,13 @@ describe('Pagination browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(0) expect(hits).toEqual([]) }) - test('Test 0 hitsPerPage w/ page 0 ', async () => { + test('0 hitsPerPage w/ page 0 ', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -91,12 +94,13 @@ describe('Pagination browser test', () => { }, }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(0) expect(hits).toEqual([]) }) - test('Test pagination total hits ', async () => { + test('pagination total hits ', async () => { const customClient = instantMeiliSearch( 'http://localhost:7700', 'masterKey', @@ -104,16 +108,18 @@ describe('Pagination browser test', () => { paginationTotalHits: 1, } ) + const response = await customClient.search([ { indexName: 'movies', }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(1) }) - test('Test zero pagination total hits ', async () => { + test('zero pagination total hits ', async () => { const customClient = instantMeiliSearch( 'http://localhost:7700', 'masterKey', @@ -121,16 +127,18 @@ describe('Pagination browser test', () => { paginationTotalHits: 0, } ) + const response = await customClient.search([ { indexName: 'movies', }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(0) }) - test('Test bigger pagination total hits than nbr hits', async () => { + test('bigger pagination total hits than nbr hits', async () => { const customClient = instantMeiliSearch( 'http://localhost:7700', 'masterKey', @@ -138,16 +146,18 @@ describe('Pagination browser test', () => { paginationTotalHits: 1000, } ) + const response = await customClient.search([ { indexName: 'movies', }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(6) }) - test('Test bigger pagination total hits than nbr hits', async () => { + test('bigger pagination total hits than nbr hits', async () => { const customClient = instantMeiliSearch( 'http://localhost:7700', 'masterKey', @@ -155,16 +165,18 @@ describe('Pagination browser test', () => { paginationTotalHits: 1000, } ) + const response = await customClient.search([ { indexName: 'movies', }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(6) }) - test('Test pagination total hits with finite pagination', async () => { + test('pagination total hits with finite pagination', async () => { const customClient = instantMeiliSearch( 'http://localhost:7700', 'masterKey', @@ -173,29 +185,13 @@ describe('Pagination browser test', () => { finitePagination: true, } ) - const response = await customClient.search([ - { - indexName: 'movies', - }, - ]) - const hits = response.results[0].hits - expect(hits.length).toBe(5) - }) - test('Test pagination total hits with infinite pagination', async () => { - const customClient = instantMeiliSearch( - 'http://localhost:7700', - 'masterKey', - { - paginationTotalHits: 5, - finitePagination: true, - } - ) const response = await customClient.search([ { indexName: 'movies', }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(5) }) diff --git a/tests/placeholder-search.tests.ts b/tests/placeholder-search.tests.ts index c78b2298..b2c9acbd 100644 --- a/tests/placeholder-search.tests.ts +++ b/tests/placeholder-search.tests.ts @@ -19,7 +19,7 @@ describe('Pagination browser test', () => { await meilisearchClient.index('movies').waitForTask(documentsTask.taskUid) }) - test('Test placeholdersearch set to false', async () => { + test('placeholdersearch set to false', async () => { const customClient = instantMeiliSearch( 'http://localhost:7700', 'masterKey', @@ -28,16 +28,18 @@ describe('Pagination browser test', () => { placeholderSearch: true, } ) + const response = await customClient.search([ { indexName: 'movies', }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(5) }) - test('Test placeholdersearch set to true', async () => { + test('placeholdersearch set to true', async () => { const customClient = instantMeiliSearch( 'http://localhost:7700', 'masterKey', @@ -46,11 +48,13 @@ describe('Pagination browser test', () => { placeholderSearch: false, } ) + const response = await customClient.search([ { indexName: 'movies', }, ]) + const hits = response.results[0].hits expect(hits.length).toBe(0) }) diff --git a/tests/search-resolver.tests.ts b/tests/search-resolver.tests.ts index 28a1ffa0..dd5eca43 100644 --- a/tests/search-resolver.tests.ts +++ b/tests/search-resolver.tests.ts @@ -35,7 +35,7 @@ describe('Pagination browser test', () => { jest.clearAllMocks() }) - test('Test the same search parameters twice', async () => { + test('the same search parameters twice', async () => { const searchParameters = { indexName: 'movies', params: { @@ -54,7 +54,7 @@ describe('Pagination browser test', () => { expect(mockedSearch).toHaveBeenCalledTimes(1) }) - test('Test two different search parameters', async () => { + test('two different search parameters', async () => { const searchParameters1 = { indexName: 'movies', params: { @@ -80,7 +80,7 @@ describe('Pagination browser test', () => { expect(mockedSearch).toHaveBeenCalledTimes(2) }) - test('Test two identical and one different search parameters', async () => { + test('two identical and one different search parameters', async () => { const searchParameters1 = { indexName: 'movies', params: { @@ -107,7 +107,7 @@ describe('Pagination browser test', () => { expect(mockedSearch).toHaveBeenCalledTimes(2) }) - test('Test two same and two different search parameter', async () => { + test('two same and two different search parameter', async () => { const searchParameters1 = { indexName: 'movies', params: { diff --git a/tests/snippets.tests.ts b/tests/snippets.tests.ts index f6a5cffa..d2eed06f 100644 --- a/tests/snippets.tests.ts +++ b/tests/snippets.tests.ts @@ -54,7 +54,7 @@ describe('Snippet Browser test', () => { }) }) - test('Test one attributesToSnippet on placeholder', async () => { + test('one attributesToSnippet on placeholder', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -65,13 +65,15 @@ describe('Snippet Browser test', () => { }, }, ]) + const snippeted = response.results[0]?.hits[0]?._snippetResult + expect(snippeted).toHaveProperty('overview', { value: 'Taisto Kasurinen…', }) }) - test('Test one attributesToSnippet on specific query', async () => { + test('one attributesToSnippet on specific query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -82,6 +84,7 @@ describe('Snippet Browser test', () => { }, }, ]) + const snippeted = response.results[0].hits[0]._snippetResult expect(snippeted).toHaveProperty('overview', { @@ -89,7 +92,7 @@ describe('Snippet Browser test', () => { }) }) - test('Test * attributesToSnippet on specific query', async () => { + test('* attributesToSnippet on specific query', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -126,7 +129,7 @@ describe('Snippet Browser test', () => { } }) - test('Test two snippets on specific query and compare snippet with highlight results', async () => { + test('two snippets on specific query and compare snippet with highlight results', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -157,7 +160,7 @@ describe('Snippet Browser test', () => { }) }) - test('Test attributesToSnippet on a null attribute', async () => { + test('attributesToSnippet on a null attribute', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -173,7 +176,7 @@ describe('Snippet Browser test', () => { expect(firstHit).toHaveProperty('overview', { value: 'null' }) }) - test('Test one attributesToSnippet on placeholder w/ snippetEllipsisText', async () => { + test('one attributesToSnippet on placeholder w/ snippetEllipsisText', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -190,7 +193,7 @@ describe('Snippet Browser test', () => { expect(snippeted).toHaveProperty('overview', { value: 'Taisto Kasurinen…' }) }) - test('Test one attributesToSnippet on specific query w/ snippetEllipsisText', async () => { + test('one attributesToSnippet on specific query w/ snippetEllipsisText', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -201,11 +204,12 @@ describe('Snippet Browser test', () => { }, }, ]) + const snippeted = response.results[0]?.hits[0]?._snippetResult expect(snippeted).toHaveProperty('overview', { value: 'While racing…' }) }) - test('Test two attributesToSnippet on specific query with one hit empty string w/ snippetEllipsisText', async () => { + test('two attributesToSnippet on specific query with one hit empty string w/ snippetEllipsisText', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -216,8 +220,8 @@ describe('Snippet Browser test', () => { }, }, ]) - const firstHit = response.results[0]?.hits[0]?._snippetResult + const firstHit = response.results[0]?.hits[0]?._snippetResult expect(firstHit).toHaveProperty('title', { value: '__ais-highlight__M__/ais-highlight__agnetic…', }) @@ -232,7 +236,7 @@ describe('Snippet Browser test', () => { }) }) - test('Test attributesToSnippet on a null attribute w/ snippetEllipsisText', async () => { + test('attributesToSnippet on a null attribute w/ snippetEllipsisText', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -254,7 +258,7 @@ describe('Snippet Browser test', () => { }) }) - test('Test attributes to snippet on non-string-types', async () => { + test('attributes to snippet on non-string-types', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -265,11 +269,12 @@ describe('Snippet Browser test', () => { }, }, ]) - const hit = response.results[0].hits[0]._snippetResult + const hit = response.results[0].hits[0]._snippetResult if (hit?.overview) { expect(hit?.overview.value).toEqual('While…') } + if (hit?.poster) { // Considered to be 2 words because of special char expect(hit?.poster.value).toEqual('https…') @@ -279,9 +284,11 @@ describe('Snippet Browser test', () => { expect(hit?.genres[0]?.value).toEqual('Action') expect(hit?.genres[1]?.value).toEqual('Thriller') } + if (hit?.id) { expect(hit?.id.value).toEqual('6') } + if (hit?.undefinedArray) { // @ts-ignore expect(hit?.undefinedArray[0]?.value).toEqual('null') @@ -371,7 +378,7 @@ describe('Snippet Browser test', () => { }) }) -test('Test attributes to snippet on value smaller than the snippet size', async () => { +test('attributes to snippet on value smaller than the snippet size', async () => { const response = await searchClient.search([ { indexName: 'movies', @@ -382,8 +389,8 @@ test('Test attributes to snippet on value smaller than the snippet size', async }, }, ]) - const hit = response.results[0].hits[0]._snippetResult + const hit = response.results[0].hits[0]._snippetResult if (hit?.overview) { expect(hit?.title?.value).toEqual('Ariel') }