@@ -4,10 +4,15 @@ var Drawing = require('@src/components/drawing');
4
4
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
5
5
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
6
6
var fail = require ( '../assets/fail_test' ) ;
7
+ var customMatchers = require ( '../assets/custom_matchers' ) ;
7
8
8
9
describe ( 'Drawing' , function ( ) {
9
10
'use strict' ;
10
11
12
+ beforeAll ( function ( ) {
13
+ jasmine . addMatchers ( customMatchers ) ;
14
+ } ) ;
15
+
11
16
describe ( 'setClipUrl' , function ( ) {
12
17
13
18
beforeEach ( function ( ) {
@@ -349,6 +354,17 @@ describe('Drawing', function() {
349
354
describe ( 'bBox' , function ( ) {
350
355
afterEach ( destroyGraphDiv ) ;
351
356
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
+
352
368
it ( 'should update bounding box dimension on window scroll' , function ( done ) {
353
369
var gd = createGraphDiv ( ) ;
354
370
@@ -366,7 +382,7 @@ describe('Drawing', function() {
366
382
} )
367
383
. then ( function ( ) {
368
384
var node = d3 . select ( 'text.annotation' ) . node ( ) ;
369
- expect ( Drawing . bBox ( node ) ) . toEqual ( {
385
+ assertBBox ( Drawing . bBox ( node ) , {
370
386
height : 14 ,
371
387
width : 27.671875 ,
372
388
left : - 13.671875 ,
@@ -380,14 +396,28 @@ describe('Drawing', function() {
380
396
} )
381
397
. then ( function ( ) {
382
398
var node = d3 . select ( 'text.annotation' ) . node ( ) ;
383
- expect ( Drawing . bBox ( node ) ) . toEqual ( {
399
+ assertBBox ( Drawing . bBox ( node ) , {
384
400
height : 14 ,
385
401
width : 41.015625 ,
386
402
left : - 20.671875 ,
387
403
top : - 11 ,
388
404
right : 20.34375 ,
389
405
bottom : 3
390
406
} ) ;
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
+ } ) ;
391
421
} )
392
422
. catch ( fail )
393
423
. then ( done ) ;
0 commit comments