Convert OrgProfile test to RTL (#50525)

This commit is contained in:
Ashley Harrison 2022-06-09 16:07:40 +01:00 committed by GitHub
parent 6151320020
commit 6da4feb2a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 25 deletions

View File

@ -146,9 +146,6 @@ exports[`no enzyme tests`] = {
"public/app/features/org/OrgDetailsPage.test.tsx:3835042085": [
[0, 19, 13, "RegExp match", "2409514259"]
],
"public/app/features/org/OrgProfile.test.tsx:623809345": [
[0, 19, 13, "RegExp match", "2409514259"]
],
"public/app/features/teams/TeamSettings.test.tsx:2043271249": [
[0, 19, 13, "RegExp match", "2409514259"]
],

View File

@ -1,4 +1,5 @@
import { shallow } from 'enzyme';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import OrgProfile, { Props } from './OrgProfile';
@ -11,19 +12,36 @@ jest.mock('app/core/core', () => {
};
});
const setup = () => {
describe('OrgProfile', () => {
const props: Props = {
orgName: 'Main org',
onSubmit: jest.fn(),
};
return shallow(<OrgProfile {...props} />);
};
it('should render without crashing', () => {
expect(() => render(<OrgProfile {...props} />)).not.toThrow();
});
describe('Render', () => {
it('should render component', () => {
const wrapper = setup();
it('should show the current org name', () => {
render(<OrgProfile {...props} />);
expect(wrapper).toMatchSnapshot();
const orgNameInput = screen.getByLabelText('Organization name');
expect(orgNameInput).toHaveValue('Main org');
});
it('can update the current org name', async () => {
render(<OrgProfile {...props} />);
const orgNameInput = screen.getByLabelText('Organization name');
const submitButton = screen.getByRole('button', { name: 'Update organization name' });
expect(orgNameInput).toHaveValue('Main org');
await userEvent.clear(orgNameInput);
await userEvent.type(orgNameInput, 'New org name');
await userEvent.click(submitButton);
expect(props.onSubmit).toHaveBeenCalledWith('New org name');
});
});

View File

@ -1,14 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Render should render component 1`] = `
<Form
defaultValues={
Object {
"orgName": "Main org",
}
}
onSubmit={[Function]}
>
<Component />
</Form>
`;