@@ -49,3 +49,57 @@ describe('zoom box element', function() {
49
49
. toEqual ( 0 ) ;
50
50
} ) ;
51
51
} ) ;
52
+
53
+ describe ( 'relayout' , function ( ) {
54
+
55
+ describe ( 'axis category attributes' , function ( ) {
56
+ var mock = require ( '@mocks/basic_bar.json' ) ;
57
+
58
+ var gd , mockCopy ;
59
+
60
+ beforeEach ( function ( ) {
61
+ mockCopy = Lib . extendDeep ( { } , mock ) ;
62
+ gd = createGraphDiv ( ) ;
63
+ } ) ;
64
+
65
+ afterEach ( destroyGraphDiv ) ;
66
+
67
+ it ( 'should response to \'categoryarray\' and \'categoryorder\' updates' , function ( done ) {
68
+ function assertCategories ( list ) {
69
+ d3 . selectAll ( 'g.xtick' ) . each ( function ( _ , i ) {
70
+ var tick = d3 . select ( this ) . select ( 'text' ) ;
71
+ expect ( tick . html ( ) ) . toEqual ( list [ i ] ) ;
72
+ } ) ;
73
+ }
74
+
75
+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
76
+ assertCategories ( [ 'giraffes' , 'orangutans' , 'monkeys' ] ) ;
77
+
78
+ return Plotly . relayout ( gd , 'xaxis.categoryorder' , 'category descending' ) ;
79
+ } ) . then ( function ( ) {
80
+ var list = [ 'orangutans' , 'monkeys' , 'giraffes' ] ;
81
+
82
+ expect ( gd . _fullLayout . xaxis . _initialCategories ) . toEqual ( list ) ;
83
+ assertCategories ( list ) ;
84
+
85
+ return Plotly . relayout ( gd , 'xaxis.categoryorder' , null ) ;
86
+ } ) . then ( function ( ) {
87
+ assertCategories ( [ 'giraffes' , 'orangutans' , 'monkeys' ] ) ;
88
+
89
+ return Plotly . relayout ( gd , {
90
+ 'xaxis.categoryarray' : [ 'monkeys' , 'giraffes' , 'orangutans' ]
91
+ } ) ;
92
+ } ) . then ( function ( ) {
93
+ var list = [ 'monkeys' , 'giraffes' , 'orangutans' ] ;
94
+
95
+ expect ( gd . layout . xaxis . categoryarray ) . toEqual ( list ) ;
96
+ expect ( gd . _fullLayout . xaxis . categoryarray ) . toEqual ( list ) ;
97
+ expect ( gd . _fullLayout . xaxis . _initialCategories ) . toEqual ( list ) ;
98
+ assertCategories ( list ) ;
99
+
100
+ done ( ) ;
101
+ } ) ;
102
+ } ) ;
103
+ } ) ;
104
+
105
+ } ) ;
0 commit comments