mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: convert DashboardGrid test to RTL (#53405)
This commit is contained in:
parent
1772bd4238
commit
9930fd522d
@ -74,9 +74,6 @@ exports[`no enzyme tests`] = {
|
|||||||
"public/app/features/dashboard/components/ShareModal/ShareLink.test.tsx:3716733755": [
|
"public/app/features/dashboard/components/ShareModal/ShareLink.test.tsx:3716733755": [
|
||||||
[0, 35, 13, "RegExp match", "2409514259"]
|
[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": [
|
"public/app/features/dimensions/editors/ThresholdsEditor/ThresholdsEditor.test.tsx:4164297658": [
|
||||||
[0, 17, 13, "RegExp match", "2409514259"]
|
[0, 17, 13, "RegExp match", "2409514259"]
|
||||||
],
|
],
|
||||||
@ -4281,8 +4278,7 @@ exports[`better eslint`] = {
|
|||||||
],
|
],
|
||||||
"public/app/features/dashboard/dashgrid/DashboardGrid.test.tsx:5381": [
|
"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.", "0"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
|
|
||||||
],
|
],
|
||||||
"public/app/features/dashboard/dashgrid/DashboardGrid.tsx:5381": [
|
"public/app/features/dashboard/dashgrid/DashboardGrid.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { shallow, ShallowWrapper } from 'enzyme';
|
import { render } from '@testing-library/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { DashboardModel } from '../state';
|
import { DashboardModel } from '../state';
|
||||||
@ -12,13 +12,6 @@ jest.mock('app/features/dashboard/dashgrid/LazyLoader', () => {
|
|||||||
return { 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 {
|
function getTestDashboard(overrides?: any, metaOverrides?: any): DashboardModel {
|
||||||
const data = Object.assign(
|
const data = Object.assign(
|
||||||
{
|
{
|
||||||
@ -57,43 +50,14 @@ function getTestDashboard(overrides?: any, metaOverrides?: any): DashboardModel
|
|||||||
return new DashboardModel(data, meta);
|
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', () => {
|
describe('DashboardGrid', () => {
|
||||||
dashboardGridScenario('Can render dashboard grid', (ctx) => {
|
it('should render without error', () => {
|
||||||
ctx.setup(() => {});
|
const props: Props = {
|
||||||
|
editPanel: null,
|
||||||
it('Should render', () => {
|
viewPanel: null,
|
||||||
expect(ctx.wrapper).toMatchSnapshot();
|
dashboard: getTestDashboard(),
|
||||||
});
|
cleanAndRemoveMany: jest.fn,
|
||||||
|
};
|
||||||
|
expect(() => render(<DashboardGrid {...props} />)).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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>
|
|
||||||
`;
|
|
Loading…
Reference in New Issue
Block a user