Skip to content

Commit dfcd6c3

Browse files
committed
add ternary test suite:
- add one visibility toogle test - add one delete / add trace test
1 parent 8338be6 commit dfcd6c3

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

test/jasmine/tests/ternary_test.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
var Plotly = require('@lib');
2+
var Lib = require('@src/lib');
3+
var d3 = require('d3');
4+
var createGraphDiv = require('../assets/create_graph_div');
5+
var destroyGraphDiv = require('../assets/destroy_graph_div');
6+
7+
8+
describe('ternary plots', function() {
9+
'use strict';
10+
11+
afterEach(destroyGraphDiv);
12+
13+
describe('with scatterternary trace(s)', function() {
14+
var mock = require('@mocks/ternary_simple.json');
15+
var gd;
16+
17+
beforeEach(function(done) {
18+
gd = createGraphDiv();
19+
20+
var mockCopy = Lib.extendDeep({}, mock);
21+
22+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
23+
});
24+
25+
it('should be able to toggle trace visibility', function(done) {
26+
expect(countTraces('scatter')).toEqual(1);
27+
28+
Plotly.restyle(gd, 'visible', false).then(function() {
29+
expect(countTraces('scatter')).toEqual(0);
30+
31+
return Plotly.restyle(gd, 'visible', true);
32+
}).then(function() {
33+
expect(countTraces('scatter')).toEqual(1);
34+
35+
return Plotly.restyle(gd, 'visible', 'legendonly');
36+
}).then(function() {
37+
expect(countTraces('scatter')).toEqual(0);
38+
39+
return Plotly.restyle(gd, 'visible', true);
40+
}).then(function() {
41+
expect(countTraces('scatter')).toEqual(1);
42+
43+
done();
44+
});
45+
});
46+
47+
it('should be able to delete and add traces', function(done) {
48+
expect(countTernarySubplot()).toEqual(1);
49+
expect(countTraces('scatter')).toEqual(1);
50+
51+
Plotly.deleteTraces(gd, [0]).then(function() {
52+
expect(countTernarySubplot()).toEqual(0);
53+
expect(countTraces('scatter')).toEqual(0);
54+
55+
var trace = Lib.extendDeep({}, mock.data[0]);
56+
57+
return Plotly.addTraces(gd, [trace]);
58+
}).then(function() {
59+
expect(countTernarySubplot()).toEqual(1);
60+
expect(countTraces('scatter')).toEqual(1);
61+
62+
var trace = Lib.extendDeep({}, mock.data[0]);
63+
64+
return Plotly.addTraces(gd, [trace]);
65+
}).then(function() {
66+
expect(countTernarySubplot()).toEqual(1);
67+
expect(countTraces('scatter')).toEqual(2);
68+
69+
return Plotly.deleteTraces(gd, [0]);
70+
}).then(function() {
71+
expect(countTernarySubplot()).toEqual(1);
72+
expect(countTraces('scatter')).toEqual(1);
73+
74+
done();
75+
});
76+
77+
});
78+
79+
});
80+
81+
function countTernarySubplot() {
82+
return d3.selectAll('.ternary').size();
83+
}
84+
85+
function countTraces(type) {
86+
return d3.selectAll('.ternary').selectAll('g.trace.' + type).size();
87+
}
88+
});

0 commit comments

Comments
 (0)