Skip to content

Commit 7cbb250

Browse files
committed
test: fix search api call count
1 parent 58499a5 commit 7cbb250

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/library-authoring/collections/LibraryCollectionPage.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import mockResult from '../__mocks__/collection-search.json';
1212
import {
1313
mockContentLibrary, mockLibraryBlockTypes, mockXBlockFields,
1414
} from '../data/api.mocks';
15-
import { mockContentSearchConfig } from '../../search-manager/data/api.mock';
15+
import { mockContentSearchConfig, mockGetBlockTypes } from '../../search-manager/data/api.mock';
1616
import { mockBroadcastChannel } from '../../generic/data/api.mock';
1717
import { LibraryLayout } from '..';
1818

1919
mockContentSearchConfig.applyMock();
20+
mockGetBlockTypes.applyMock();
2021
mockContentLibrary.applyMock();
2122
mockLibraryBlockTypes.applyMock();
2223
mockXBlockFields.applyMock();
@@ -87,8 +88,7 @@ describe('<LibraryCollectionPage />', () => {
8788
});
8889

8990
if (colId !== mockCollection.collectionNeverLoads) {
90-
// TODO: Check why the search endpoint is called 3 times
91-
await waitFor(() => { expect(fetchMock).toHaveFetchedTimes(3, searchEndpoint, 'post'); });
91+
await waitFor(() => { expect(fetchMock).toHaveFetchedTimes(1, searchEndpoint, 'post'); });
9292
}
9393
};
9494

@@ -112,8 +112,6 @@ describe('<LibraryCollectionPage />', () => {
112112
expect((await screen.findAllByText(libraryTitle))[0]).toBeInTheDocument();
113113
expect((await screen.findAllByText(mockCollection.title))[0]).toBeInTheDocument();
114114

115-
expect(screen.queryByText('This collection is currently empty.')).not.toBeInTheDocument();
116-
117115
// "Recently Modified" sort shown
118116
expect(screen.getAllByText('Recently Modified').length).toEqual(1);
119117
expect((await screen.findAllByText('Introduction to Testing'))[0]).toBeInTheDocument();
@@ -128,7 +126,8 @@ describe('<LibraryCollectionPage />', () => {
128126
expect((await screen.findAllByText(libraryTitle))[0]).toBeInTheDocument();
129127
expect((await screen.findAllByText(mockCollection.title))[0]).toBeInTheDocument();
130128

131-
expect(screen.getAllByText('This collection is currently empty.')[0]).toBeInTheDocument();
129+
// In the collection page and in the sidebar
130+
expect(screen.getAllByText('This collection is currently empty.').length).toEqual(2);
132131

133132
const addComponentButton = screen.getAllByRole('button', { name: /new/i })[1];
134133
fireEvent.click(addComponentButton);
@@ -151,7 +150,8 @@ describe('<LibraryCollectionPage />', () => {
151150
await renderLibraryCollectionPage(mockCollection.collectionNoComponents, libraryId);
152151

153152
expect(await screen.findByText('All Collections')).toBeInTheDocument();
154-
expect(screen.getAllByText('This collection is currently empty.')[0]).toBeInTheDocument();
153+
// In the collection page and in the sidebar
154+
expect(screen.getAllByText('This collection is currently empty.').length).toEqual(2);
155155
expect(screen.queryByRole('button', { name: /new/i })).not.toBeInTheDocument();
156156
expect(screen.getByText('Read Only')).toBeInTheDocument();
157157
});

0 commit comments

Comments
 (0)