Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
69 changes: 67 additions & 2 deletions src/library-authoring/create-library/CreateLibrary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ describe('<CreateLibrary />', () => {
sections: 8,
subsections: 12,
units: 20,
createdOnServer: '2025-01-01T10:00:00Z',
createdOnServer: 'test.com',
createdAt: '2025-01-01T10:00:00Z',
createdBy: {
username: 'testuser',
Expand Down Expand Up @@ -478,7 +478,72 @@ describe('<CreateLibrary />', () => {
await waitFor(() => {
expect(screen.getByText('Test Archive Library')).toBeInTheDocument();
expect(screen.getByText('TestOrg / test-archive')).toBeInTheDocument();
expect(screen.getByText(/Contains 15 Components/i)).toBeInTheDocument();
// Testing the archive details summary
expect(screen.getByText(/Contains 8 sections, 12 subsections, 20 units, 15 components/i)).toBeInTheDocument();
expect(screen.getByText(/Created on instance test.com/i)).toBeInTheDocument();
expect(screen.getByText(/by user [email protected]/i)).toBeInTheDocument();
});
});

test('shows success state without instance and user email information', async () => {
const user = userEvent.setup();
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, studioHomeMock);

const mockResult = {
learningPackageId: 123,
title: 'Test Archive Library',
org: 'TestOrg',
slug: 'test-archive',
key: 'TestOrg/test-archive',
archiveKey: 'archive-key',
containers: 5,
components: 15,
collections: 3,
sections: 8,
subsections: 12,
units: 20,
createdOnServer: null,
createdAt: '2025-01-01T10:00:00Z',
createdBy: null,
};

// Pre-set the restore status to succeeded
mockRestoreStatusData = {
state: LibraryRestoreStatus.Succeeded,
result: mockResult,
error: null,
errorLog: null,
};

// Mock the restore mutation to return a task ID
mockRestoreMutate.mockImplementation((_file: File, { onSuccess }: any) => {
onSuccess({ taskId: 'task-123' });
});

render(<CreateLibrary />);

// Switch to archive mode
const createFromArchiveBtn = await screen.findByRole('button', { name: messages.createFromArchiveButton.defaultMessage });
await user.click(createFromArchiveBtn);

// Upload a file to trigger the restore process
const file = new File(['test content'], 'test-archive.zip', { type: 'application/zip' });
const dropzone = screen.getByTestId('library-archive-dropzone');
Comment thread
bradenmacdonald marked this conversation as resolved.
Outdated
const input = dropzone.querySelector('input[type="file"]') as HTMLInputElement;

Object.defineProperty(input, 'files', {
value: [file],
writable: false,
});

fireEvent.change(input);
Comment thread
bradenmacdonald marked this conversation as resolved.
Outdated

// Wait for the restore to complete and archive details to be shown
await waitFor(() => {
// Testing the archive details summary without instance and user email
expect(screen.getByText(/Contains 8 sections, 12 subsections, 20 units, 15 components/i)).toBeInTheDocument();
expect(screen.queryByText(/Created on instance/i)).not.toBeInTheDocument();
expect(screen.queryByText(/by user/i)).not.toBeInTheDocument();
});
});

Expand Down
23 changes: 20 additions & 3 deletions src/library-authoring/create-library/CreateLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
AccessTime,
Widgets,
PersonOutline,
} from '@openedx/paragon/icons';
import AlertError from '@src/generic/alert-error';
import classNames from 'classnames';
Expand Down Expand Up @@ -203,20 +204,36 @@ export const CreateLibrary = ({
<Card.Body>
<div className="d-flex flex-column flex-md-row justify-content-between align-items-start p-4 text-primary-700">
<div className="flex-grow-1 mb-4 mb-md-0">
<span className="mb-2">{restoreStatus.result.title}</span>
<span className="mb-4">{restoreStatus.result.title}</span>
<p className="small mb-0">
{restoreStatus.result.org} / {restoreStatus.result.slug}
</p>
</div>
<div className="d-flex flex-column gap-2 align-items-md-end">
<div className="d-flex flex-column gap-2 align-items-md-start">
<div className="d-flex align-items-md-center gap-2">
<Icon src={Widgets} style={{ width: '20px', height: '20px', marginRight: '8px' }} />
<span className="x-small">
{intl.formatMessage(messages.archiveComponentsCount, {
count: restoreStatus.result.components,
countSections: restoreStatus.result.sections,
countSubsections: restoreStatus.result.subsections,
countUnits: restoreStatus.result.units,
countComponents: restoreStatus.result.components,
})}
</span>
</div>
{
(restoreStatus.result.createdBy?.email && restoreStatus.result.createdOnServer) && (
<div className="d-flex align-items-md-center gap-2">
<Icon src={PersonOutline} style={{ width: '20px', height: '20px', marginRight: '8px' }} />
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.

instead of inline styling for margin can we use bootstrap classes? like: 'mr-2'

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks

<span className="x-small">
{intl.formatMessage(messages.archiveRestoredCreatedBy, {
createdBy: restoreStatus.result.createdBy?.email,
server: restoreStatus.result.createdOnServer,
})}
</span>
</div>
)
}
<div className="d-flex align-items-md-center gap-2">
<Icon src={AccessTime} style={{ width: '20px', height: '20px', marginRight: '8px' }} />
<span className="x-small">
Expand Down
7 changes: 6 additions & 1 deletion src/library-authoring/create-library/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ const messages = defineMessages({
},
archiveComponentsCount: {
id: 'course-authoring.library-authoring.create-library.form.archive.components-count',
defaultMessage: 'Contains {count} Components',
defaultMessage: 'Contains {countSections} sections, {countSubsections} subsections, {countUnits} units, {countComponents} components',
description: 'Text showing the number of components in the restored archive.',
Comment thread
bradenmacdonald marked this conversation as resolved.
Outdated
},
archiveRestoredCreatedBy: {
id: 'course-authoring.library-authoring.create-library.form.archive.restored-created-by',
defaultMessage: 'Created on instance {server}, by user {createdBy}',
description: 'Text showing who restored the archive.',
},
archiveBackupDate: {
id: 'course-authoring.library-authoring.create-library.form.archive.backup-date',
defaultMessage: 'Backed up {date} at {time}',
Expand Down