Added test cases for duplicate url and title

Signed-off-by: AmbrishRamachandiran <ambrish.r@infosys.com>
This commit is contained in:
AmbrishRamachandiran
2023-08-14 16:36:39 +05:30
parent bba2d81367
commit 3a1e7dc3c5
+31 -6
View File
@@ -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(
<TestApiProvider apis={[[shortcutsApiRef, mockShortcutApi]]}>
<ShortcutForm {...props} />
</TestApiProvider>,
);
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(
<TestApiProvider