Skip to content

Commit 34475d5

Browse files
committed
test: add legend restyle test cases
1 parent 503d52f commit 34475d5

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/jasmine/tests/legend_test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var anchorUtils = require('@src/components/legend/anchor_utils');
1010
var d3 = require('d3');
1111
var createGraphDiv = require('../assets/create_graph_div');
1212
var destroyGraphDiv = require('../assets/destroy_graph_div');
13+
var customMatchers = require('../assets/custom_matchers');
1314

1415

1516
describe('legend defaults', function() {
@@ -563,3 +564,59 @@ describe('legend orientation change:', function() {
563564
});
564565
});
565566
});
567+
568+
describe('legend restyle update', function() {
569+
'use strict';
570+
571+
beforeAll(function() {
572+
jasmine.addMatchers(customMatchers);
573+
});
574+
575+
afterEach(destroyGraphDiv);
576+
577+
it('should update trace toggle background rectangle', function(done) {
578+
var mock = require('@mocks/0.json'),
579+
mockCopy = Lib.extendDeep({}, mock),
580+
gd = createGraphDiv();
581+
582+
mockCopy.data[0].visible = false;
583+
mockCopy.data[0].showlegend = false;
584+
mockCopy.data[1].visible = false;
585+
mockCopy.data[1].showlegend = false;
586+
587+
function countLegendItems() {
588+
return d3.select(gd).selectAll('rect.legendtoggle').size();
589+
}
590+
591+
function assertTraceToggleRect() {
592+
var nodes = d3.selectAll('rect.legendtoggle');
593+
594+
nodes.each(function() {
595+
var node = d3.select(this);
596+
597+
expect(node.attr('x')).toEqual('0');
598+
expect(node.attr('y')).toEqual('-9.5');
599+
expect(node.attr('height')).toEqual('19');
600+
601+
var w = +node.attr('width');
602+
expect(Math.abs(w - 160)).toBeLessThan(10);
603+
});
604+
}
605+
606+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
607+
expect(countLegendItems()).toEqual(1);
608+
assertTraceToggleRect();
609+
610+
return Plotly.restyle(gd, 'visible', [true, false, false]);
611+
}).then(function() {
612+
expect(countLegendItems()).toEqual(0);
613+
614+
return Plotly.restyle(gd, 'showlegend', [true, false, false]);
615+
}).then(function() {
616+
expect(countLegendItems()).toEqual(1);
617+
assertTraceToggleRect();
618+
619+
done();
620+
});
621+
});
622+
});

0 commit comments

Comments
 (0)