Skip to content

Commit f1e8aee

Browse files
authored
Merge pull request #1596 from plotly/carpet-test-etienne
A few more carpet plot tests
2 parents e4971ef + 71b96f3 commit f1e8aee

File tree

1 file changed

+99
-17
lines changed

1 file changed

+99
-17
lines changed

test/jasmine/tests/carpet_test.js

+99-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
// var Plotly = require('@lib/index');
1+
var Plotly = require('@lib/index');
22
var Plots = require('@src/plots/plots');
3-
// var Lib = require('@src/lib');
3+
var Lib = require('@src/lib');
44

55
var Carpet = require('@src/traces/carpet');
66
var smoothFill2D = require('@src/traces/carpet/smooth_fill_2d_array');
77
var smoothFill = require('@src/traces/carpet/smooth_fill_array');
8-
// var calc = require('@src/traces/carpet/calc');
98

9+
var d3 = require('d3');
1010
var customMatchers = require('../assets/custom_matchers');
11-
12-
// var d3 = require('d3');
13-
// var createGraphDiv = require('../assets/create_graph_div');
14-
// var destroyGraphDiv = require('../assets/destroy_graph_div');
15-
// var customMatchers = require('../assets/custom_matchers');
16-
17-
var test = {
18-
supplyDefaults: false,
19-
smoothFill2D: true
20-
};
11+
var createGraphDiv = require('../assets/create_graph_div');
12+
var destroyGraphDiv = require('../assets/destroy_graph_div');
13+
var fail = require('../assets/fail_test');
2114

2215
describe('carpet supplyDefaults', function() {
23-
if(!test.supplyDefaults) return;
2416
'use strict';
2517

2618
var traceIn,
@@ -55,7 +47,6 @@ describe('carpet supplyDefaults', function() {
5547
expect(traceOut.db).toBeUndefined();
5648
expect(traceOut.a0).toBeUndefined();
5749
expect(traceOut.b0).toBeUndefined();
58-
expect(traceOut.visible).toBe(true);
5950
});
6051

6152
it('sets a0/da when a not provided', function() {
@@ -222,7 +213,6 @@ describe('supplyDefaults visibility check', function() {
222213
});
223214

224215
describe('carpet smooth_fill_2d_array', function() {
225-
if(!test.smoothFill2D) return;
226216
var _;
227217

228218
beforeAll(function() { jasmine.addMatchers(customMatchers); });
@@ -389,7 +379,6 @@ describe('carpet smooth_fill_2d_array', function() {
389379
});
390380

391381
describe('smooth_fill_array', function() {
392-
if(!test.smoothFill2D) return;
393382
var _;
394383

395384
beforeAll(function() { jasmine.addMatchers(customMatchers); });
@@ -430,3 +419,96 @@ describe('smooth_fill_array', function() {
430419
.toBeCloseToArray([0, 1, 2, 3]);
431420
});
432421
});
422+
423+
describe('Test carpet interactions:', function() {
424+
var gd;
425+
426+
beforeEach(function() {
427+
gd = createGraphDiv();
428+
});
429+
430+
afterEach(destroyGraphDiv);
431+
432+
function countCarpets() {
433+
return d3.select(gd).selectAll('.carpetlayer').selectAll('.trace').size();
434+
}
435+
436+
function countContourTraces() {
437+
return d3.select(gd).selectAll('.contour').size();
438+
}
439+
440+
it('should restyle visible attribute properly', function(done) {
441+
var mock = Lib.extendDeep({}, require('@mocks/cheater.json'));
442+
443+
Plotly.plot(gd, mock)
444+
.then(function() {
445+
expect(countCarpets()).toEqual(1);
446+
expect(countContourTraces()).toEqual(3);
447+
448+
return Plotly.restyle(gd, 'visible', false, [2, 3]);
449+
})
450+
.then(function() {
451+
expect(countCarpets()).toEqual(1);
452+
expect(countContourTraces()).toEqual(1);
453+
454+
return Plotly.restyle(gd, 'visible', true);
455+
})
456+
.then(function() {
457+
expect(countCarpets()).toEqual(1);
458+
expect(countContourTraces()).toEqual(3);
459+
460+
return Plotly.restyle(gd, 'visible', false);
461+
})
462+
.then(function() {
463+
expect(countCarpets()).toEqual(0);
464+
expect(countContourTraces()).toEqual(0);
465+
})
466+
.catch(fail)
467+
.then(done);
468+
});
469+
470+
it('should add/delete trace properly', function(done) {
471+
var mock = Lib.extendDeep({}, require('@mocks/cheater.json'));
472+
var trace1 = Lib.extendDeep({}, mock.data[1]);
473+
474+
Plotly.plot(gd, mock)
475+
.then(function() {
476+
expect(countCarpets()).toEqual(1);
477+
expect(countContourTraces()).toEqual(3);
478+
479+
return Plotly.deleteTraces(gd, [1]);
480+
})
481+
.then(function() {
482+
expect(countCarpets()).toEqual(1);
483+
expect(countContourTraces()).toEqual(2);
484+
485+
return Plotly.addTraces(gd, trace1);
486+
})
487+
.then(function() {
488+
expect(countCarpets()).toEqual(1);
489+
expect(countContourTraces()).toEqual(3);
490+
491+
return Plotly.deleteTraces(gd, [0, 1, 2, 3]);
492+
})
493+
.then(function() {
494+
expect(countCarpets()).toEqual(0);
495+
expect(countContourTraces()).toEqual(0);
496+
})
497+
.catch(fail)
498+
.then(done);
499+
});
500+
501+
it('should respond to relayout properly', function(done) {
502+
var mock = Lib.extendDeep({}, require('@mocks/cheater.json'));
503+
504+
Plotly.plot(gd, mock)
505+
.then(function() {
506+
return Plotly.relayout(gd, 'xaxis.range', [0, 1]);
507+
})
508+
.then(function() {
509+
return Plotly.relayout(gd, 'yaxis.range', [7, 8]);
510+
})
511+
.catch(fail)
512+
.then(done);
513+
});
514+
});

0 commit comments

Comments
 (0)