-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathHighchartsMapChart.spec.js
82 lines (66 loc) · 2.21 KB
/
HighchartsMapChart.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import * as React from 'react';
import { render } from '@testing-library/react';
jest.mock('react-jsx-highcharts', () => ({
...jest.requireActual('react-jsx-highcharts'),
useHighcharts: jest.fn()
}));
import { useHighcharts } from 'react-jsx-highcharts';
import { Highcharts, createMockChart } from '../../test-utils';
import HighchartsMapChart from '../../../src/components/HighchartsMapChart/HighchartsMapChart';
describe('<HighchartsMapChart />', () => {
let chart;
beforeEach(() => {
chart = createMockChart();
Highcharts.mapChart.mockReturnValue(chart);
useHighcharts.mockImplementation(() => Highcharts);
});
afterEach(() => {
Highcharts.mapChart.mockRestore();
});
it('creates a chart', () => {
render(<HighchartsMapChart />);
expect(Highcharts.mapChart).toHaveBeenCalled();
});
it('creates a chart with the correct chart type', () => {
render(<HighchartsMapChart />);
expect(Highcharts.mapChart).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
chartType: 'mapChart'
})
);
});
it('creates a chart with GeoJSON from a string', () => {
render(<HighchartsMapChart map="mock/map" />);
expect(Highcharts.mapChart).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
chart: expect.objectContaining({ map: { some: 'data' } })
})
);
});
it('creates a chart with direct GeoJSON', () => {
render(<HighchartsMapChart map={{ direct: 'input' }} />);
expect(Highcharts.mapChart).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
chart: expect.objectContaining({ map: { direct: 'input' } })
})
);
});
it('passes other props through to chart', () => {
render(<HighchartsMapChart plotOptions={{ c: 'd' }} />);
expect(Highcharts.mapChart).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({ plotOptions: { c: 'd' } })
);
});
it('return a chart instance to the callback prop', () => {
let cbChart;
const chartCallback = returnedChart => {
cbChart = returnedChart;
};
render(<HighchartsMapChart callback={chartCallback} />);
expect(cbChart).toBeDefined();
});
});