Skip to content

Commit 43016d7

Browse files
committed
chore: update test to prevent issues with useContentLibrary
1 parent b31ad58 commit 43016d7

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/library-authoring/backup-restore/LibraryBackupPage.test.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import { LibraryBackupStatus } from './data/constants';
1111
import { LibraryBackupPage } from './LibraryBackupPage';
1212
import messages from './messages';
1313

14-
mockContentLibrary.applyMock();
15-
const mockLibraryId = mockContentLibrary.libraryId;
16-
const render = (libraryId: string = mockLibraryId) => baseRender(<LibraryBackupPage />, {
14+
const render = (libraryId: string = mockContentLibrary.libraryId) => baseRender(<LibraryBackupPage />, {
1715
extraWrapper: ({ children }) => (
1816
<LibraryProvider libraryId={libraryId}>{children}</LibraryProvider>
1917
),
@@ -26,6 +24,13 @@ jest.mock('@edx/frontend-platform/i18n', () => ({
2624
}),
2725
}));
2826

27+
const mockLibraryData:
28+
{ data: typeof mockContentLibrary.libraryData | undefined } = { data: mockContentLibrary.libraryData };
29+
30+
jest.mock('@src/library-authoring/data/apiHooks', () => ({
31+
useContentLibrary: () => (mockLibraryData),
32+
}));
33+
2934
// Mutable mocks varied per test
3035
const mockMutate = jest.fn();
3136
let mockStatusData: any = {};
@@ -46,18 +51,17 @@ describe('<LibraryBackupPage />', () => {
4651
mockMutate.mockReset();
4752
mockStatusData = {};
4853
mockMutationError = null;
54+
mockLibraryData.data = mockContentLibrary.libraryData;
4955
});
5056

5157
it('returns NotFoundAlert if no libraryData', () => {
52-
mockContentLibrary.libraryData = null as any;
53-
54-
render();
58+
mockLibraryData.data = undefined as any;
59+
render(mockContentLibrary.libraryIdThatNeverLoads);
5560

5661
expect(screen.getByText(/Not Found/i)).toBeVisible();
5762
});
5863

5964
it('renders the backup page title and initial download button', () => {
60-
mockStatusData = {};
6165
render();
6266
expect(screen.getByText(messages.backupPageTitle.defaultMessage)).toBeVisible();
6367
const button = screen.getByRole('button', { name: messages.downloadAriaLabel.defaultMessage });
@@ -223,7 +227,7 @@ describe('<LibraryBackupPage />', () => {
223227
// Verify the download was triggered
224228
expect(createElementSpy).toHaveBeenCalledWith('a');
225229
expect(mockAnchor.href).toContain('/api/libraries/v2/backup/download/test-backup.tar.gz');
226-
expect(mockAnchor.download).toBe('test-lib-backup.tar.gz');
230+
expect(mockAnchor.download).toContain('backup.tar.gz');
227231
expect(mockAnchor.click).toHaveBeenCalled();
228232
expect(appendChildSpy).toHaveBeenCalledWith(mockAnchor);
229233
expect(removeChildSpy).toHaveBeenCalledWith(mockAnchor);

0 commit comments

Comments
 (0)