@@ -1162,6 +1162,58 @@ describe('Test axes', function() {
1162
1162
expect ( layoutOut . xaxis2 . rangebreaks [ 2 ] . bounds [ 1 ] ) . toBe ( 6 , 'convert sat' ) ;
1163
1163
expect ( layoutOut . xaxis2 . rangebreaks [ 3 ] . bounds [ 1 ] ) . toBe ( '-1' , 'string' ) ;
1164
1164
} ) ;
1165
+
1166
+ it ( 'should validate inputs in respect to *day of week* pattern' , function ( ) {
1167
+ layoutIn = {
1168
+ xaxis : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ '6.999' , '0' ] } ] } ,
1169
+ xaxis2 : { type : 'date' , rangebreaks : [ { bounds : [ 'Sunday' ] } ] } ,
1170
+ xaxis3 : { type : 'date' , rangebreaks : [ { bounds : [ 'sun' , 'mon' , 'tue' ] } ] } ,
1171
+ xaxis4 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '-1' ] } ] } ,
1172
+ xaxis5 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '-.001' ] } ] } ,
1173
+ xaxis6 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '7' ] } ] } ,
1174
+ xaxis7 : { type : 'date' , rangebreaks : [ { pattern : 'day of week' , bounds : [ 1 , '6.999' ] } ] }
1175
+ } ;
1176
+ layoutOut . _subplots . xaxis . push ( 'x2' , 'x3' , 'x4' , 'x5' , 'x6' , 'x7' ) ;
1177
+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
1178
+
1179
+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'valid' ) ;
1180
+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . bounds [ 0 ] ) . toBe ( 6 , 'cast float to int' ) ;
1181
+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . bounds [ 1 ] ) . toBe ( 0 , 'cast string to int' ) ;
1182
+ expect ( layoutOut . xaxis2 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bounds.length < 2' ) ;
1183
+ expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'do not reject bounds.length > 2' ) ;
1184
+ expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . bounds . length ) . toBe ( 2 , 'pick first two' ) ;
1185
+ expect ( layoutOut . xaxis4 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 0' ) ;
1186
+ expect ( layoutOut . xaxis5 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 0' ) ;
1187
+ expect ( layoutOut . xaxis6 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound >= 7' ) ;
1188
+ expect ( layoutOut . xaxis7 . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'do not reject bound < 7' ) ;
1189
+ } ) ;
1190
+
1191
+ it ( 'should validate inputs in respect to *hour* pattern' , function ( ) {
1192
+ layoutIn = {
1193
+ xaxis : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ '23.999' , '0' ] } ] } ,
1194
+ xaxis2 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 ] } ] } ,
1195
+ xaxis3 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , 2 , 3 ] } ] } ,
1196
+ xaxis4 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '-1' ] } ] } ,
1197
+ xaxis5 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '-.001' ] } ] } ,
1198
+ xaxis6 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '24.001' ] } ] } ,
1199
+ xaxis7 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '23.999' ] } ] } ,
1200
+ xaxis8 : { type : 'date' , rangebreaks : [ { pattern : 'hour' , bounds : [ 1 , '24' ] } ] }
1201
+ } ;
1202
+ layoutOut . _subplots . xaxis . push ( 'x2' , 'x3' , 'x4' , 'x5' , 'x6' , 'x7' , 'x8' ) ;
1203
+ supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
1204
+
1205
+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'valid' ) ;
1206
+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . bounds [ 0 ] ) . toBe ( '23.999' , 'do not cast float to int' ) ;
1207
+ expect ( layoutOut . xaxis . rangebreaks [ 0 ] . bounds [ 1 ] ) . toBe ( '0' , 'do not cast string to int' ) ;
1208
+ expect ( layoutOut . xaxis2 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bounds.length < 2' ) ;
1209
+ expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'do not reject bounds.length > 2' ) ;
1210
+ expect ( layoutOut . xaxis3 . rangebreaks [ 0 ] . bounds . length ) . toBe ( 2 , 'pick first two' ) ;
1211
+ expect ( layoutOut . xaxis4 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 0' ) ;
1212
+ expect ( layoutOut . xaxis5 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound < 0' ) ;
1213
+ expect ( layoutOut . xaxis6 . rangebreaks [ 0 ] . enabled ) . toBe ( false , 'reject bound > 24' ) ;
1214
+ expect ( layoutOut . xaxis7 . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'do not reject bound <= 24' ) ;
1215
+ expect ( layoutOut . xaxis8 . rangebreaks [ 0 ] . enabled ) . toBe ( true , 'do not reject 24' ) ;
1216
+ } ) ;
1165
1217
} ) ;
1166
1218
1167
1219
describe ( 'constraints relayout' , function ( ) {
0 commit comments