Skip to content

Commit 4a8a638

Browse files
committed
fixup! feat: improve collection sidebar
1 parent 5cc6ba1 commit 4a8a638

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,46 @@ describe('<CollectionInfoHeader />', () => {
4848
expect(textBox).not.toBeInTheDocument();
4949
expect(mockShowToast).toHaveBeenCalledWith('Collection updated successfully.');
5050
});
51+
52+
it('should close edit collection title on press Escape', async () => {
53+
const { axiosMock, mockShowToast } = initializeMocks();
54+
const library = await mockContentLibrary(mockContentLibrary.libraryId);
55+
render(<CollectionInfoHeader library={library} collection={mockCollectionHit} />);
56+
const url = api.getLibraryCollectionApiUrl(library.id, mockCollectionHit.blockId);
57+
axiosMock.onPatch(url).reply(200);
58+
59+
fireEvent.click(screen.getByRole('button', { name: /edit collection title/i }));
60+
61+
const textBox = screen.getByRole('textbox', { name: /title input/i });
62+
63+
fireEvent.change(textBox, { target: { value: 'New Collection Title' } });
64+
fireEvent.keyDown(textBox, { key: 'Escape', code: 'Escape', charCode: 27 });
65+
66+
await waitFor(() => expect(axiosMock.history.patch.length).toEqual(0));
67+
68+
expect(textBox).not.toBeInTheDocument();
69+
});
70+
71+
it('should show error on edit collection tittle', async () => {
72+
const { axiosMock, mockShowToast } = initializeMocks();
73+
const library = await mockContentLibrary(mockContentLibrary.libraryId);
74+
render(<CollectionInfoHeader library={library} collection={mockCollectionHit} />);
75+
const url = api.getLibraryCollectionApiUrl(library.id, mockCollectionHit.blockId);
76+
axiosMock.onPatch(url).reply(500);
77+
78+
fireEvent.click(screen.getByRole('button', { name: /edit collection title/i }));
79+
80+
const textBox = screen.getByRole('textbox', { name: /title input/i });
81+
82+
fireEvent.change(textBox, { target: { value: 'New Collection Title' } });
83+
fireEvent.keyDown(textBox, { key: 'Enter', code: 'Enter', charCode: 13 });
84+
85+
await waitFor(() => {
86+
expect(axiosMock.history.patch[0].url).toEqual(url);
87+
expect(axiosMock.history.patch[0].data).toEqual(JSON.stringify({ title: 'New Collection Title' }));
88+
});
89+
90+
expect(textBox).not.toBeInTheDocument();
91+
expect(mockShowToast).toHaveBeenCalledWith('Failed to update collection.');
92+
});
5193
});

0 commit comments

Comments
 (0)