Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed Oct 22, 2023
1 parent 0fcb5b2 commit ef9b271
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
16 changes: 9 additions & 7 deletions frontend/packages/ux-editor/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -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<ServicesContextProps> = {
getInstanceIdForPreview: jest.fn().mockImplementation(() => Promise.resolve('test')),
};
return renderWithMockStore({}, queries)(<App />);
const appContextProps: Partial<AppContextProps> = {
selectedLayoutSet: 'layout-set-that-does-not-exist',
removeSelectedLayoutSet: removeSelectedLayoutSetMock,
};
return renderWithMockStore({}, queries, queryClientMock, appContextProps)(<App />);
};

describe('App', () => {
Expand All @@ -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 () => {
Expand Down
7 changes: 1 addition & 6 deletions frontend/packages/ux-editor/src/AppContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@ export interface AppContextProps {
removeSelectedLayoutSet: () => void;
}

export const AppContext = createContext<AppContextProps>({
previewIframeRef: null,
selectedLayoutSet: undefined,
setSelectedLayoutSet: (layoutSet: string) => {},
removeSelectedLayoutSet: () => {},
});
export const AppContext = createContext<AppContextProps>(null);

0 comments on commit ef9b271

Please sign in to comment.