Skip to content

Commit 294fe42

Browse files
authored
feat: add support for origin server and user info (#2663)
* feat: add support for origin server and user info * test: add coverage for restore archive summary * test: increase coverage for restore archive summary * fix: address comments
1 parent 95ec41d commit 294fe42

File tree

3 files changed

+91
-9
lines changed

3 files changed

+91
-9
lines changed

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

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ describe('<CreateLibrary />', () => {
435435
sections: 8,
436436
subsections: 12,
437437
units: 20,
438-
createdOnServer: '2025-01-01T10:00:00Z',
438+
createdOnServer: 'test.com',
439439
createdAt: '2025-01-01T10:00:00Z',
440440
createdBy: {
441441
username: 'testuser',
@@ -478,7 +478,67 @@ describe('<CreateLibrary />', () => {
478478
await waitFor(() => {
479479
expect(screen.getByText('Test Archive Library')).toBeInTheDocument();
480480
expect(screen.getByText('TestOrg / test-archive')).toBeInTheDocument();
481-
expect(screen.getByText(/Contains 15 Components/i)).toBeInTheDocument();
481+
// Testing the archive details summary
482+
expect(screen.getByText(/Contains 8 sections, 12 subsections, 20 units, 15 components/i)).toBeInTheDocument();
483+
expect(screen.getByText(/Created on instance test.com/i)).toBeInTheDocument();
484+
expect(screen.getByText(/by user test@example.com/i)).toBeInTheDocument();
485+
});
486+
});
487+
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.getByRole('presentation', { hidden: true });
532+
const input = dropzone.querySelector('input[type="file"]') as HTMLInputElement;
533+
534+
await user.upload(input, file);
535+
536+
// Wait for the restore to complete and archive details to be shown
537+
await waitFor(() => {
538+
// Testing the archive details summary without instance and user email
539+
expect(screen.getByText(/Contains 8 sections, 12 subsections, 20 units, 15 components/i)).toBeInTheDocument();
540+
expect(screen.queryByText(/Created on instance/i)).not.toBeInTheDocument();
541+
expect(screen.queryByText(/by user/i)).not.toBeInTheDocument();
482542
});
483543
});
484544

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import {
1616
AccessTime,
1717
Widgets,
18+
PersonOutline,
1819
} from '@openedx/paragon/icons';
1920
import AlertError from '@src/generic/alert-error';
2021
import classNames from 'classnames';
@@ -203,22 +204,38 @@ export const CreateLibrary = ({
203204
<Card.Body>
204205
<div className="d-flex flex-column flex-md-row justify-content-between align-items-start p-4 text-primary-700">
205206
<div className="flex-grow-1 mb-4 mb-md-0">
206-
<span className="mb-2">{restoreStatus.result.title}</span>
207+
<span className="mb-4">{restoreStatus.result.title}</span>
207208
<p className="small mb-0">
208209
{restoreStatus.result.org} / {restoreStatus.result.slug}
209210
</p>
210211
</div>
211-
<div className="d-flex flex-column gap-2 align-items-md-end">
212+
<div className="d-flex flex-column gap-2 align-items-md-start">
212213
<div className="d-flex align-items-md-center gap-2">
213-
<Icon src={Widgets} style={{ width: '20px', height: '20px', marginRight: '8px' }} />
214+
<Icon src={Widgets} className="mr-2" style={{ width: '20px', height: '20px' }} />
214215
<span className="x-small">
215216
{intl.formatMessage(messages.archiveComponentsCount, {
216-
count: restoreStatus.result.components,
217+
countSections: restoreStatus.result.sections,
218+
countSubsections: restoreStatus.result.subsections,
219+
countUnits: restoreStatus.result.units,
220+
countComponents: restoreStatus.result.components,
217221
})}
218222
</span>
219223
</div>
224+
{
225+
(restoreStatus.result.createdBy?.email && restoreStatus.result.createdOnServer) && (
226+
<div className="d-flex align-items-md-center gap-2">
227+
<Icon src={PersonOutline} className="mr-2" style={{ width: '20px', height: '20px' }} />
228+
<span className="x-small">
229+
{intl.formatMessage(messages.archiveRestoredCreatedBy, {
230+
createdBy: restoreStatus.result.createdBy?.email,
231+
server: restoreStatus.result.createdOnServer,
232+
})}
233+
</span>
234+
</div>
235+
)
236+
}
220237
<div className="d-flex align-items-md-center gap-2">
221-
<Icon src={AccessTime} style={{ width: '20px', height: '20px', marginRight: '8px' }} />
238+
<Icon src={AccessTime} className="mr-2" style={{ width: '20px', height: '20px' }} />
222239
<span className="x-small">
223240
{intl.formatMessage(messages.archiveBackupDate, {
224241
date: new Date(restoreStatus.result.createdAt).toLocaleDateString(),

src/library-authoring/create-library/messages.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ const messages = defineMessages({
120120
},
121121
archiveComponentsCount: {
122122
id: 'course-authoring.library-authoring.create-library.form.archive.components-count',
123-
defaultMessage: 'Contains {count} Components',
124-
description: 'Text showing the number of components in the restored archive.',
123+
defaultMessage: 'Contains {countSections} sections, {countSubsections} subsections, {countUnits} units, {countComponents} components',
124+
description: 'Text showing the number of sections, subsections, units, and components in the restored archive.',
125+
},
126+
archiveRestoredCreatedBy: {
127+
id: 'course-authoring.library-authoring.create-library.form.archive.restored-created-by',
128+
defaultMessage: 'Created on instance {server}, by user {createdBy}',
129+
description: 'Text showing who restored the archive.',
125130
},
126131
archiveBackupDate: {
127132
id: 'course-authoring.library-authoring.create-library.form.archive.backup-date',

0 commit comments

Comments
 (0)