Skip to content

Commit 3fdb308

Browse files
committed
make bbox test more robust
1 parent 9af534a commit 3fdb308

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

test/jasmine/tests/drawing_test.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ var Drawing = require('@src/components/drawing');
44
var createGraphDiv = require('../assets/create_graph_div');
55
var destroyGraphDiv = require('../assets/destroy_graph_div');
66
var fail = require('../assets/fail_test');
7+
var customMatchers = require('../assets/custom_matchers');
78

89
describe('Drawing', function() {
910
'use strict';
1011

12+
beforeAll(function() {
13+
jasmine.addMatchers(customMatchers);
14+
});
15+
1116
describe('setClipUrl', function() {
1217

1318
beforeEach(function() {
@@ -349,6 +354,17 @@ describe('Drawing', function() {
349354
describe('bBox', function() {
350355
afterEach(destroyGraphDiv);
351356

357+
function assertBBox(actual, expected) {
358+
expect(actual.height).toEqual(expected.height, 'height');
359+
expect(actual.top).toEqual(expected.top, 'top');
360+
expect(actual.bottom).toEqual(expected.bottom, 'bottom');
361+
362+
var TOL = 3;
363+
expect(actual.width).toBeWithin(expected.width, TOL, 'width');
364+
expect(actual.left).toBeWithin(expected.left, TOL, 'left');
365+
expect(actual.right).toBeWithin(expected.right, TOL, 'right');
366+
}
367+
352368
it('should update bounding box dimension on window scroll', function(done) {
353369
var gd = createGraphDiv();
354370

@@ -366,7 +382,7 @@ describe('Drawing', function() {
366382
})
367383
.then(function() {
368384
var node = d3.select('text.annotation').node();
369-
expect(Drawing.bBox(node)).toEqual({
385+
assertBBox(Drawing.bBox(node), {
370386
height: 14,
371387
width: 27.671875,
372388
left: -13.671875,
@@ -380,14 +396,28 @@ describe('Drawing', function() {
380396
})
381397
.then(function() {
382398
var node = d3.select('text.annotation').node();
383-
expect(Drawing.bBox(node)).toEqual({
399+
assertBBox(Drawing.bBox(node), {
384400
height: 14,
385401
width: 41.015625,
386402
left: -20.671875,
387403
top: -11,
388404
right: 20.34375,
389405
bottom: 3
390406
});
407+
408+
window.scroll(200, 0);
409+
return Plotly.relayout(gd, 'annotations[0].font.size', 20);
410+
})
411+
.then(function() {
412+
var node = d3.select('text.annotation').node();
413+
assertBBox(Drawing.bBox(node), {
414+
height: 22,
415+
width: 66.015625,
416+
left: -32.78125,
417+
top: -18,
418+
right: 33.234375,
419+
bottom: 4
420+
});
391421
})
392422
.catch(fail)
393423
.then(done);

0 commit comments

Comments
 (0)