convert TestRuleResult to RTL (#53953)

This commit is contained in:
Ashley Harrison 2022-08-19 15:00:53 +01:00 committed by GitHub
parent 4ca845e479
commit b6835ef87d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 38 deletions

View File

@ -68,9 +68,6 @@ exports[`no enzyme tests`] = {
"public/app/features/alerting/AlertRuleList.test.tsx:2998938420": [
[0, 19, 13, "RegExp match", "2409514259"]
],
"public/app/features/alerting/TestRuleResult.test.tsx:2358420489": [
[0, 19, 13, "RegExp match", "2409514259"]
],
"public/app/features/dashboard/components/ShareModal/ShareLink.test.tsx:3716733755": [
[0, 35, 13, "RegExp match", "2409514259"]
],

View File

@ -1,4 +1,4 @@
import { shallow } from 'enzyme';
import { render } from '@testing-library/react';
import React from 'react';
import { DashboardModel, PanelModel } from '../dashboard/state';
@ -16,35 +16,20 @@ jest.mock('@grafana/runtime', () => {
};
});
const setup = (propOverrides?: object) => {
const props: Props = {
panel: new PanelModel({ id: 1 }),
dashboard: new DashboardModel({ panels: [{ id: 1 }] }),
};
Object.assign(props, propOverrides);
const wrapper = shallow(<TestRuleResult {...props} />);
return { wrapper, instance: wrapper.instance() as TestRuleResult };
const props: Props = {
panel: new PanelModel({ id: 1 }),
dashboard: new DashboardModel({ panels: [{ id: 1 }] }),
};
describe('Render', () => {
it('should render component', () => {
const { wrapper } = setup();
describe('TestRuleResult', () => {
it('should render without error', () => {
expect(() => render(<TestRuleResult {...props} />)).not.toThrow();
});
expect(wrapper).toMatchSnapshot();
});
});
describe('Life cycle', () => {
describe('component did mount', () => {
it('should call testRule', () => {
const { instance } = setup();
instance.testRule = jest.fn();
instance.componentDidMount();
expect(instance.testRule).toHaveBeenCalled();
});
it('should call testRule when mounting', () => {
jest.spyOn(TestRuleResult.prototype, 'testRule');
render(<TestRuleResult {...props} />);
expect(TestRuleResult.prototype.testRule).toHaveBeenCalled();
});
});

View File

@ -1,7 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Render should render component 1`] = `
<LoadingPlaceholder
text="Evaluating rule"
/>
`;