Skip to content

Commit f653510

Browse files
committed
jest config
1 parent 629ca4f commit f653510

File tree

6 files changed

+354
-18
lines changed

6 files changed

+354
-18
lines changed

jest.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file is needed because it is used by vscode and other tools that
2+
// call `jest` directly. However, unless you are doing anything special
3+
// do not edit this file
4+
5+
const standard = require('@grafana/toolkit/src/config/jest.plugin.config');
6+
7+
// This process will use the same config that `yarn test` is using
8+
module.exports = standard.jestConfig();
9+
module.exports.setupFiles.push('./src/jest.setup.ts');

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
},
1818
"devDependencies": {
1919
"@grafana/data": "next",
20+
"@grafana/runtime": "next",
2021
"@grafana/toolkit": "next",
2122
"@grafana/ui": "next",
22-
"@grafana/runtime": "next",
23-
"emotion": "10.0.27"
23+
"emotion": "10.0.27",
24+
"enzyme": "^3.11.0",
25+
"enzyme-adapter-react-16": "1.15.2"
2426
}
2527
}

src/buttonPanel.test.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
DefaultTimeRange,
3+
DefaultTimeZone,
4+
LoadingState,
5+
PanelProps,
6+
} from '@grafana/data';
7+
import { mount } from 'enzyme';
8+
import React from 'react';
9+
import { Options } from 'types';
10+
import { ButtonPanel } from './buttonPanel';
11+
12+
describe('button panel', () => {
13+
test('panel', () => {
14+
let props: PanelProps<Options> = {
15+
id: 1,
16+
data: {
17+
timeRange: DefaultTimeRange,
18+
state: LoadingState.Done,
19+
series: [],
20+
},
21+
fieldConfig: { defaults: {}, overrides: [] },
22+
height: 1,
23+
transparent: false,
24+
width: 2,
25+
onChangeTimeRange: () => {},
26+
onFieldConfigChange: () => {},
27+
onOptionsChange: () => {},
28+
renderCounter: 1,
29+
replaceVariables: () => '',
30+
timeRange: DefaultTimeRange,
31+
timeZone: DefaultTimeZone,
32+
options: {
33+
buttons: [],
34+
orientation: 'horizontal',
35+
} as Options,
36+
};
37+
38+
mount(<ButtonPanel {...props} />);
39+
});
40+
});

src/jest.setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Enzyme from 'enzyme';
2+
import Adapter from 'enzyme-adapter-react-16';
3+
Enzyme.configure({ adapter: new Adapter() });

src/module.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
// Just a stub test
2-
describe('placeholder test', () => {
3-
it('should return true', () => {
4-
expect(true).toBeTruthy();
1+
import { standardEditorsRegistry } from '@grafana/data';
2+
import { plugin } from './module';
3+
4+
describe('button plugin', () => {
5+
test('editor options', () => {
6+
standardEditorsRegistry.setInit(() => {
7+
return [{ id: 'radio' }] as any;
8+
});
9+
expect(plugin.optionEditors).toBeDefined();
10+
expect(plugin.optionEditors?.list()).toHaveLength(2);
511
});
612
});

0 commit comments

Comments
 (0)