Skip to content

Commit 33f4495

Browse files
committed
Add/adjust tests
1 parent fba744b commit 33f4495

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/components/fields/__tests__/DataSelector-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('DataSelector', () => {
3838
const onUpdateTraces = jest.fn();
3939
const wrapper = render({onUpdateTraces}).find(DropdownWidget);
4040
wrapper.prop('onChange')('y1');
41-
expect(onUpdateTraces.mock.calls[0][0]).toEqual({
41+
expect(onUpdateTraces.mock.calls[2][0]).toEqual({
4242
update: {xsrc: 'y1', x: [2, 3, 4]},
4343
traceIndexes: [0],
4444
});

src/components/fields/__tests__/TraceSelector-test.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,67 @@ import {connectTraceToPlot} from 'lib';
99
describe('TraceSelector', () => {
1010
const TraceSection = connectTraceToPlot(Section);
1111

12+
it('sets mode to markers if trace scatter, no data or mode provided', () => {
13+
const editorProps = {
14+
...fixtures.scatter({data: [{mode: null, xsrc: null, ysrc: null}]}),
15+
onUpdate: jest.fn(),
16+
};
17+
const wrapper = mount(
18+
<TestEditor {...editorProps} plotly={plotly}>
19+
<TraceSection traceIndex={0}>
20+
<TraceSelector attr="type" />
21+
</TraceSection>
22+
</TestEditor>
23+
).find(TraceSelector);
24+
25+
const innerDropdown = wrapper.find(Dropdown);
26+
27+
expect(wrapper.props().plotProps.container.mode).toBe('markers');
28+
expect(innerDropdown.prop('value')).toEqual('scatter');
29+
});
30+
31+
it('if no data provided, but mode is provided, displays correct trace type', () => {
32+
const editorProps = {
33+
...fixtures.scatter({
34+
data: [{mode: 'lines+markers', xsrc: null, ysrc: null}],
35+
}),
36+
onUpdate: jest.fn(),
37+
};
38+
const wrapper = mount(
39+
<TestEditor {...editorProps} plotly={plotly}>
40+
<TraceSection traceIndex={0}>
41+
<TraceSelector attr="type" />
42+
</TraceSection>
43+
</TestEditor>
44+
).find(TraceSelector);
45+
46+
const innerDropdown = wrapper.find(Dropdown);
47+
48+
expect(innerDropdown.prop('value')).toEqual('line');
49+
});
50+
51+
it('if data provided, but no mode is provided, chooses mode according to fullData', () => {
52+
const editorProps = {
53+
...fixtures.scatter(),
54+
onUpdate: jest.fn(),
55+
};
56+
57+
expect(!editorProps.graphDiv.data[0].mode).toBe(true);
58+
expect(editorProps.graphDiv._fullData[0].mode).toBe('lines+markers');
59+
60+
const wrapper = mount(
61+
<TestEditor {...editorProps} plotly={plotly}>
62+
<TraceSection traceIndex={0}>
63+
<TraceSelector attr="type" />
64+
</TraceSection>
65+
</TestEditor>
66+
).find(TraceSelector);
67+
68+
const innerDropdown = wrapper.find(Dropdown);
69+
expect(wrapper.props().plotProps.container.mode).toBe('lines+markers');
70+
expect(innerDropdown.prop('value')).toEqual('line');
71+
});
72+
1273
it('interprets scatter + fill as type=area', () => {
1374
const editorProps = {
1475
...fixtures.scatter({data: [{fill: 'tonexty'}]}),

0 commit comments

Comments
 (0)