@@ -28,7 +28,6 @@ var supplyDefaults = require('../assets/supply_defaults');
28
28
29
29
describe ( 'Test axes' , function ( ) {
30
30
'use strict' ;
31
-
32
31
describe ( 'swap' , function ( ) {
33
32
it ( 'should swap most attributes and fix placeholder titles' , function ( ) {
34
33
var gd = {
@@ -8217,3 +8216,65 @@ describe('shift tests', function() {
8217
8216
} ) ;
8218
8217
} ) ;
8219
8218
} ) ;
8219
+ describe ( 'test tickmode calculator' , function ( ) {
8220
+ beforeEach ( function ( ) {
8221
+ gd = createGraphDiv ( ) ;
8222
+ } ) ;
8223
+
8224
+ afterEach ( destroyGraphDiv ) ;
8225
+
8226
+ function generateTickConfig ( ) {
8227
+ standardConfig = { tickmode : 'array' , ticks : 'inside' , ticklen : 1 , showticklabels : false } ;
8228
+
8229
+ // Number of ticks will be random
8230
+ var n = Math . floor ( Math . random ( ) * 99 ) + 1 ;
8231
+ tickVals = [ ] ;
8232
+ for ( let i = 0 ; i <= n ; i ++ ) tickVals . push ( i ) ;
8233
+ standardConfig [ 'tickvals' ] = tickVals ;
8234
+ standardConfig [ 'ticktext' ] = tickVals ;
8235
+ return standardConfig ;
8236
+ }
8237
+ var ticksOff = { tickmode :"array" , ticks : '' , tickvals :[ ] , ticktext :[ ] , ticklen : 0 , showticklabels : false } ;
8238
+ // the goal is target the arrayTicks() function, the subject of PR: https://github.com/plotly/plotly.js/pull/6829
8239
+ // we test xMajor and xMinor in on/on on/off off/on and off/off
8240
+ // since we can't unit test functions that are not exported, we shim functions we don't care about instead and
8241
+ // test the nearest exported functions (calcTicks)
8242
+ describe ( 'arrayTicks' , function ( ) {
8243
+ for ( let i = 0 ; i < 4 ; i ++ ) {
8244
+ ( function ( i ) {
8245
+ it ( 'should return the specified correct number of major ticks and minor ticks' , function ( ) {
8246
+ const BOTH = 0 ;
8247
+ const MAJOR = 1 ;
8248
+ const MINOR = 2 ;
8249
+ const NEITHER = 3 ;
8250
+ var xMajorConfig = ticksOff ;
8251
+ var xMinorConfig = ticksOff ;
8252
+ if ( i == BOTH ) {
8253
+ xMajorConfig = generateTickConfig ( ) ;
8254
+ xMinorConfig = generateTickConfig ( ) ;
8255
+ } else if ( i == MAJOR ) {
8256
+ xMajorConfig = generateTickConfig ( ) ;
8257
+ } else if ( i == MINOR ) {
8258
+ xMinorConfig = generateTickConfig ( ) ;
8259
+ } else if ( i == NEITHER ) {
8260
+ // Do nothing, all ticks off
8261
+ }
8262
+ xaxis = {
8263
+ r2l : Lib . cleanNumber ,
8264
+ d2l : Lib . cleanNumber ,
8265
+ _separators : ',' ,
8266
+ range : [ 0 , 1000 ] ,
8267
+ ...xMajorConfig ,
8268
+ minor : {
8269
+ ...xMinorConfig ,
8270
+ } ,
8271
+ } ;
8272
+ Axes . prepMinorTicks = function ( ) { return } ; // Not part of this test
8273
+ Axes . prepTicks = function ( ) { return } ; // Not part of this test
8274
+ ticksOut = Axes . calcTicks ( xaxis ) ;
8275
+ expect ( ticksOut . length ) . toEqual ( xMajorConfig . tickvals . length + xMinorConfig . tickvals . length ) ;
8276
+ } ) ;
8277
+ } ) ( i ) ;
8278
+ }
8279
+ } ) ;
8280
+ } ) ;
0 commit comments