Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
standeren committed Oct 20, 2023
1 parent e222e1a commit e726a67
Showing 1 changed file with 9 additions and 7 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

0 comments on commit e726a67

Please sign in to comment.