From eb589c856846e1d94f05543cbdf6920abad11e9b Mon Sep 17 00:00:00 2001 From: melanieb Date: Fri, 9 Oct 2020 14:14:29 +0200 Subject: [PATCH 1/6] Add findByType method to find all main_navigation typed document --- services/document-fetcher.js | 7 ++++++ tests/services/document-fetcher.test.js | 30 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/services/document-fetcher.js b/services/document-fetcher.js index 419288d21..f22805aa6 100644 --- a/services/document-fetcher.js +++ b/services/document-fetcher.js @@ -25,6 +25,13 @@ export function documentFetcher( const lang = i18n.locale || i18n.defaultLocale return { get: getSingle, + findByType: async (type) => { + const documents = await prismic.api.query( + prismic.predicates.at('document.type', type), + { lang } + ) + return documents.results + }, getEmployers: async () => { const document = await prismic.api.getSingle('employers', { lang, diff --git a/tests/services/document-fetcher.test.js b/tests/services/document-fetcher.test.js index bf1a8a253..a463393f7 100644 --- a/tests/services/document-fetcher.test.js +++ b/tests/services/document-fetcher.test.js @@ -109,4 +109,34 @@ describe('DocumentFetcher', () => { expect(prismicPredicates.at).toBeCalledWith('my.slices_page.uid', uid) expect(response).toEqual(expectedValue) }) + + test('#findByType', async () => { + // Given + const type = 'main_navigation' + const expectedValue = [ + { type: 'main_navigation', navigation_for: 'pix-site' }, + { type: 'main_navigation', navigation_for: 'pix-pro' }, + ] + const expectedPredicatesAtValue = Symbol('AT') + const findMock = () => ({ results: expectedValue }) + const prismicApi = { + query: jest.fn().mockImplementationOnce(findMock), + } + prismic.api = prismicApi + + const prismicPredicates = { + at: jest.fn(() => expectedPredicatesAtValue), + } + prismic.predicates = prismicPredicates + + // When + const response = await documentFetcher(prismic).findByType(type) + + // Then + expect(prismicApi.query).toBeCalledWith(expectedPredicatesAtValue, { + lang: 'fr-fr', + }) + expect(prismicPredicates.at).toBeCalledWith('document.type', type) + expect(response).toEqual(expectedValue) + }) }) From 03a3d712dbc8ee09bd889dcfe1f6b1ba1143fcfc Mon Sep 17 00:00:00 2001 From: melanieb Date: Fri, 9 Oct 2020 14:30:13 +0200 Subject: [PATCH 2/6] Use findByType method to get the main Navigation --- components/NavigationSliceZone.vue | 12 ++++++++---- store/index.js | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/NavigationSliceZone.vue b/components/NavigationSliceZone.vue index 57c843a65..9f1af1c01 100644 --- a/components/NavigationSliceZone.vue +++ b/components/NavigationSliceZone.vue @@ -14,7 +14,7 @@