Skip to content

Commit 927af3b

Browse files
committed
fixup legend test:
- make sure to extend the mock before each test case - fix typo (addTrace -> addTraces)
1 parent 3e6b949 commit 927af3b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

test/jasmine/tests/legend_scroll_test.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var Plotly = require('@lib/index');
2+
var Lib = require('@src/lib');
3+
24
var createGraph = require('../assets/create_graph_div');
35
var destroyGraph = require('../assets/destroy_graph_div');
46
var getBBox = require('../assets/get_bbox');
@@ -26,10 +28,15 @@ describe('The legend', function() {
2628

2729

2830
describe('when plotted with many traces', function() {
29-
beforeEach(function() {
31+
beforeEach(function(done) {
3032
gd = createGraph();
31-
Plotly.plot(gd, mock.data, mock.layout);
32-
legend = document.getElementsByClassName('legend')[0];
33+
34+
var mockCopy = Lib.extendDeep({}, mock);
35+
36+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
37+
legend = document.getElementsByClassName('legend')[0];
38+
done();
39+
});
3340
});
3441

3542
afterEach(destroyGraph);
@@ -96,7 +103,7 @@ describe('The legend', function() {
96103
it('should resize when relayout\'ed with new height', function(done) {
97104
var origLegendHeight = getBBox(legend).height;
98105

99-
Plotly.relayout(gd, {'height': gd._fullLayout.height/2}).then(function() {
106+
Plotly.relayout(gd, 'height', gd._fullLayout.height / 2).then(function() {
100107
var legendHeight = getBBox(legend).height;
101108

102109
//legend still exists and not duplicated
@@ -114,7 +121,7 @@ describe('The legend', function() {
114121

115122

116123
describe('when plotted with few traces', function() {
117-
var gd, legend;
124+
var gd;
118125

119126
beforeEach(function() {
120127
gd = createGraph();
@@ -147,14 +154,15 @@ describe('The legend', function() {
147154
});
148155

149156
it('should resize when traces added', function(done) {
150-
legend = document.getElementsByClassName('legend')[0];
151-
var origLegendHeight = getBBox(legend).height;
157+
var origLegend = document.getElementsByClassName('legend')[0];
158+
var origLegendHeight = getBBox(origLegend).height;
152159

153-
Plotly.addTrace(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() {
160+
Plotly.addTraces(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() {
154161
var legend = document.getElementsByClassName('legend')[0];
155162
var legendHeight = getBBox(legend).height;
163+
156164
// clippath resized to show new trace
157-
expect(+legendHeight).toBeCloseTo(+origLegendHeight+18, 0);
165+
expect(+legendHeight).toBeCloseTo(+origLegendHeight + 19, 0);
158166

159167
done();
160168
});

0 commit comments

Comments
 (0)