From 77c1e227f67ca0c900eebbc5dafb238618b7d590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 9 Nov 2023 09:34:08 +0100 Subject: [PATCH] test with analytics api only in the dedicated test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../src/context/SearchContext.test.tsx | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/plugins/search-react/src/context/SearchContext.test.tsx b/plugins/search-react/src/context/SearchContext.test.tsx index 5e57c2aa84..39a9f09ef4 100644 --- a/plugins/search-react/src/context/SearchContext.test.tsx +++ b/plugins/search-react/src/context/SearchContext.test.tsx @@ -35,9 +35,6 @@ describe('SearchContext', () => { const searchApiMock = { query: jest.fn().mockResolvedValue({}), } satisfies typeof searchApiRef.T; - const analyticsApiMock = { - captureEvent: jest.fn(), - } satisfies typeof analyticsApiRef.T; const wrapper = ({ children, initialState, config = {} }: any) => { const configApiMock = new MockConfigApi(config); @@ -46,7 +43,6 @@ describe('SearchContext', () => { apis={[ [configApiRef, configApiMock], [searchApiRef, searchApiMock], - [analyticsApiRef, analyticsApiMock], ]} > @@ -425,14 +421,33 @@ describe('SearchContext', () => { }); describe('analytics', () => { - it('Captures analytics events if enabled in app', async () => { + it('captures analytics events if enabled in app', async () => { + const analyticsApiMock = { + captureEvent: jest.fn(), + } satisfies typeof analyticsApiRef.T; + searchApiMock.query.mockResolvedValue({ results: [], numberOfResults: 3, }); const { result } = renderHook(() => useSearch(), { - wrapper: ({ children }) => wrapper({ children, initialState }), + wrapper: ({ children }) => { + const configApiMock = new MockConfigApi({}); + return ( + + + {children} + + + ); + }, }); await waitFor(() => { @@ -446,6 +461,11 @@ describe('SearchContext', () => { }); await waitFor(() => { + expect(searchApiMock.query).toHaveBeenLastCalledWith({ + term: 'term', + types: ['*'], + filters: {}, + }); expect(analyticsApiMock.captureEvent).toHaveBeenCalledWith({ action: 'search', subject: 'term',