Chore: convert DashboardGrid test to RTL (#53405)

This commit is contained in:
eledobleefe 2022-08-08 17:43:35 +02:00 committed by GitHub
parent 1772bd4238
commit 9930fd522d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 71 deletions

View File

@ -74,9 +74,6 @@ exports[`no enzyme tests`] = {
"public/app/features/dashboard/components/ShareModal/ShareLink.test.tsx:3716733755": [
[0, 35, 13, "RegExp match", "2409514259"]
],
"public/app/features/dashboard/dashgrid/DashboardGrid.test.tsx:2723773538": [
[0, 35, 13, "RegExp match", "2409514259"]
],
"public/app/features/dimensions/editors/ThresholdsEditor/ThresholdsEditor.test.tsx:4164297658": [
[0, 17, 13, "RegExp match", "2409514259"]
],
@ -4281,8 +4278,7 @@ exports[`better eslint`] = {
],
"public/app/features/dashboard/dashgrid/DashboardGrid.test.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"public/app/features/dashboard/dashgrid/DashboardGrid.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],

View File

@ -1,4 +1,4 @@
import { shallow, ShallowWrapper } from 'enzyme';
import { render } from '@testing-library/react';
import React from 'react';
import { DashboardModel } from '../state';
@ -12,13 +12,6 @@ jest.mock('app/features/dashboard/dashgrid/LazyLoader', () => {
return { LazyLoader };
});
interface ScenarioContext {
props: Props;
wrapper?: ShallowWrapper<Props, any, DashboardGrid>;
setup: (fn: () => void) => void;
setProps: (props: Partial<Props>) => void;
}
function getTestDashboard(overrides?: any, metaOverrides?: any): DashboardModel {
const data = Object.assign(
{
@ -57,43 +50,14 @@ function getTestDashboard(overrides?: any, metaOverrides?: any): DashboardModel
return new DashboardModel(data, meta);
}
function dashboardGridScenario(description: string, scenarioFn: (ctx: ScenarioContext) => void) {
describe(description, () => {
let setupFn: () => void;
const ctx: ScenarioContext = {
setup: (fn) => {
setupFn = fn;
},
props: {
editPanel: null,
viewPanel: null,
dashboard: getTestDashboard(),
cleanAndRemoveMany: jest.fn,
},
setProps: (props: Partial<Props>) => {
Object.assign(ctx.props, props);
if (ctx.wrapper) {
ctx.wrapper.setProps(ctx.props);
}
},
};
beforeEach(() => {
setupFn();
ctx.wrapper = shallow(<DashboardGrid {...ctx.props} />);
});
scenarioFn(ctx);
});
}
describe('DashboardGrid', () => {
dashboardGridScenario('Can render dashboard grid', (ctx) => {
ctx.setup(() => {});
it('Should render', () => {
expect(ctx.wrapper).toMatchSnapshot();
});
it('should render without error', () => {
const props: Props = {
editPanel: null,
viewPanel: null,
dashboard: getTestDashboard(),
cleanAndRemoveMany: jest.fn,
};
expect(() => render(<DashboardGrid {...props} />)).not.toThrow();
});
});

View File

@ -1,21 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`DashboardGrid Can render dashboard grid Should render 1`] = `
<div
style={
Object {
"display": undefined,
"flex": "1 1 auto",
}
}
>
<AutoSizer
disableHeight={true}
disableWidth={false}
onResize={[Function]}
style={Object {}}
>
<Component />
</AutoSizer>
</div>
`;