|
| 1 | +var Plotly = require('@lib/index'); |
1 | 2 | var Plots = require('@src/plots/plots');
|
| 3 | +var Lib = require('@src/lib'); |
2 | 4 |
|
3 | 5 | var Carpet = require('@src/traces/carpet');
|
4 | 6 | var smoothFill2D = require('@src/traces/carpet/smooth_fill_2d_array');
|
5 | 7 | var smoothFill = require('@src/traces/carpet/smooth_fill_array');
|
6 | 8 |
|
| 9 | +var d3 = require('d3'); |
7 | 10 | var customMatchers = require('../assets/custom_matchers');
|
8 |
| - |
| 11 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 12 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 13 | +var fail = require('../assets/fail_test'); |
9 | 14 |
|
10 | 15 | describe('carpet supplyDefaults', function() {
|
11 | 16 | 'use strict';
|
@@ -414,3 +419,96 @@ describe('smooth_fill_array', function() {
|
414 | 419 | .toBeCloseToArray([0, 1, 2, 3]);
|
415 | 420 | });
|
416 | 421 | });
|
| 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