diff --git a/src/library-authoring/collections/LibraryCollectionPage.test.tsx b/src/library-authoring/collections/LibraryCollectionPage.test.tsx index af9f794a8d..67e4eea084 100644 --- a/src/library-authoring/collections/LibraryCollectionPage.test.tsx +++ b/src/library-authoring/collections/LibraryCollectionPage.test.tsx @@ -33,7 +33,7 @@ const path = '/library/:libraryId/*'; const libraryTitle = mockContentLibrary.libraryData.title; const mockCollection = { collectionId: mockResult.results[2].hits[0].block_id, - collectionNeverLoads: 'collection-always-loading', + collectionNeverLoads: mockGetCollectionMetadata.collectionIdLoading, collectionNoComponents: 'collection-no-components', collectionEmpty: mockGetCollectionMetadata.collectionIdError, }; @@ -108,7 +108,7 @@ describe('', () => { it('shows an error component if no collection returned', async () => { // This mock will simulate incorrect collection id await renderLibraryCollectionPage(mockCollection.collectionEmpty); - expect(await screen.findByText(/Mocked request failed with status code 400./)).toBeInTheDocument(); + expect(await screen.findByText(/Mocked request failed with status code 404./)).toBeInTheDocument(); }); it('shows collection data', async () => { diff --git a/src/library-authoring/data/api.mocks.ts b/src/library-authoring/data/api.mocks.ts index 0a4b824119..220c7576d4 100644 --- a/src/library-authoring/data/api.mocks.ts +++ b/src/library-authoring/data/api.mocks.ts @@ -281,13 +281,22 @@ mockLibraryBlockMetadata.applyMock = () => jest.spyOn(api, 'getLibraryBlockMetad * This mock returns a fixed response for the collection ID *collection_1*. */ export async function mockGetCollectionMetadata(libraryId: string, collectionId: string): Promise { - if (collectionId === mockGetCollectionMetadata.collectionIdError) { - throw createAxiosError({ code: 400, message: 'Not found.', path: api.getLibraryCollectionApiUrl(libraryId, collectionId) }); + switch (collectionId) { + case mockGetCollectionMetadata.collectionIdError: + throw createAxiosError({ + code: 404, + message: 'Not found.', + path: api.getLibraryCollectionApiUrl(libraryId, collectionId), + }); + case mockGetCollectionMetadata.collectionIdLoading: + return new Promise(() => {}); + default: + return Promise.resolve(mockGetCollectionMetadata.collectionData); } - return Promise.resolve(mockGetCollectionMetadata.collectionData); } mockGetCollectionMetadata.collectionId = 'collection_1'; mockGetCollectionMetadata.collectionIdError = 'collection_error'; +mockGetCollectionMetadata.collectionIdLoading = 'collection_loading'; mockGetCollectionMetadata.collectionData = { id: 1, key: 'collection_1',