This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 281
/
chart-editor.test.jsx
86 lines (65 loc) · 2.82 KB
/
chart-editor.test.jsx
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
83
84
85
86
import React from 'react';
import {configure, mount} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
// workaround `TypeError: window.URL.createObjectURL is not a function`
window.URL.createObjectURL = function() {};
// workaround `Error: Not implemented: HTMLCanvasElement.prototype.getContext`
HTMLCanvasElement.prototype.getContext = function () {return null;};
jest.unmock('../../../../../app/components/Settings/Preview/chart-editor.jsx');
const ChartEditor = require('../../../../../app/components/Settings/Preview/chart-editor.jsx');
describe('ChartEditor', () => {
let chartEditor, columnNames, rows, plotlyJSON, onUpdate, hidden;
beforeAll(() => {
configure({adapter: new Adapter()});
columnNames = ['x', 'y'];
rows = [];
for (let i = 0; i < 1 + ChartEditor.MAX_ROWS; i++) {
rows.push([i, 10 * i]);
}
plotlyJSON = {};
onUpdate = (nextPlotlyJSON) => {plotlyJSON = nextPlotlyJSON;};
hidden = true;
chartEditor = mount(
<ChartEditor
columnNames={columnNames}
rows={rows}
plotlyJSON={plotlyJSON}
onUpdate={onUpdate}
hidden={hidden}
/>
);
});
it('honors props', () => {
expect(chartEditor.prop('columnNames')).toBe(columnNames);
expect(chartEditor.prop('rows')).toBe(rows);
expect(chartEditor.prop('plotlyJSON')).toBe(plotlyJSON);
expect(chartEditor.prop('onUpdate')).toBe(onUpdate);
expect(chartEditor.prop('hidden')).toBe(hidden);
const {dataSources, dataSourceOptions} = chartEditor.state();
expect(dataSourceOptions.length).toBe(columnNames.length);
columnNames.forEach((name, i) => {
const dataSourceOption = dataSourceOptions[i];
expect(dataSourceOption).toEqual({value: name, label: name});
// check length has been capped
const dataSource = dataSources[name];
expect(dataSource.length).toEqual(ChartEditor.MAX_ROWS);
});
// check a few data
expect(dataSources.x[0]).toBe(0);
expect(dataSources.x[1]).toBe(1);
expect(dataSources.x[ChartEditor.MAX_ROWS - 1]).toBe(ChartEditor.MAX_ROWS - 1);
expect(dataSources.y[0]).toBe(0);
expect(dataSources.y[1]).toBe(10);
expect(dataSources.y[ChartEditor.MAX_ROWS - 1]).toBe(10 * (ChartEditor.MAX_ROWS - 1));
});
// requires node-canvas
xit('honors props.hidden', () => {
function getPlotlyEditor() {
return chartEditor.find('.plotly-editor');
}
expect(chartEditor.prop('hidden')).toBe(true);
expect(getPlotlyEditor().length).toBe(0);
chartEditor.setProps({hidden: false});
expect(getPlotlyEditor().length).toBe(1);
});
});