Skip to content

Commit 857878b

Browse files
committed
add legend and clip path count test,
- to ensure that they are properly removed when 'showlegend' is relayout'ed to false.
1 parent 335bb40 commit 857878b

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

test/jasmine/tests/legend_scroll_test.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ describe('The legend', function() {
1010

1111
var gd, legend;
1212

13+
function countLegendGroups(gd) {
14+
return gd._fullLayout._toppaper.selectAll('g.legend').size();
15+
}
16+
17+
function countLegendClipPaths(gd) {
18+
var uid = gd._fullLayout._uid;
19+
20+
return gd._fullLayout._topdefs.selectAll('#legend' + uid).size();
21+
}
22+
1323
describe('when plotted with many traces', function() {
1424
beforeEach(function() {
1525
gd = createGraph();
@@ -66,22 +76,51 @@ describe('The legend', function() {
6676
legend.dispatchEvent(scrollTo(10000));
6777
expect(+scrollBar.getAttribute('y')).toBe(legendHeight - 4 - 20);
6878
});
79+
80+
it('should be removed from DOM when \'showlegend\' is relayout\'ed to false', function(done) {
81+
expect(countLegendGroups(gd)).toBe(1);
82+
expect(countLegendClipPaths(gd)).toBe(1);
83+
84+
Plotly.relayout(gd, 'showlegend', false).then(function() {
85+
expect(countLegendGroups(gd)).toBe(0);
86+
expect(countLegendClipPaths(gd)).toBe(0);
87+
88+
done();
89+
});
90+
});
6991
});
7092

7193
describe('when plotted with few traces', function() {
7294
var gd;
7395

7496
beforeEach(function() {
7597
gd = createGraph();
76-
Plotly.plot(gd, [{ x: [1,2,3], y: [2,3,4], name: 'Test' }], {});
98+
99+
var data = [{ x: [1,2,3], y: [2,3,4], name: 'Test' }];
100+
var layout = { showlegend: true };
101+
102+
Plotly.plot(gd, data, layout);
77103
});
78104

79105
afterEach(destroyGraph);
80106

81107
it('should not display the scrollbar', function() {
82108
var scrollBar = document.getElementsByClassName('scrollbar')[0];
83109

84-
expect(scrollBar).toBeUndefined();
110+
expect(+scrollBar.getAttribute('width')).toBe(0);
111+
expect(+scrollBar.getAttribute('height')).toBe(0);
112+
});
113+
114+
it('should be removed from DOM when \'showlegend\' is relayout\'ed to false', function(done) {
115+
expect(countLegendGroups(gd)).toBe(1);
116+
expect(countLegendClipPaths(gd)).toBe(1);
117+
118+
Plotly.relayout(gd, 'showlegend', false).then(function() {
119+
expect(countLegendGroups(gd)).toBe(0);
120+
expect(countLegendClipPaths(gd)).toBe(0);
121+
122+
done();
123+
});
85124
});
86125
});
87126
});

0 commit comments

Comments
 (0)