Convert FormField tests to RTL (#49068)

This commit is contained in:
Ashley Harrison 2022-05-17 13:26:48 +01:00 committed by GitHub
parent e5925b2e91
commit bddbed4e21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 56 deletions

View File

@ -8,9 +8,6 @@ exports[`no enzyme tests`] = {
"packages/grafana-ui/src/components/BarGauge/BarGauge.test.tsx:4199795290": [
[0, 19, 13, "RegExp match", "2409514259"]
],
"packages/grafana-ui/src/components/FormField/FormField.test.tsx:3429087660": [
[0, 19, 13, "RegExp match", "2409514259"]
],
"packages/grafana-ui/src/components/Forms/Legacy/Input/Input.test.tsx:3129955645": [
[0, 19, 13, "RegExp match", "2409514259"]
],

View File

@ -1,4 +1,4 @@
import { shallow } from 'enzyme';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { FormField, Props } from './FormField';
@ -13,26 +13,20 @@ const setup = (propOverrides?: Partial<Props>) => {
Object.assign(props, propOverrides);
return shallow(<FormField {...props} />);
render(<FormField {...props} />);
};
describe('FormField', () => {
it('should render component with default inputEl', () => {
const wrapper = setup();
expect(wrapper).toMatchSnapshot();
it('should render a default inputEl', () => {
setup();
expect(screen.getByRole('textbox')).toBeInTheDocument();
});
it('should render component with custom inputEl', () => {
const wrapper = setup({
inputEl: (
<>
<span>Input</span>
<button>Ok</button>
</>
),
it('should render a custom inputEl instead if specified', () => {
setup({
inputEl: <input role="checkbox" />,
});
expect(wrapper).toMatchSnapshot();
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
expect(screen.getByRole('checkbox')).toBeInTheDocument();
});
});

View File

@ -1,37 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`FormField should render component with custom inputEl 1`] = `
<div
className="css-aq4c43"
>
<FormLabel
width={11}
>
Test
</FormLabel>
<span>
Input
</span>
<button>
Ok
</button>
</div>
`;
exports[`FormField should render component with default inputEl 1`] = `
<div
className="css-aq4c43"
>
<FormLabel
width={11}
>
Test
</FormLabel>
<input
className="gf-form-input width-12"
onChange={[MockFunction]}
type="text"
value={10}
/>
</div>
`;