diff --git a/frontend/packages/ux-editor/src/App.test.tsx b/frontend/packages/ux-editor/src/App.test.tsx index 217a19df38c..c99bb7f91f1 100644 --- a/frontend/packages/ux-editor/src/App.test.tsx +++ b/frontend/packages/ux-editor/src/App.test.tsx @@ -1,17 +1,23 @@ import React from 'react'; import { screen, waitFor } from '@testing-library/react'; -import { renderWithMockStore } from './testing/mocks'; +import { queryClientMock, renderWithMockStore } from './testing/mocks'; import { App } from './App'; import { textMock } from '../../../testing/mocks/i18nMock'; import { typedLocalStorage } from 'app-shared/utils/webStorage'; import { ServicesContextProps } from 'app-shared/contexts/ServicesContext'; import { appStateMock } from './testing/stateMocks'; +import { AppContextProps } from './AppContext'; +const removeSelectedLayoutSetMock = jest.fn(); const render = () => { const queries: Partial = { getInstanceIdForPreview: jest.fn().mockImplementation(() => Promise.resolve('test')), }; - return renderWithMockStore({}, queries)(); + const appContextProps: Partial = { + selectedLayoutSet: 'layout-set-that-does-not-exist', + removeSelectedLayoutSet: removeSelectedLayoutSetMock, + }; + return renderWithMockStore({}, queries, queryClientMock, appContextProps)(); }; describe('App', () => { @@ -30,15 +36,11 @@ describe('App', () => { }); it('Removes the preview layout set from local storage if it does not exist', async () => { - const layoutSetThatDoesNotExist = 'layout-set-that-does-not-exist'; - jest.spyOn(typedLocalStorage, 'getItem').mockReturnValue(layoutSetThatDoesNotExist); - const removeItem = jest.spyOn(typedLocalStorage, 'removeItem'); render(); await waitFor(() => expect(screen.queryByText(textMock('general.loading'))).not.toBeInTheDocument(), ); - expect(removeItem).toHaveBeenCalledTimes(1); - expect(removeItem).toHaveBeenCalledWith('layoutSet/app'); + expect(removeSelectedLayoutSetMock).toHaveBeenCalledTimes(1); }); it('Does not remove the preview layout set from local storage if it exists', async () => { diff --git a/frontend/packages/ux-editor/src/AppContext.ts b/frontend/packages/ux-editor/src/AppContext.ts index f542931a8d1..25b6e869d37 100644 --- a/frontend/packages/ux-editor/src/AppContext.ts +++ b/frontend/packages/ux-editor/src/AppContext.ts @@ -7,9 +7,4 @@ export interface AppContextProps { removeSelectedLayoutSet: () => void; } -export const AppContext = createContext({ - previewIframeRef: null, - selectedLayoutSet: undefined, - setSelectedLayoutSet: (layoutSet: string) => {}, - removeSelectedLayoutSet: () => {}, -}); +export const AppContext = createContext(null);