From 3a1e7dc3c5f573493ff199a750bbaa04630c2adc Mon Sep 17 00:00:00 2001 From: AmbrishRamachandiran Date: Mon, 14 Aug 2023 16:36:39 +0530 Subject: [PATCH] Added test cases for duplicate url and title Signed-off-by: AmbrishRamachandiran --- plugins/shortcuts/src/ShortcutForm.test.tsx | 37 +++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/plugins/shortcuts/src/ShortcutForm.test.tsx b/plugins/shortcuts/src/ShortcutForm.test.tsx index 56309b4a64..388c072725 100644 --- a/plugins/shortcuts/src/ShortcutForm.test.tsx +++ b/plugins/shortcuts/src/ShortcutForm.test.tsx @@ -53,15 +53,40 @@ describe('ShortcutForm', () => { expect( screen.getByText('Must be at least 2 characters'), ).toBeInTheDocument(); - expect( - screen.queryByText('A shortcut with this title already exists'), - ).not.toBeInTheDocument(); - expect( - screen.queryByText('A shortcut with this url already exists'), - ).not.toBeInTheDocument(); }); }); + it('displays duplicate validation messages for title and URL', async () => { + const mockShortcutApi = new DefaultShortcutsApi(MockStorageApi.create()); + mockShortcutApi.add({ title: 'Existing Title', url: '/existing-url' }); + + await renderInTestApp( + + + , + ); + + const urlInput = screen.getByPlaceholderText('Enter a URL'); + const titleInput = screen.getByPlaceholderText('Enter a display name'); + + fireEvent.change(urlInput, { target: { value: '/existing-url' } }); + fireEvent.change(titleInput, { target: { value: 'Existing Title' } }); + + fireEvent.click(screen.getByText('Save')); + + await waitFor(() => { + expect( + screen.getByText('A shortcut with this title already exists'), + ).toBeInTheDocument(); + expect( + screen.getByText('A shortcut with this url already exists'), + ).toBeInTheDocument(); + }); + + expect(props.onSave).not.toHaveBeenCalled(); + expect(props.onClose).not.toHaveBeenCalled(); + }); + it('allows external links', async () => { await renderInTestApp(