@@ -7,7 +7,7 @@ var createGraphDiv = require('../assets/create_graph_div');
7
7
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
8
8
9
9
10
- describe ( 'Test shapes nodes ' , function ( ) {
10
+ describe ( 'Test shapes: ' , function ( ) {
11
11
'use strict' ;
12
12
13
13
var mock = require ( '@mocks/shapes.json' ) ;
@@ -28,26 +28,74 @@ describe('Test shapes nodes', function() {
28
28
return d3 . selectAll ( '.shapelayer' ) . size ( ) ;
29
29
}
30
30
31
- function countPaths ( ) {
31
+ function countShapePaths ( ) {
32
32
return d3 . selectAll ( '.shapelayer > path' ) . size ( ) ;
33
33
}
34
34
35
- it ( 'has one *shapelayer* node' , function ( ) {
36
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
37
- } ) ;
35
+ describe ( 'DOM' , function ( ) {
36
+ it ( 'has one *shapelayer* node' , function ( ) {
37
+ expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
38
+ } ) ;
39
+
40
+ it ( 'has as many *path* nodes as there are shapes' , function ( ) {
41
+ expect ( countShapePaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
42
+ } ) ;
38
43
39
- it ( 'has as many *path* nodes as there are shapes' , function ( ) {
40
- expect ( countPaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
44
+ it ( 'should be able to get relayout' , function ( done ) {
45
+ expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
46
+ expect ( countShapePaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
47
+
48
+ Plotly . relayout ( gd , { height : 200 , width : 400 } ) . then ( function ( ) {
49
+ expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
50
+ expect ( countShapePaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
51
+ } ) . then ( done ) ;
52
+ } ) ;
41
53
} ) ;
42
54
43
- it ( 'should be able to get relayout' , function ( done ) {
44
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
45
- expect ( countPaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
55
+ function countShapes ( gd ) {
56
+ return gd . layout . shapes ?
57
+ gd . layout . shapes . length :
58
+ 0 ;
59
+ }
60
+
61
+ function getLastShape ( gd ) {
62
+ return gd . layout . shapes ?
63
+ gd . layout . shapes [ gd . layout . shapes . length - 1 ] :
64
+ null ;
65
+ }
46
66
47
- Plotly . relayout ( gd , { height : 200 , width : 400 } ) . then ( function ( ) {
48
- expect ( countShapeLayers ( ) ) . toEqual ( 1 ) ;
49
- expect ( countPaths ( ) ) . toEqual ( mock . layout . shapes . length ) ;
50
- done ( ) ;
67
+ function getRandomShape ( ) {
68
+ return {
69
+ x0 : Math . random ( ) ,
70
+ y0 : Math . random ( ) ,
71
+ x1 : Math . random ( ) ,
72
+ y1 : Math . random ( )
73
+ } ;
74
+ }
75
+
76
+ describe ( 'Plotly.relayout' , function ( ) {
77
+ it ( 'should be able to add a shape' , function ( done ) {
78
+ var index = countShapes ( gd ) ;
79
+ var shape = getRandomShape ( ) ;
80
+
81
+ Plotly . relayout ( gd , 'shapes[' + index + ']' , shape ) . then ( function ( ) {
82
+ expect ( getLastShape ( gd ) ) . toEqual ( shape ) ;
83
+ expect ( countShapes ( gd ) ) . toEqual ( index + 1 ) ;
84
+ } ) . then ( done ) ;
85
+ } ) ;
86
+
87
+ it ( 'should be able to remove a shape' , function ( done ) {
88
+ var index = countShapes ( gd ) ;
89
+ var shape = getRandomShape ( ) ;
90
+
91
+ Plotly . relayout ( gd , 'shapes[' + index + ']' , shape ) . then ( function ( ) {
92
+ expect ( getLastShape ( gd ) ) . toEqual ( shape ) ;
93
+ expect ( countShapes ( gd ) ) . toEqual ( index + 1 ) ;
94
+ } ) . then ( function ( ) {
95
+ Plotly . relayout ( gd , 'shapes[' + index + ']' , 'remove' ) ;
96
+ } ) . then ( function ( ) {
97
+ expect ( countShapes ( gd ) ) . toEqual ( index ) ;
98
+ } ) . then ( done ) ;
51
99
} ) ;
52
100
} ) ;
53
101
} ) ;
0 commit comments