Skip to content

Commit fd5cab7

Browse files
committed
add geo and cartesian delete traces tests
1 parent 1d4f7e6 commit fd5cab7

File tree

2 files changed

+154
-38
lines changed

2 files changed

+154
-38
lines changed

test/jasmine/tests/geo_interact_test.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ describe('Test geo interactions', function() {
2424
mouseEvent(type, 400, 160);
2525
}
2626

27+
function countTraces(type) {
28+
return d3.selectAll('g.trace.' + type).size();
29+
}
30+
31+
function countGeos() {
32+
return d3.select('div.geo-container').selectAll('div').size();
33+
}
34+
35+
function countColorBars() {
36+
return d3.select('g.infolayer').selectAll('.cbbg').size();
37+
}
38+
2739
beforeEach(function(done) {
2840
gd = createGraphDiv();
2941
Plotly.plot(gd, mock.data, mock.layout).then(done);
@@ -181,10 +193,6 @@ describe('Test geo interactions', function() {
181193
});
182194

183195
describe('trace visibility toggle', function() {
184-
function countTraces(type) {
185-
return d3.selectAll('g.trace.' + type).size();
186-
}
187-
188196
it('should toggle scattergeo elements', function(done) {
189197
expect(countTraces('scattergeo')).toBe(1);
190198
expect(countTraces('choropleth')).toBe(1);
@@ -218,5 +226,37 @@ describe('Test geo interactions', function() {
218226
});
219227

220228
});
229+
230+
describe('deleting traces and geos', function() {
231+
it('should delete traces in succession', function(done) {
232+
expect(countTraces('scattergeo')).toBe(1);
233+
expect(countTraces('choropleth')).toBe(1);
234+
expect(countGeos()).toBe(1);
235+
expect(countColorBars()).toBe(1);
236+
237+
Plotly.deleteTraces(gd, [0]).then(function() {
238+
expect(countTraces('scattergeo')).toBe(0);
239+
expect(countTraces('choropleth')).toBe(1);
240+
expect(countGeos()).toBe(1);
241+
expect(countColorBars()).toBe(1);
242+
243+
Plotly.deleteTraces(gd, [0]).then(function() {
244+
expect(countTraces('scattergeo')).toBe(0);
245+
expect(countTraces('choropleth')).toBe(0);
246+
expect(countGeos()).toBe(1);
247+
expect(countColorBars()).toBe(0);
248+
249+
Plotly.relayout(gd, 'geo', null).then(function() {
250+
expect(countTraces('scattergeo')).toBe(0);
251+
expect(countTraces('choropleth')).toBe(0);
252+
expect(countGeos()).toBe(0);
253+
expect(countColorBars()).toBe(0);
254+
done();
255+
});
256+
});
257+
});
258+
});
259+
});
260+
221261
});
222262
});

test/jasmine/tests/plot_interact_test.js

Lines changed: 110 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,30 @@ describe('Test plot structure', function() {
2020
afterEach(destroyGraphDiv);
2121

2222
describe('cartesian plots', function() {
23+
24+
function countSubplots() {
25+
return d3.selectAll('g.subplot').size();
26+
}
27+
28+
function countScatterTraces() {
29+
return d3.selectAll('g.trace.scatter').size();
30+
}
31+
32+
function countColorBars() {
33+
return d3.selectAll('rect.cbbg').size();
34+
}
35+
2336
describe('scatter traces', function() {
2437
var mock = require('@mocks/14.json');
38+
var gd;
2539

2640
beforeEach(function(done) {
27-
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
41+
gd = createGraphDiv();
42+
Plotly.plot(gd, mock.data, mock.layout).then(done);
2843
});
2944

3045
it('has one *subplot xy* node', function() {
31-
var nodes = d3.selectAll('g.subplot.xy');
32-
expect(nodes.size()).toEqual(1);
46+
expect(countSubplots()).toEqual(1);
3347
});
3448

3549
it('has one *scatterlayer* node', function() {
@@ -38,8 +52,7 @@ describe('Test plot structure', function() {
3852
});
3953

4054
it('has as many *trace scatter* nodes as there are traces', function() {
41-
var nodes = d3.selectAll('g.trace.scatter');
42-
expect(nodes.size()).toEqual(mock.data.length);
55+
expect(countScatterTraces()).toEqual(mock.data.length);
4356
});
4457

4558
it('has as many *point* nodes as there are traces', function() {
@@ -61,50 +74,73 @@ describe('Test plot structure', function() {
6174
assertNamespaces(node);
6275
});
6376
});
77+
78+
it('should delete be able to get deleted', function(done) {
79+
expect(countScatterTraces()).toEqual(mock.data.length);
80+
expect(countSubplots()).toEqual(1);
81+
82+
Plotly.deleteTraces(gd, [0]).then(function() {
83+
expect(countScatterTraces()).toEqual(0);
84+
expect(countSubplots()).toEqual(1);
85+
done();
86+
});
87+
});
6488
});
6589

6690
describe('contour/heatmap traces', function() {
6791
var mock = require('@mocks/connectgaps_2d.json');
92+
var gd;
6893

6994
function extendMock() {
70-
var mockCopy = Lib.extendDeep(mock);
95+
var mockData = Lib.extendDeep([], mock.data),
96+
mockLayout = Lib.extendDeep({}, mock.layout);
7197

7298
// add a colorbar for testing
73-
mockCopy.data[0].showscale = true;
99+
mockData[0].showscale = true;
100+
101+
return {
102+
data: mockData,
103+
layout: mockLayout
104+
};
105+
}
106+
107+
function assertHeatmapNodes(expectedCnt) {
108+
var hmNodes = d3.selectAll('g.hm');
109+
expect(hmNodes.size()).toEqual(expectedCnt);
110+
111+
var imageNodes = d3.selectAll('image');
112+
expect(imageNodes.size()).toEqual(expectedCnt);
113+
}
74114

75-
return mockCopy;
115+
function assertContourNodes(expectedCnt) {
116+
var nodes = d3.selectAll('g.contour');
117+
expect(nodes.size()).toEqual(expectedCnt);
76118
}
77119

78120
describe('initial structure', function() {
79121
beforeEach(function(done) {
80122
var mockCopy = extendMock();
123+
var gd = createGraphDiv();
81124

82-
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout)
125+
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
83126
.then(done);
84127
});
85128

86129
it('has four *subplot* nodes', function() {
87-
var nodes = d3.selectAll('g.subplot');
88-
expect(nodes.size()).toEqual(4);
130+
expect(countSubplots()).toEqual(4);
89131
});
90132

91-
// N.B. the contour traces both have a heatmap fill
92133
it('has four heatmap image nodes', function() {
93-
var hmNodes = d3.selectAll('g.hm');
94-
expect(hmNodes.size()).toEqual(4);
95-
96-
var imageNodes = d3.selectAll('image');
97-
expect(imageNodes.size()).toEqual(4);
134+
// N.B. the contour traces both have a heatmap fill
135+
assertHeatmapNodes(4);
98136
});
99137

100138
it('has two contour nodes', function() {
101-
var nodes = d3.selectAll('g.contour');
102-
expect(nodes.size()).toEqual(2);
139+
assertContourNodes(2);
103140
});
104141

105142
it('has one colorbar nodes', function() {
106-
var nodes = d3.selectAll('rect.cbbg');
107-
expect(nodes.size()).toEqual(1);
143+
expect(countColorBars()).toEqual(1);
108144
});
109145
});
110146

@@ -129,33 +165,73 @@ describe('Test plot structure', function() {
129165
});
130166

131167
it('has four *subplot* nodes', function() {
132-
var nodes = d3.selectAll('g.subplot');
133-
expect(nodes.size()).toEqual(4);
168+
expect(countSubplots()).toEqual(4);
134169
});
135170

136171
it('has two heatmap image nodes', function() {
137-
var hmNodes = d3.selectAll('g.hm');
138-
expect(hmNodes.size()).toEqual(2);
139-
140-
var imageNodes = d3.selectAll('image');
141-
expect(imageNodes.size()).toEqual(2);
172+
assertHeatmapNodes(2);
142173
});
143174

144175
it('has two contour nodes', function() {
145-
var nodes = d3.selectAll('g.contour');
146-
expect(nodes.size()).toEqual(2);
176+
assertContourNodes(2);
147177
});
148178

149179
it('has one scatter node', function() {
150-
var nodes = d3.selectAll('g.trace.scatter');
151-
expect(nodes.size()).toEqual(1);
180+
expect(countScatterTraces()).toEqual(1);
152181
});
153182

154183
it('has no colorbar node', function() {
155-
var nodes = d3.selectAll('rect.cbbg');
156-
expect(nodes.size()).toEqual(0);
184+
expect(countColorBars()).toEqual(0);
185+
});
186+
});
187+
188+
describe('structure after deleteTraces', function() {
189+
beforeEach(function(done) {
190+
gd = createGraphDiv();
191+
192+
var mockCopy = extendMock();
193+
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
194+
.then(done);
157195
});
196+
197+
it('should be removed of traces in sequence', function(done) {
198+
expect(countSubplots()).toEqual(4);
199+
assertHeatmapNodes(4);
200+
assertContourNodes(2);
201+
expect(countColorBars()).toEqual(1);
202+
203+
Plotly.deleteTraces(gd, [0]).then(function() {
204+
expect(countSubplots()).toEqual(4);
205+
assertHeatmapNodes(3);
206+
assertContourNodes(2);
207+
expect(countColorBars()).toEqual(0);
208+
209+
Plotly.deleteTraces(gd, [0]).then(function() {
210+
expect(countSubplots()).toEqual(4);
211+
assertHeatmapNodes(2);
212+
assertContourNodes(2);
213+
expect(countColorBars()).toEqual(0);
214+
215+
Plotly.deleteTraces(gd, [0]).then(function() {
216+
expect(countSubplots()).toEqual(4);
217+
assertHeatmapNodes(1);
218+
assertContourNodes(1);
219+
expect(countColorBars()).toEqual(0);
220+
221+
Plotly.deleteTraces(gd, [0]).then(function() {
222+
expect(countSubplots()).toEqual(4);
223+
assertHeatmapNodes(0);
224+
assertContourNodes(0);
225+
expect(countColorBars()).toEqual(0);
226+
done();
227+
});
228+
});
229+
});
230+
});
231+
});
232+
158233
});
234+
159235
});
160236

161237
describe('pie traces', function() {

0 commit comments

Comments
 (0)