Skip to content

Commit e3a2c84

Browse files
committed
DRY up select_test.js
1 parent ec6e360 commit e3a2c84

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

test/jasmine/tests/select_test.js

+16-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('select box and lasso', function() {
1616
var selectPath = [[93, 193], [143, 193]];
1717
var lassoPath = [[316, 171], [318, 239], [335, 243], [328, 169]];
1818

19-
beforeEach(function() {
19+
beforeAll(function() {
2020
jasmine.addMatchers(customMatchers);
2121
});
2222

@@ -59,6 +59,13 @@ describe('select box and lasso', function() {
5959
});
6060
}
6161

62+
function assertSelectionNodes(cornerCnt, outlineCnt) {
63+
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
64+
.toBe(cornerCnt, 'selection corner count');
65+
expect(d3.selectAll('.zoomlayer > .select-outline').size())
66+
.toBe(outlineCnt, 'selection outline count');
67+
}
68+
6269
describe('select elements', function() {
6370
var mockCopy = Lib.extendDeep({}, mock);
6471
mockCopy.layout.dragmode = 'select';
@@ -80,30 +87,21 @@ describe('select box and lasso', function() {
8087
y2 = 50;
8188

8289
gd.once('plotly_selecting', function() {
83-
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
84-
.toEqual(1);
85-
expect(d3.selectAll('.zoomlayer > .select-outline').size())
86-
.toEqual(2);
90+
assertSelectionNodes(1, 2);
8791
});
8892

8993
gd.once('plotly_selected', function() {
90-
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
91-
.toEqual(0);
92-
expect(d3.selectAll('.zoomlayer > .select-outline').size())
93-
.toEqual(2);
94+
assertSelectionNodes(0, 2);
9495
});
9596

9697
gd.once('plotly_deselect', function() {
97-
expect(d3.selectAll('.zoomlayer > .select-outline').size())
98-
.toEqual(0);
98+
assertSelectionNodes(0, 0);
9999
});
100100

101101
mouseEvent('mousemove', x0, y0);
102-
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
103-
.toEqual(0);
102+
assertSelectionNodes(0, 0);
104103

105104
drag([[x0, y0], [x1, y1]]);
106-
107105
doubleClick(x2, y2).then(done);
108106
});
109107
});
@@ -129,30 +127,21 @@ describe('select box and lasso', function() {
129127
y2 = 50;
130128

131129
gd.once('plotly_selecting', function() {
132-
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
133-
.toEqual(1);
134-
expect(d3.selectAll('.zoomlayer > .select-outline').size())
135-
.toEqual(2);
130+
assertSelectionNodes(1, 2);
136131
});
137132

138133
gd.once('plotly_selected', function() {
139-
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
140-
.toEqual(0);
141-
expect(d3.selectAll('.zoomlayer > .select-outline').size())
142-
.toEqual(2);
134+
assertSelectionNodes(0, 2);
143135
});
144136

145137
gd.once('plotly_deselect', function() {
146-
expect(d3.selectAll('.zoomlayer > .select-outline').size())
147-
.toEqual(0);
138+
assertSelectionNodes(0, 0);
148139
});
149140

150141
mouseEvent('mousemove', x0, y0);
151-
expect(d3.selectAll('.zoomlayer > .zoombox-corners').size())
152-
.toEqual(0);
142+
assertSelectionNodes(0, 0);
153143

154144
drag([[x0, y0], [x1, y1]]);
155-
156145
doubleClick(x2, y2).then(done);
157146
});
158147
});

0 commit comments

Comments
 (0)