Skip to content

Commit d16fe6b

Browse files
committed
plotly#189 additional tests for categorymode coercions
1 parent e472e14 commit d16fe6b

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

Diff for: test/jasmine/tests/axes_test.js

+64-4
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,15 @@ describe('Test axes', function() {
356356

357357
});
358358

359-
describe('setting, or not setting categorymode to "array"', function() {
359+
describe('setting categorymode to "array"', function() {
360360

361361
it('should leave categorymode on "array" if it is supplied', function() {
362362
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
363-
xaxis: {type: 'category', categorymode: "array", categorylist: ['b','a','d','e','c']}
363+
xaxis: {type: 'category', categorymode: 'array', categorylist: ['b','a','d','e','c']}
364364
});
365365
expect(gd._fullLayout.xaxis.categorymode).toBe('array');
366366
});
367-
367+
368368
it('should switch categorymode on "array" if it is not supplied but categorylist is supplied', function() {
369369
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
370370
xaxis: {type: 'category', categorylist: ['b','a','d','e','c']}
@@ -374,11 +374,71 @@ describe('Test axes', function() {
374374

375375
it('should revert categorymode to "trace" if "array" is supplied but there is no list', function() {
376376
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
377-
xaxis: {type: 'category', categorymode: "array"}
377+
xaxis: {type: 'category', categorymode: 'array'}
378+
});
379+
expect(gd._fullLayout.xaxis.categorymode).toBe('trace');
380+
});
381+
382+
});
383+
384+
describe('do not set categorymode to "array" if list exists but empty', function() {
385+
386+
it('should switch categorymode to default if list is not supplied', function() {
387+
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
388+
xaxis: {type: 'category', categorymode: 'array', categorylist: []}
389+
});
390+
expect(gd._fullLayout.xaxis.categorymode).toBe('trace');
391+
});
392+
393+
it('should not switch categorymode on "array" if categorylist is supplied but empty', function() {
394+
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
395+
xaxis: {type: 'category', categorylist: []}
396+
});
397+
expect(gd._fullLayout.xaxis.categorymode).toBe('trace');
398+
});
399+
});
400+
401+
describe('do NOT set categorymode to "array" if it has some other proper value', function() {
402+
403+
it('should use specified categorymode if it is supplied even if categorylist exists', function() {
404+
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
405+
xaxis: {type: 'category', categorymode: 'trace', categorylist: ['b','a','d','e','c']}
378406
});
379407
expect(gd._fullLayout.xaxis.categorymode).toBe('trace');
380408
});
381409

410+
it('should use specified categorymode if it is supplied even if categorylist exists', function() {
411+
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
412+
xaxis: {type: 'category', categorymode: 'category ascending', categorylist: ['b','a','d','e','c']}
413+
});
414+
expect(gd._fullLayout.xaxis.categorymode).toBe('category ascending');
415+
});
416+
417+
it('should use specified categorymode if it is supplied even if categorylist exists', function() {
418+
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
419+
xaxis: {type: 'category', categorymode: 'category descending', categorylist: ['b','a','d','e','c']}
420+
});
421+
expect(gd._fullLayout.xaxis.categorymode).toBe('category descending');
422+
});
423+
424+
});
425+
426+
describe('setting categorymode to the default if the value is unexpected', function() {
427+
428+
it('should switch categorymode to "trace" if mode is supplied but invalid', function() {
429+
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
430+
xaxis: {type: 'category', categorymode: 'invalid value'}
431+
});
432+
expect(gd._fullLayout.xaxis.categorymode).toBe('trace');
433+
});
434+
435+
it('should switch categorymode to "array" if mode is supplied but invalid and list is supplied', function() {
436+
PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {
437+
xaxis: {type: 'category', categorymode: 'invalid value', categorylist: ['b','a','d','e','c']}
438+
});
439+
expect(gd._fullLayout.xaxis.categorymode).toBe('array');
440+
});
441+
382442
});
383443

384444
});

0 commit comments

Comments
 (0)