mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Playlists: Save button now correctly creates a new playlist (#50381)
* Add type="submit" to PlaylistForm submit button * fix linting errors
This commit is contained in:
parent
6e3d58d779
commit
a1cf709ad2
@ -1,5 +1,5 @@
|
|||||||
import { within } from '@testing-library/dom';
|
import { within } from '@testing-library/dom';
|
||||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
@ -133,8 +133,8 @@ describe('PlaylistForm', () => {
|
|||||||
it('then the correct item should be submitted', async () => {
|
it('then the correct item should be submitted', async () => {
|
||||||
const { onSubmitMock } = getTestContext(playlist);
|
const { onSubmitMock } = getTestContext(playlist);
|
||||||
|
|
||||||
fireEvent.submit(screen.getByRole('button', { name: /save/i }));
|
await userEvent.click(screen.getByRole('button', { name: /save/i }));
|
||||||
await waitFor(() => expect(onSubmitMock).toHaveBeenCalledTimes(1));
|
expect(onSubmitMock).toHaveBeenCalledTimes(1);
|
||||||
expect(onSubmitMock).toHaveBeenCalledWith(playlist);
|
expect(onSubmitMock).toHaveBeenCalledWith(playlist);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -142,8 +142,8 @@ describe('PlaylistForm', () => {
|
|||||||
it('then an alert should appear and nothing should be submitted', async () => {
|
it('then an alert should appear and nothing should be submitted', async () => {
|
||||||
const { onSubmitMock } = getTestContext({ ...playlist, name: undefined });
|
const { onSubmitMock } = getTestContext({ ...playlist, name: undefined });
|
||||||
|
|
||||||
fireEvent.submit(screen.getByRole('button', { name: /save/i }));
|
await userEvent.click(screen.getByRole('button', { name: /save/i }));
|
||||||
expect(await screen.findAllByRole('alert')).toHaveLength(1);
|
expect(screen.getAllByRole('alert')).toHaveLength(1);
|
||||||
expect(onSubmitMock).not.toHaveBeenCalled();
|
expect(onSubmitMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -153,8 +153,8 @@ describe('PlaylistForm', () => {
|
|||||||
const { onSubmitMock } = getTestContext(playlist);
|
const { onSubmitMock } = getTestContext(playlist);
|
||||||
|
|
||||||
await userEvent.clear(screen.getByRole('textbox', { name: /playlist interval/i }));
|
await userEvent.clear(screen.getByRole('textbox', { name: /playlist interval/i }));
|
||||||
fireEvent.submit(screen.getByRole('button', { name: /save/i }));
|
await userEvent.click(screen.getByRole('button', { name: /save/i }));
|
||||||
expect(await screen.findAllByRole('alert')).toHaveLength(1);
|
expect(screen.getAllByRole('alert')).toHaveLength(1);
|
||||||
expect(onSubmitMock).not.toHaveBeenCalled();
|
expect(onSubmitMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,7 @@ export const PlaylistForm: FC<PlaylistFormProps> = ({ onSubmit, playlist }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<HorizontalGroup>
|
<HorizontalGroup>
|
||||||
<Button variant="primary" disabled={isDisabled}>
|
<Button type="submit" variant="primary" disabled={isDisabled}>
|
||||||
Save
|
Save
|
||||||
</Button>
|
</Button>
|
||||||
<LinkButton variant="secondary" href={`${config.appSubUrl}/playlists`}>
|
<LinkButton variant="secondary" href={`${config.appSubUrl}/playlists`}>
|
||||||
|
Loading…
Reference in New Issue
Block a user