Skip to content

Commit 073d1f4

Browse files
committed
fix: nits and improving coverage
1 parent 0962eab commit 073d1f4

File tree

4 files changed

+98
-8
lines changed

4 files changed

+98
-8
lines changed

src/library-authoring/LibraryAuthoringPage.test.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ describe('<LibraryAuthoringPage />', () => {
394394
await waitFor(() => expect(screen.queryByTestId('library-sidebar')).not.toBeInTheDocument());
395395
});
396396

397-
it('should open component sidebar, showing manage tab on clicking add to collection menu item', async () => {
397+
it('should open component sidebar, showing manage tab on clicking add to collection menu item (component)', async () => {
398398
const mockResult0 = { ...mockResult }.results[0].hits[0];
399399
const displayName = 'Introduction to Testing';
400400
expect(mockResult0.display_name).toStrictEqual(displayName);
@@ -419,6 +419,29 @@ describe('<LibraryAuthoringPage />', () => {
419419
await waitFor(() => expect(screen.queryByTestId('library-sidebar')).not.toBeInTheDocument());
420420
});
421421

422+
it('should open component sidebar, showing manage tab on clicking add to collection menu item (unit)', async () => {
423+
const displayName = 'Test Unit';
424+
await renderLibraryPage();
425+
426+
waitFor(() => expect(screen.getAllByTestId('container-card-menu-toggle').length).toBeGreaterThan(0));
427+
428+
// Open menu
429+
fireEvent.click((await screen.findAllByTestId('container-card-menu-toggle'))[0]);
430+
// Click add to collection
431+
fireEvent.click(screen.getByRole('button', { name: 'Add to collection' }));
432+
433+
const sidebar = screen.getByTestId('library-sidebar');
434+
435+
const { getByRole, queryByText } = within(sidebar);
436+
437+
await waitFor(() => expect(queryByText(displayName)).toBeInTheDocument());
438+
expect(getByRole('tab', { selected: true })).toHaveTextContent('Organize');
439+
const closeButton = getByRole('button', { name: /close/i });
440+
fireEvent.click(closeButton);
441+
442+
await waitFor(() => expect(screen.queryByTestId('library-sidebar')).not.toBeInTheDocument());
443+
});
444+
422445
it('should open and close the collection sidebar', async () => {
423446
await renderLibraryPage();
424447

@@ -734,7 +757,7 @@ describe('<LibraryAuthoringPage />', () => {
734757
fireEvent.click(cancelButton);
735758
expect(unitModalHeading).not.toBeInTheDocument();
736759

737-
// Open new unit modal again and create a collection
760+
// Open new unit modal again and create a unit
738761
fireEvent.click(newUnitButton);
739762
const createButton = screen.getByRole('button', { name: /create/i });
740763
const nameField = screen.getByRole('textbox', { name: /name your unit/i });
@@ -802,7 +825,7 @@ describe('<LibraryAuthoringPage />', () => {
802825
fireEvent.click(newButton);
803826
expect(screen.getByText(/add content/i)).toBeInTheDocument();
804827

805-
// Open New collection Modal
828+
// Open New Unit Modal
806829
const sidebar = screen.getByTestId('library-sidebar');
807830
const newUnitButton = within(sidebar).getAllByRole('button', { name: /unit/i })[0];
808831
fireEvent.click(newUnitButton);

src/library-authoring/__mocks__/collection-search.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,45 @@
218218
"org": "OpenedX",
219219
"access_id": 16,
220220
"num_children": 1
221+
},
222+
{
223+
"display_name": "Test Unit",
224+
"block_id": "test-unit-9284e2",
225+
"id": "lctAximTESTunittest-unit-9284e2-a9a4386e",
226+
"type": "library_container",
227+
"breadcrumbs": [
228+
{
229+
"display_name": "Test Library"
230+
}
231+
],
232+
"created": 1742221203.895054,
233+
"modified": 1742221203.895054,
234+
"usage_key": "lct:Axim:TEST:unit:test-unit-9284e2",
235+
"block_type": "unit",
236+
"context_key": "lib:Axim:TEST",
237+
"org": "Axim",
238+
"access_id": 15,
239+
"num_children": 0,
240+
"_formatted": {
241+
"display_name": "Test Unit",
242+
"block_id": "test-unit-9284e2",
243+
"id": "lctAximTESTunittest-unit-9284e2-a9a4386e",
244+
"type": "library_container",
245+
"breadcrumbs": [
246+
{
247+
"display_name": "Test Library"
248+
}
249+
],
250+
"created": "1742221203.895054",
251+
"modified": "1742221203.895054",
252+
"usage_key": "lct:Axim:TEST:unit:test-unit-9284e2",
253+
"block_type": "unit",
254+
"context_key": "lib:Axim:TEST",
255+
"org": "Axim",
256+
"access_id": "15",
257+
"num_children": "0"
258+
}
221259
}
222-
223260
],
224261
"query": "",
225262
"processingTimeMs": 1,

src/library-authoring/collections/LibraryCollectionPage.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
mockContentLibrary,
1616
mockXBlockFields,
1717
mockGetCollectionMetadata,
18+
mockGetContainerMetadata,
1819
} from '../data/api.mocks';
1920
import { mockContentSearchConfig, mockGetBlockTypes } from '../../search-manager/data/api.mock';
2021
import { mockBroadcastChannel, mockClipboardEmpty } from '../../generic/data/api.mock';
@@ -31,6 +32,7 @@ mockContentSearchConfig.applyMock();
3132
mockGetBlockTypes.applyMock();
3233
mockContentLibrary.applyMock();
3334
mockXBlockFields.applyMock();
35+
mockGetContainerMetadata.applyMock();
3436
mockBroadcastChannel();
3537

3638
const searchEndpoint = 'http://mock.meilisearch.local/multi-search';
@@ -375,4 +377,34 @@ describe('<LibraryCollectionPage />', () => {
375377
// Should close sidebar as component was removed
376378
await waitFor(() => expect(screen.queryByTestId('library-sidebar')).not.toBeInTheDocument());
377379
});
380+
381+
it('should remove unit from collection and hides sidebar', async () => {
382+
const url = getLibraryCollectionItemsApiUrl(
383+
mockContentLibrary.libraryId,
384+
mockCollection.collectionId,
385+
);
386+
axiosMock.onDelete(url).reply(204);
387+
const displayName = 'Test Unit';
388+
await renderLibraryCollectionPage();
389+
390+
// Wait for the unit cards to load
391+
waitFor(() => expect(screen.getAllByTestId('container-card-menu-toggle').length).toBeGreaterThan(0));
392+
393+
// open sidebar
394+
fireEvent.click(await screen.findByText(displayName));
395+
await waitFor(() => expect(screen.queryByTestId('library-sidebar')).toBeInTheDocument());
396+
397+
// Open menu
398+
fireEvent.click((await screen.findAllByTestId('container-card-menu-toggle'))[0]);
399+
400+
// Click remove to collection
401+
fireEvent.click(screen.getByRole('button', { name: 'Remove from collection' }));
402+
403+
await waitFor(() => {
404+
expect(axiosMock.history.delete.length).toEqual(1);
405+
});
406+
expect(mockShowToast).toHaveBeenCalledWith('Item successfully removed');
407+
// Should close sidebar as component was removed
408+
await waitFor(() => expect(screen.queryByTestId('library-sidebar')).not.toBeInTheDocument());
409+
});
378410
});

src/library-authoring/components/ContainerCard.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const ContainerMenu = ({ hit } : ContainerMenuProps) => {
3232
const intl = useIntl();
3333
const {
3434
contextKey,
35-
blockId,
3635
usageKey: containerId,
3736
displayName,
3837
} = hit;
@@ -74,14 +73,13 @@ const ContainerMenu = ({ hit } : ContainerMenuProps) => {
7473
src={MoreVert}
7574
iconAs={Icon}
7675
variant="primary"
77-
alt={intl.formatMessage(messages.collectionCardMenuAlt)}
76+
alt={intl.formatMessage(messages.containerCardMenuAlt)}
7877
data-testid="container-card-menu-toggle"
7978
/>
8079
<Dropdown.Menu>
8180
<Dropdown.Item
8281
as={Link}
83-
to={`/library/${contextKey}/container/${blockId}`}
84-
disabled
82+
to={`/library/${contextKey}/unit/${containerId}`}
8583
>
8684
<FormattedMessage {...messages.menuOpen} />
8785
</Dropdown.Item>

0 commit comments

Comments
 (0)