Skip to content

Commit dc2f3ba

Browse files
committed
Move assertions from hover_label_test.js to custom_assertions.js #2193
- Reason: prepare writing fixed size shape tests.
1 parent acc7d81 commit dc2f3ba

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

test/jasmine/assets/custom_assertions.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,29 @@ exports.checkTicks = function(axLetter, vals, msg) {
190190
expect(d3.select(this).text()).toBe(vals[i], msg + ': ' + i);
191191
});
192192
};
193+
194+
exports.assertElemRightTo = function(elem, refElem, msg) {
195+
var elemBB = elem.getBoundingClientRect();
196+
var refElemBB = refElem.getBoundingClientRect();
197+
expect(elemBB.left >= refElemBB.right).toBe(true, msg);
198+
};
199+
200+
201+
exports.assertElemTopsAligned = function(elem1, elem2, msg) {
202+
var elem1BB = elem1.getBoundingClientRect();
203+
var elem2BB = elem2.getBoundingClientRect();
204+
205+
// Hint: toBeWithin tolerance is exclusive, hence a
206+
// diff of exactly 1 would fail the test
207+
var tolerance = 1.1;
208+
expect(elem1BB.top - elem2BB.top).toBeWithin(0, tolerance, msg);
209+
};
210+
211+
exports.assertElemInside = function(elem, container, msg) {
212+
var elemBB = elem.getBoundingClientRect();
213+
var contBB = container.getBoundingClientRect();
214+
expect(contBB.left < elemBB.left &&
215+
contBB.right > elemBB.right &&
216+
contBB.top < elemBB.top &&
217+
contBB.bottom > elemBB.bottom).toBe(true, msg);
218+
};

test/jasmine/tests/hover_label_test.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ var fail = require('../assets/fail_test');
1717
var customAssertions = require('../assets/custom_assertions');
1818
var assertHoverLabelStyle = customAssertions.assertHoverLabelStyle;
1919
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
20+
var assertElemRightTo = customAssertions.assertElemRightTo;
21+
var assertElemTopsAligned = customAssertions.assertElemTopsAligned;
22+
var assertElemInside = customAssertions.assertElemInside;
2023

2124
describe('hover info', function() {
2225
'use strict';
@@ -1136,15 +1139,6 @@ describe('hover info', function() {
11361139
msgPrefixFmt + 'Primary text inside box');
11371140
assertElemInside(nodes.secondaryText, nodes.secondaryBox,
11381141
msgPrefixFmt + 'Secondary text inside box');
1139-
1140-
function assertElemInside(elem, container, msg) {
1141-
var elemBB = elem.getBoundingClientRect();
1142-
var contBB = container.getBoundingClientRect();
1143-
expect(contBB.left < elemBB.left &&
1144-
contBB.right > elemBB.right &&
1145-
contBB.top < elemBB.top &&
1146-
contBB.bottom > elemBB.bottom).toBe(true, msg);
1147-
}
11481142
}
11491143

11501144
function assertSecondaryRightToPrimaryBox(nodes, msgPrefix) {
@@ -1154,22 +1148,6 @@ describe('hover info', function() {
11541148
msgPrefixFmt + 'Secondary box right to primary box');
11551149
assertElemTopsAligned(nodes.secondaryBox, nodes.primaryBox,
11561150
msgPrefixFmt + 'Top edges of primary and secondary boxes aligned');
1157-
1158-
function assertElemRightTo(elem, refElem, msg) {
1159-
var elemBB = elem.getBoundingClientRect();
1160-
var refElemBB = refElem.getBoundingClientRect();
1161-
expect(elemBB.left >= refElemBB.right).toBe(true, msg);
1162-
}
1163-
1164-
function assertElemTopsAligned(elem1, elem2, msg) {
1165-
var elem1BB = elem1.getBoundingClientRect();
1166-
var elem2BB = elem2.getBoundingClientRect();
1167-
1168-
// Hint: toBeWithin tolerance is exclusive, hence a
1169-
// diff of exactly 1 would fail the test
1170-
var tolerance = 1.1;
1171-
expect(elem1BB.top - elem2BB.top).toBeWithin(0, tolerance, msg);
1172-
}
11731151
}
11741152

11751153
describe('centered', function() {

0 commit comments

Comments
 (0)