Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
18 changes: 16 additions & 2 deletions src/library-authoring/LibraryAuthoringPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -50,11 +54,17 @@ const returnEmptyResult = (_url, req) => {

const path = '/library/:libraryId/*';
const libraryTitle = mockContentLibrary.libraryData.title;
let store;

describe('<LibraryAuthoringPage />', () => {
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();
Expand Down Expand Up @@ -683,9 +693,13 @@ describe('<LibraryAuthoringPage />', () => {
...studioHomeMock,
libraries_v2_enabled: false,
});
axiosMock
.onGet(getApiWaffleFlagsUrl())
.reply(200, {});
await executeThunk(fetchWaffleFlags(), store.dispatch);

render(<LibraryLayout />, { 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.');
});
});
13 changes: 12 additions & 1 deletion src/library-authoring/add-content/AddContentWorkflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand All @@ -27,6 +31,7 @@ const { libraryId } = mockContentLibrary;

const onClose = jest.fn();
let mockShowToast: (message: string) => void;
let store;

const render = () => baseRender(<PickLibraryContentModal isOpen onClose={onClose} />, {
path: '/library/:libraryId/collection/:collectionId/*',
Expand All @@ -43,10 +48,15 @@ const render = () => baseRender(<PickLibraryContentModal isOpen onClose={onClose
});

describe('<PickLibraryContentModal />', () => {
beforeEach(() => {
beforeEach(async () => {
const mocks = initializeMocks();
store = initializeStore();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not call initializeStore() after calling initializeMocks(); because initializeMocks is already initializing the store. Instead you can use const { reduxStore, ...mocks } = initializeMocks(); and then reduxStore is the store variable.

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 () => {
Expand Down