Skip to content

Commit 47be3ef

Browse files
committed
test: increase coverage for restore archive summary
1 parent 9e1564c commit 47be3ef

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/library-authoring/create-library/CreateLibrary.test.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,68 @@ describe('<CreateLibrary />', () => {
485485
});
486486
});
487487

488+
test('shows success state without instance and user email information', async () => {
489+
const user = userEvent.setup();
490+
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock);
491+
492+
const mockResult = {
493+
learningPackageId: 123,
494+
title: 'Test Archive Library',
495+
org: 'TestOrg',
496+
slug: 'test-archive',
497+
key: 'TestOrg/test-archive',
498+
archiveKey: 'archive-key',
499+
containers: 5,
500+
components: 15,
501+
collections: 3,
502+
sections: 8,
503+
subsections: 12,
504+
units: 20,
505+
createdOnServer: null,
506+
createdAt: '2025-01-01T10:00:00Z',
507+
createdBy: null,
508+
};
509+
510+
// Pre-set the restore status to succeeded
511+
mockRestoreStatusData = {
512+
state: LibraryRestoreStatus.Succeeded,
513+
result: mockResult,
514+
error: null,
515+
errorLog: null,
516+
};
517+
518+
// Mock the restore mutation to return a task ID
519+
mockRestoreMutate.mockImplementation((_file: File, { onSuccess }: any) => {
520+
onSuccess({ taskId: 'task-123' });
521+
});
522+
523+
render(<CreateLibrary />);
524+
525+
// Switch to archive mode
526+
const createFromArchiveBtn = await screen.findByRole('button', { name: messages.createFromArchiveButton.defaultMessage });
527+
await user.click(createFromArchiveBtn);
528+
529+
// Upload a file to trigger the restore process
530+
const file = new File(['test content'], 'test-archive.zip', { type: 'application/zip' });
531+
const dropzone = screen.getByTestId('library-archive-dropzone');
532+
const input = dropzone.querySelector('input[type="file"]') as HTMLInputElement;
533+
534+
Object.defineProperty(input, 'files', {
535+
value: [file],
536+
writable: false,
537+
});
538+
539+
fireEvent.change(input);
540+
541+
// Wait for the restore to complete and archive details to be shown
542+
await waitFor(() => {
543+
// Testing the archive details summary without instance and user email
544+
expect(screen.getByText(/Contains 8 sections, 12 subsections, 20 units, 15 components/i)).toBeInTheDocument();
545+
expect(screen.queryByText(/Created on instance/i)).not.toBeInTheDocument();
546+
expect(screen.queryByText(/by user/i)).not.toBeInTheDocument();
547+
});
548+
});
549+
488550
test('shows error state with error message and link after failed upload', async () => {
489551
const user = userEvent.setup();
490552
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock);

0 commit comments

Comments
 (0)