Skip to content

Commit 8601385

Browse files
committed
clean up click test:
- move copy-mock step and add-custom-matchers to suite scope - rewrite one test as promise chain - define auto range values in suite scope
1 parent 6586d1c commit 8601385

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

test/jasmine/tests/click_test.js

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@ var customMatchers = require('../assets/custom_matchers');
99

1010

1111
describe('Test click interactions:', function() {
12-
var mock = require('@mocks/14.json'),
13-
gd;
12+
var mock = require('@mocks/14.json');
13+
14+
var mockCopy, gd;
1415

1516
var pointPos = [351, 223],
1617
blankPos = [70, 363];
1718

19+
var autoRangeX = [-3.011967491973726, 2.1561305597186564],
20+
autoRangeY = [-0.9910086301469277, 1.389382716298284];
21+
22+
beforeAll(function() {
23+
jasmine.addMatchers(customMatchers);
24+
});
25+
26+
beforeEach(function() {
27+
gd = createGraphDiv();
28+
mockCopy = Lib.extendDeep({}, mock);
29+
});
30+
1831
afterEach(destroyGraphDiv);
1932

2033
// cartesian click events events use the hover data
@@ -54,11 +67,7 @@ describe('Test click interactions:', function() {
5467
var futureData;
5568

5669
beforeEach(function(done) {
57-
gd = createGraphDiv();
58-
59-
var mockCopy = Lib.extendDeep({}, mock);
60-
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
61-
.then(done);
70+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
6271

6372
gd.on('plotly_click', function(data) {
6473
futureData = data;
@@ -90,11 +99,7 @@ describe('Test click interactions:', function() {
9099
var futureData;
91100

92101
beforeEach(function(done) {
93-
gd = createGraphDiv();
94-
95-
var mockCopy = Lib.extendDeep({}, mock);
96-
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
97-
.then(done);
102+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
98103

99104
gd.on('plotly_doubleclick', function(data) {
100105
futureData = data;
@@ -111,11 +116,6 @@ describe('Test click interactions:', function() {
111116
});
112117

113118
describe('double click interactions', function() {
114-
var mockCopy;
115-
116-
var autoRangeX = [-3.011967491973726, 2.1561305597186564],
117-
autoRangeY = [-0.9910086301469277, 1.389382716298284];
118-
119119
var setRangeX = [-3, 1],
120120
setRangeY = [-0.5, 1];
121121

@@ -129,15 +129,6 @@ describe('Test click interactions:', function() {
129129
'yaxis.range[1]': zoomRangeY[1]
130130
};
131131

132-
beforeAll(function() {
133-
jasmine.addMatchers(customMatchers);
134-
});
135-
136-
beforeEach(function() {
137-
gd = createGraphDiv();
138-
mockCopy = Lib.extendDeep({}, mock);
139-
});
140-
141132
function setRanges(mockCopy) {
142133
mockCopy.layout.xaxis.autorange = false;
143134
mockCopy.layout.xaxis.range = setRangeX.slice();
@@ -153,17 +144,17 @@ describe('Test click interactions:', function() {
153144
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
154145
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
155146

156-
Plotly.relayout(gd, update).then(function() {
157-
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
158-
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
147+
return Plotly.relayout(gd, update);
148+
}).then(function() {
149+
expect(gd.layout.xaxis.range).toBeCloseToArray(zoomRangeX);
150+
expect(gd.layout.yaxis.range).toBeCloseToArray(zoomRangeY);
159151

160-
return doubleClick(blankPos[0], blankPos[1]);
161-
}).then(function() {
162-
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
163-
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
152+
return doubleClick(blankPos[0], blankPos[1]);
153+
}).then(function() {
154+
expect(gd.layout.xaxis.range).toBeCloseToArray(autoRangeX);
155+
expect(gd.layout.yaxis.range).toBeCloseToArray(autoRangeY);
164156

165-
done();
166-
});
157+
done();
167158
});
168159
});
169160

0 commit comments

Comments
 (0)