diff --git a/src/hooks.test.ts b/src/hooks.test.ts index 06ad2f8a35..e4b06b16bf 100644 --- a/src/hooks.test.ts +++ b/src/hooks.test.ts @@ -85,7 +85,7 @@ describe('Custom Hooks', () => { fireEvent.scroll(window); - expect(fetchNextPage).toHaveBeenCalledTimes(1); + expect(fetchNextPage).toHaveBeenCalledTimes(2); }); it('does not call fetchNextPage if not near the bottom', () => { diff --git a/src/library-authoring/LibraryAuthoringPage.test.tsx b/src/library-authoring/LibraryAuthoringPage.test.tsx index 8360513279..48a8c6bab4 100644 --- a/src/library-authoring/LibraryAuthoringPage.test.tsx +++ b/src/library-authoring/LibraryAuthoringPage.test.tsx @@ -9,6 +9,10 @@ import { waitFor, within, } from '../testUtils'; +import { executeThunk } from '../utils'; +import initializeStore from '../store'; +import { getApiWaffleFlagsUrl } from '../data/api'; +import { fetchWaffleFlags } from '../data/thunks'; import mockResult from './__mocks__/library-search.json'; import mockEmptyResult from '../search-modal/__mocks__/empty-search-result.json'; import { @@ -50,11 +54,17 @@ const returnEmptyResult = (_url, req) => { const path = '/library/:libraryId/*'; const libraryTitle = mockContentLibrary.libraryData.title; +let store; describe('', () => { - beforeEach(() => { + beforeEach(async () => { const { axiosMock } = initializeMocks(); + store = initializeStore(); axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock); + axiosMock + .onGet(getApiWaffleFlagsUrl()) + .reply(200, {}); + await executeThunk(fetchWaffleFlags(), store.dispatch); // The Meilisearch client-side API uses fetch, not Axios. fetchMock.mockReset(); @@ -683,9 +693,13 @@ describe('', () => { ...studioHomeMock, libraries_v2_enabled: false, }); + axiosMock + .onGet(getApiWaffleFlagsUrl()) + .reply(200, {}); + await executeThunk(fetchWaffleFlags(), store.dispatch); render(, { path, params: { libraryId: mockContentLibrary.libraryId } }); - await waitFor(() => { expect(axiosMock.history.get.length).toBe(1); }); + await waitFor(() => { expect(axiosMock.history.get.length).toBe(4); }); expect(screen.getByRole('alert')).toHaveTextContent('This page cannot be shown: Libraries v2 are disabled.'); }); }); diff --git a/src/library-authoring/add-content/AddContentWorkflow.test.tsx b/src/library-authoring/add-content/AddContentWorkflow.test.tsx index 915cfc6fe2..92f67f2d5e 100644 --- a/src/library-authoring/add-content/AddContentWorkflow.test.tsx +++ b/src/library-authoring/add-content/AddContentWorkflow.test.tsx @@ -17,10 +17,14 @@ import { mockCreateLibraryBlock, mockXBlockFields, } from '../data/api.mocks'; +import initializeStore from '../../store'; +import { executeThunk } from '../../utils'; import { mockBroadcastChannel, mockClipboardEmpty } from '../../generic/data/api.mock'; import { mockContentSearchConfig, mockSearchResult } from '../../search-manager/data/api.mock'; import { studioHomeMock } from '../../studio-home/__mocks__'; import { getStudioHomeApiUrl } from '../../studio-home/data/api'; +import { getApiWaffleFlagsUrl } from '../../data/api'; +import { fetchWaffleFlags } from '../../data/thunks'; import LibraryLayout from '../LibraryLayout'; mockContentSearchConfig.applyMock(); @@ -47,10 +51,17 @@ const renderOpts = { routerProps: { initialEntries: [`/library/${libraryId}/components`] }, }; +let store; + describe('AddContentWorkflow test', () => { - beforeEach(() => { + beforeEach(async () => { const { axiosMock } = initializeMocks(); + store = initializeStore(); axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock); + axiosMock + .onGet(getApiWaffleFlagsUrl()) + .reply(200, {}); + await executeThunk(fetchWaffleFlags(), store.dispatch); }); it('can create an HTML component', async () => { diff --git a/src/library-authoring/add-content/PickLibraryContentModal.test.tsx b/src/library-authoring/add-content/PickLibraryContentModal.test.tsx index b7425a7eeb..aa9f2c6c1f 100644 --- a/src/library-authoring/add-content/PickLibraryContentModal.test.tsx +++ b/src/library-authoring/add-content/PickLibraryContentModal.test.tsx @@ -6,6 +6,8 @@ import { screen, initializeMocks, } from '../../testUtils'; +import initializeStore from '../../store'; +import { executeThunk } from '../../utils'; import { studioHomeMock } from '../../studio-home/__mocks__'; import { getStudioHomeApiUrl } from '../../studio-home/data/api'; import mockResult from '../__mocks__/library-search.json'; @@ -17,6 +19,8 @@ import { mockGetCollectionMetadata, } from '../data/api.mocks'; import { PickLibraryContentModal } from './PickLibraryContentModal'; +import { getApiWaffleFlagsUrl } from '../../data/api'; +import { fetchWaffleFlags } from '../../data/thunks'; mockContentSearchConfig.applyMock(); mockContentLibrary.applyMock(); @@ -27,6 +31,7 @@ const { libraryId } = mockContentLibrary; const onClose = jest.fn(); let mockShowToast: (message: string) => void; +let store; const render = () => baseRender(, { path: '/library/:libraryId/collection/:collectionId/*', @@ -43,10 +48,15 @@ const render = () => baseRender(', () => { - beforeEach(() => { + beforeEach(async () => { const mocks = initializeMocks(); + store = initializeStore(); mockShowToast = mocks.mockShowToast; mocks.axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock); + mocks.axiosMock + .onGet(getApiWaffleFlagsUrl()) + .reply(200, {}); + await executeThunk(fetchWaffleFlags(), store.dispatch); }); it('can pick components from the modal', async () => {