Chore: Converts ButtonRow tests to RTL (#51068)

This commit is contained in:
Seyaji
2022-06-20 13:46:11 +01:00
committed by GitHub
parent e4f4cc4a32
commit 606732dd5e
3 changed files with 10 additions and 96 deletions

View File

@@ -1,6 +1,8 @@
import { shallow } from 'enzyme';
import { screen, render } from '@testing-library/react';
import React from 'react';
import { selectors } from '@grafana/e2e-selectors';
import ButtonRow, { Props } from './ButtonRow';
jest.mock('app/core/core', () => {
@@ -23,22 +25,18 @@ const setup = (propOverrides?: object) => {
Object.assign(props, propOverrides);
return shallow(<ButtonRow {...props} />);
return render(<ButtonRow {...props} />);
};
describe('Render', () => {
describe('Button Row', () => {
it('should render component', () => {
const wrapper = setup();
setup();
expect(wrapper).toMatchSnapshot();
expect(screen.getByRole('button', { name: selectors.pages.DataSource.delete })).toBeInTheDocument();
});
it('should render save & test', () => {
setup({ canSave: true });
it('should render with buttons enabled', () => {
const wrapper = setup({
canSave: true,
canDelete: true,
});
expect(wrapper).toMatchSnapshot();
expect(screen.getByRole('button', { name: selectors.pages.DataSource.saveAndTest })).toBeInTheDocument();
});
});

View File

@@ -1,81 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Render should render component 1`] = `
<div
className="gf-form-button-row"
>
<Button
fill="solid"
onClick={[Function]}
type="button"
variant="secondary"
>
Back
</Button>
<LinkButton
disabled={false}
fill="solid"
href="/explore"
variant="secondary"
>
Explore
</LinkButton>
<Button
aria-label="Data source settings page Delete button"
disabled={true}
onClick={[MockFunction]}
type="button"
variant="destructive"
>
Delete
</Button>
<Button
onClick={[MockFunction]}
type="submit"
variant="primary"
>
Test
</Button>
</div>
`;
exports[`Render should render with buttons enabled 1`] = `
<div
className="gf-form-button-row"
>
<Button
fill="solid"
onClick={[Function]}
type="button"
variant="secondary"
>
Back
</Button>
<LinkButton
disabled={false}
fill="solid"
href="/explore"
variant="secondary"
>
Explore
</LinkButton>
<Button
aria-label="Data source settings page Delete button"
disabled={false}
onClick={[MockFunction]}
type="button"
variant="destructive"
>
Delete
</Button>
<Button
aria-label="Data source settings page Save and Test button"
disabled={false}
onClick={[Function]}
type="submit"
variant="primary"
>
Save & test
</Button>
</div>
`;