@@ -25,6 +25,7 @@ describe('plot schema', function() {
25
25
var isPlainObject = Lib . isPlainObject ;
26
26
27
27
var VALTYPES = Object . keys ( valObjects ) ;
28
+ var ROLES = [ 'info' , 'style' , 'data' ] ;
28
29
var editType = plotSchema . defs . editType ;
29
30
30
31
function assertTraceSchema ( callback ) {
@@ -72,6 +73,26 @@ describe('plot schema', function() {
72
73
) ;
73
74
} ) ;
74
75
76
+ it ( 'all attributes should only have valid `role`' , function ( ) {
77
+ assertPlotSchema (
78
+ function ( attr ) {
79
+ if ( isValObject ( attr ) ) {
80
+ expect ( ROLES . indexOf ( attr . role ) !== - 1 ) . toBe ( true , attr ) ;
81
+ }
82
+ }
83
+ ) ;
84
+ } ) ;
85
+
86
+ it ( 'all nested objects should have the *object* `role`' , function ( ) {
87
+ assertPlotSchema (
88
+ function ( attr , attrName ) {
89
+ if ( ! isValObject ( attr ) && isPlainObject ( attr ) && attrName !== 'items' ) {
90
+ expect ( attr . role === 'object' ) . toBe ( true ) ;
91
+ }
92
+ }
93
+ ) ;
94
+ } ) ;
95
+
75
96
it ( 'all attributes should have the required options' , function ( ) {
76
97
assertPlotSchema (
77
98
function ( attr ) {
@@ -94,7 +115,7 @@ describe('plot schema', function() {
94
115
var opts = valObject . requiredOpts
95
116
. concat ( valObject . otherOpts )
96
117
. concat ( [
97
- 'valType' , 'description' ,
118
+ 'valType' , 'description' , 'role' ,
98
119
'editType' , 'impliedEdits' , 'anim' ,
99
120
'_compareAsJSON' , '_noTemplating'
100
121
] ) ;
@@ -164,8 +185,13 @@ describe('plot schema', function() {
164
185
165
186
// N.B. the specs below must be satisfied for plotly.py
166
187
expect ( isPlainObject ( itemsObj ) ) . toBe ( true ) ;
188
+ expect ( itemsObj . role ) . toBeUndefined ( ) ;
167
189
expect ( Object . keys ( itemsObj ) . length ) . toEqual ( 1 ) ;
168
190
expect ( isPlainObject ( itemObj ) ) . toBe ( true ) ;
191
+ expect ( itemObj . role ) . toBe ( 'object' ) ;
192
+
193
+ var role = np . get ( ) . role ;
194
+ expect ( role ) . toEqual ( 'object' ) ;
169
195
} ) ;
170
196
} ) ;
171
197
@@ -197,7 +223,7 @@ describe('plot schema', function() {
197
223
) ;
198
224
} ) ;
199
225
200
- it ( 'deprecated attributes should have a `valType`' , function ( ) {
226
+ it ( 'deprecated attributes should have a `valType` and `role` ' , function ( ) {
201
227
var DEPRECATED = '_deprecated' ;
202
228
203
229
assertPlotSchema (
@@ -208,6 +234,8 @@ describe('plot schema', function() {
208
234
209
235
expect ( VALTYPES . indexOf ( dAttr . valType ) !== - 1 )
210
236
. toBe ( true , attrString + ': ' + dAttrName ) ;
237
+ expect ( ROLES . indexOf ( dAttr . role ) !== - 1 )
238
+ . toBe ( true , attrString + ': ' + dAttrName ) ;
211
239
} ) ;
212
240
}
213
241
}
@@ -289,13 +317,15 @@ describe('plot schema', function() {
289
317
expect ( plotSchema . defs . metaKeys )
290
318
. toEqual ( [
291
319
'_isSubplotObj' , '_isLinkedToArray' , '_arrayAttrRegexps' ,
292
- '_deprecated' , 'description' , 'editType' , 'impliedEdits'
320
+ '_deprecated' , 'description' , 'role' , ' editType', 'impliedEdits'
293
321
] ) ;
294
322
} ) ;
295
323
296
324
it ( 'should list the correct frame attributes' , function ( ) {
297
325
expect ( plotSchema . frames ) . toBeDefined ( ) ;
326
+ expect ( plotSchema . frames . role ) . toEqual ( 'object' ) ;
298
327
expect ( plotSchema . frames . items . frames_entry ) . toBeDefined ( ) ;
328
+ expect ( plotSchema . frames . items . frames_entry . role ) . toEqual ( 'object' ) ;
299
329
} ) ;
300
330
301
331
it ( 'should list config attributes' , function ( ) {
@@ -439,7 +469,7 @@ describe('getTraceValObject', function() {
439
469
// it still returns the attribute itself - but maybe we should only do this
440
470
// for valType: any? (or data_array/arrayOk with just an index)
441
471
[
442
- 'valType' , 'dflt' , 'description' , 'arrayOk' ,
472
+ 'valType' , 'dflt' , 'role' , ' description', 'arrayOk' ,
443
473
'editType' , 'min' , 'max' , 'values'
444
474
] . forEach ( function ( prop ) {
445
475
expect ( getTraceValObject ( { } , [ 'x' , prop ] ) )
0 commit comments