-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathconnectLayoutToPlot-test.js
73 lines (66 loc) · 2.39 KB
/
connectLayoutToPlot-test.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
import NumericInput from '../../components/widgets/NumericInput';
import React from 'react';
import connectLayoutToPlot from '../connectLayoutToPlot';
import {PlotlyFold, PlotlyPanel, PlotlySection} from '../../components/containers';
import {Numeric} from '../../components/fields';
import {TestEditor, fixtures, plotly} from '../test-utils';
import {mount} from 'enzyme';
const Layouts = [PlotlyPanel, PlotlyFold, PlotlySection].map(connectLayoutToPlot);
const Editor = props => <TestEditor {...{plotly, onUpdate: jest.fn(), ...props}} />;
Layouts.forEach(Layout => {
describe(`<${Layout.displayName}>`, () => {
it(`wraps container with fullValue pointing to gd._fullLayout`, () => {
const wrapper = mount(
<Editor {...fixtures.scatter({layout: {height: 100}})}>
<PlotlyPanel>
<Layout>
<Numeric label="Height" step={10} attr="height" />
</Layout>
</PlotlyPanel>
</Editor>
)
.find('[attr="height"]')
.find(NumericInput);
expect(wrapper.prop('value')).toBe(100);
});
it(`sends updates to gd._layout`, () => {
const beforeUpdateLayout = jest.fn();
const wrapper = mount(
<Editor
beforeUpdateLayout={beforeUpdateLayout}
{...fixtures.scatter({layout: {height: 100}})}
>
<PlotlyPanel>
<Layout>
<Numeric label="Height" step={10} attr="height" />
</Layout>
</PlotlyPanel>
</Editor>
)
.find('[attr="height"]')
.find(NumericInput);
const heightUpdate = 200;
wrapper.prop('onChange')(heightUpdate);
const payload = beforeUpdateLayout.mock.calls[0][0];
expect(payload).toEqual({update: {height: heightUpdate}});
});
it(`automatically computes min and max defaults`, () => {
const onUpdate = jest.fn();
const wrapper = mount(
<Editor onUpdate={onUpdate} {...fixtures.scatter({layout: {showlegend: true}})}>
<PlotlyPanel>
<Layout>
<Numeric label="Position x" step={0.01} attr="legend.x" />
</Layout>
</PlotlyPanel>
</Editor>
)
.find('[attr="legend.x"]')
.find(NumericInput);
const expectedMin = -2;
const expectedMax = 3;
expect(wrapper.prop('min')).toBe(expectedMin);
expect(wrapper.prop('max')).toBe(expectedMax);
});
});
});