-
Notifications
You must be signed in to change notification settings - Fork 196
feat: add support for origin server and user info #2663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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', | ||
|
|
@@ -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'); | ||
| const input = dropzone.querySelector('input[type="file"]') as HTMLInputElement; | ||
|
|
||
| Object.defineProperty(input, 'files', { | ||
| value: [file], | ||
| writable: false, | ||
| }); | ||
|
|
||
| fireEvent.change(input); | ||
|
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(); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import { | |
| import { | ||
| AccessTime, | ||
| Widgets, | ||
| PersonOutline, | ||
| } from '@openedx/paragon/icons'; | ||
| import AlertError from '@src/generic/alert-error'; | ||
| import classNames from 'classnames'; | ||
|
|
@@ -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' }} /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.