Chore: Converts SaveDashboardForm tests to RTL (#49434)

This commit is contained in:
Joao Silva 2022-05-23 18:17:25 +01:00 committed by GitHub
parent 8af587e7ba
commit 51bc1bad1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 20 deletions

View File

@ -149,9 +149,6 @@ exports[`no enzyme tests`] = {
"public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardAsForm.test.tsx:1969004590": [
[0, 17, 13, "RegExp match", "2409514259"]
],
"public/app/features/dashboard/components/SaveDashboard/forms/SaveDashboardForm.test.tsx:948029434": [
[0, 17, 13, "RegExp match", "2409514259"]
],
"public/app/features/dashboard/components/ShareModal/ShareLink.test.tsx:2357087833": [
[0, 35, 13, "RegExp match", "2409514259"]
],

View File

@ -1,6 +1,6 @@
import { mount } from 'enzyme';
import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { act } from 'react-dom/test-utils';
import { DashboardModel } from 'app/features/dashboard/state';
@ -31,7 +31,7 @@ const prepareDashboardMock = (
};
};
const renderAndSubmitForm = async (dashboard: any, submitSpy: any) => {
const container = mount(
render(
<SaveDashboardForm
dashboard={dashboard as DashboardModel}
onCancel={() => {}}
@ -53,16 +53,13 @@ const renderAndSubmitForm = async (dashboard: any, submitSpy: any) => {
/>
);
// @ts-ignore strict null error below
await act(async () => {
const button = container.find('button[aria-label="Dashboard settings Save Dashboard Modal Save button"]');
button.simulate('submit');
});
const button = screen.getByRole('button', { name: 'Dashboard settings Save Dashboard Modal Save button' });
await userEvent.click(button);
};
describe('SaveDashboardAsForm', () => {
describe('time and variables toggle rendering', () => {
it('renders switches when variables or timerange', () => {
const container = mount(
render(
<SaveDashboardForm
dashboard={prepareDashboardMock(true, true, jest.fn(), jest.fn()) as any}
onCancel={() => {}}
@ -83,15 +80,15 @@ describe('SaveDashboardAsForm', () => {
/>
);
const variablesCheckbox = container.find(
'input[aria-label="Dashboard settings Save Dashboard Modal Save variables checkbox"]'
);
const timeRangeCheckbox = container.find(
'input[aria-label="Dashboard settings Save Dashboard Modal Save timerange checkbox"]'
);
const variablesCheckbox = screen.getByRole('checkbox', {
name: 'Dashboard settings Save Dashboard Modal Save variables checkbox',
});
const timeRangeCheckbox = screen.getByRole('checkbox', {
name: 'Dashboard settings Save Dashboard Modal Save timerange checkbox',
});
expect(variablesCheckbox).toHaveLength(1);
expect(timeRangeCheckbox).toHaveLength(1);
expect(variablesCheckbox).toBeInTheDocument();
expect(timeRangeCheckbox).toBeInTheDocument();
});
});