11import sortMenu from '../sortMenu' ;
22
3+ function stringify ( array ) {
4+ let string = '' ;
5+ array . forEach ( obj => {
6+ string += JSON . stringify ( obj ) ;
7+ } ) ;
8+ return string ;
9+ }
10+
311describe ( 'sortMenu' , ( ) => {
412 it ( 'modifies original array to follow the group, then name order provided' , ( ) => {
513 const initialArray = [
614 { props : { group : 'DEV' , name : 'Inspector' } } ,
715 { props : { group : 'DEV' , name : 'JSON' } } ,
816 ] ;
917 const orderProp = [ { group : 'DEV' , name : 'JSON' } , { group : 'DEV' , name : 'Inspector' } ] ;
10- sortMenu ( initialArray , orderProp ) ;
1118
12- expect ( initialArray [ 0 ] . props . name ) . toBe ( 'JSON' ) ;
13- expect ( initialArray [ 1 ] . props . name ) . toBe ( 'Inspector' ) ;
19+ sortMenu ( initialArray , orderProp ) ;
20+ expect ( stringify ( initialArray ) ) . toBe (
21+ stringify ( [ { props : { group : 'DEV' , name : 'JSON' } } , { props : { group : 'DEV' , name : 'Inspector' } } ] )
22+ ) ;
1423 } ) ;
1524
1625 it ( 'sorts the array by group, then by name' , ( ) => {
@@ -22,7 +31,6 @@ describe('sortMenu', () => {
2231 { props : { group : 'DEV' , name : 'Inspector' } } ,
2332 { props : { group : 'DEV' , name : 'JSON' } } ,
2433 ] ;
25-
2634 const orderProp = [
2735 { group : 'DEV' , name : 'JSON' } ,
2836 { group : 'DEV' , name : 'Inspector' } ,
@@ -33,18 +41,16 @@ describe('sortMenu', () => {
3341 ] ;
3442
3543 sortMenu ( initialArray , orderProp ) ;
36- expect ( initialArray [ 0 ] . props . group ) . toBe ( 'DEV' ) ;
37- expect ( initialArray [ 0 ] . props . name ) . toBe ( 'JSON' ) ;
38- expect ( initialArray [ 1 ] . props . group ) . toBe ( 'DEV' ) ;
39- expect ( initialArray [ 1 ] . props . name ) . toBe ( 'Inspector' ) ;
40- expect ( initialArray [ 2 ] . props . group ) . toBe ( 'Structure' ) ;
41- expect ( initialArray [ 2 ] . props . name ) . toBe ( 'Subplots' ) ;
42- expect ( initialArray [ 3 ] . props . group ) . toBe ( 'Structure' ) ;
43- expect ( initialArray [ 3 ] . props . name ) . toBe ( 'Create' ) ;
44- expect ( initialArray [ 4 ] . props . group ) . toBe ( 'Style' ) ;
45- expect ( initialArray [ 4 ] . props . name ) . toBe ( 'Color Bars' ) ;
46- expect ( initialArray [ 5 ] . props . group ) . toBe ( 'Style' ) ;
47- expect ( initialArray [ 5 ] . props . name ) . toBe ( 'Annotation' ) ;
44+ expect ( stringify ( initialArray ) ) . toBe (
45+ stringify ( [
46+ { props : { group : 'DEV' , name : 'JSON' } } ,
47+ { props : { group : 'DEV' , name : 'Inspector' } } ,
48+ { props : { group : 'Structure' , name : 'Subplots' } } ,
49+ { props : { group : 'Structure' , name : 'Create' } } ,
50+ { props : { group : 'Style' , name : 'Color Bars' } } ,
51+ { props : { group : 'Style' , name : 'Annotation' } } ,
52+ ] )
53+ ) ;
4854 } ) ;
4955
5056 it ( 'puts not mentionned panels to the bottom of list and sorts alphabetically' , ( ) => {
@@ -64,18 +70,16 @@ describe('sortMenu', () => {
6470 ] ;
6571
6672 sortMenu ( initialArray , orderProp ) ;
67- expect ( initialArray [ 0 ] . props . group ) . toBe ( 'Structure' ) ;
68- expect ( initialArray [ 0 ] . props . name ) . toBe ( 'Subplots' ) ;
69- expect ( initialArray [ 1 ] . props . group ) . toBe ( 'Structure' ) ;
70- expect ( initialArray [ 1 ] . props . name ) . toBe ( 'Create' ) ;
71- expect ( initialArray [ 2 ] . props . group ) . toBe ( 'Style' ) ;
72- expect ( initialArray [ 2 ] . props . name ) . toBe ( 'Color Bars' ) ;
73- expect ( initialArray [ 3 ] . props . group ) . toBe ( 'Style' ) ;
74- expect ( initialArray [ 3 ] . props . name ) . toBe ( 'Annotation' ) ;
75- expect ( initialArray [ 4 ] . props . group ) . toBe ( 'DEV' ) ;
76- expect ( initialArray [ 4 ] . props . name ) . toBe ( 'Inspector' ) ;
77- expect ( initialArray [ 5 ] . props . group ) . toBe ( 'DEV' ) ;
78- expect ( initialArray [ 5 ] . props . name ) . toBe ( 'JSON' ) ;
73+ expect ( stringify ( initialArray ) ) . toBe (
74+ stringify ( [
75+ { props : { group : 'Structure' , name : 'Subplots' } } ,
76+ { props : { group : 'Structure' , name : 'Create' } } ,
77+ { props : { group : 'Style' , name : 'Color Bars' } } ,
78+ { props : { group : 'Style' , name : 'Annotation' } } ,
79+ { props : { group : 'DEV' , name : 'Inspector' } } ,
80+ { props : { group : 'DEV' , name : 'JSON' } } ,
81+ ] )
82+ ) ;
7983 } ) ;
8084
8185 it ( 'orders not mentionned subpanels at the end, alphabetically' , ( ) => {
@@ -85,17 +89,17 @@ describe('sortMenu', () => {
8589 { props : { group : 'Style' , name : 'Axes' } } ,
8690 { props : { group : 'Structure' , name : 'Create' } } ,
8791 ] ;
88- const orderProp = [ { group : 'Style' , name : 'Traces' } , { group : 'Structure' , name : 'Create' } ] ;
92+ const orderProp = [ { group : 'Style' , name : 'Traces' } ] ;
8993
9094 sortMenu ( initialArray , orderProp ) ;
91- expect ( initialArray [ 0 ] . props . group ) . toBe ( 'Style' ) ;
92- expect ( initialArray [ 0 ] . props . name ) . toBe ( 'Traces' ) ;
93- expect ( initialArray [ 1 ] . props . group ) . toBe ( 'Style' ) ;
94- expect ( initialArray [ 1 ] . props . name ) . toBe ( 'Axes' ) ;
95- expect ( initialArray [ 2 ] . props . group ) . toBe ( 'Style' ) ;
96- expect ( initialArray [ 2 ] . props . name ) . toBe ( 'General' ) ;
97- expect ( initialArray [ 3 ] . props . group ) . toBe ( 'Structure' ) ;
98- expect ( initialArray [ 3 ] . props . name ) . toBe ( 'Create' ) ;
95+ expect ( stringify ( initialArray ) ) . toBe (
96+ stringify ( [
97+ { props : { group : 'Style' , name : 'Traces' } } ,
98+ { props : { group : 'Style' , name : 'Axes' } } ,
99+ { props : { group : 'Style' , name : 'General' } } ,
100+ { props : { group : 'Structure' , name : 'Create' } } ,
101+ ] )
102+ ) ;
99103 } ) ;
100104
101105 it ( 'ignores non existent panel groups' , ( ) => {
@@ -114,14 +118,14 @@ describe('sortMenu', () => {
114118 ] ;
115119
116120 sortMenu ( initialArray , orderProp ) ;
117- expect ( initialArray [ 0 ] . props . group ) . toBe ( 'Structure' ) ;
118- expect ( initialArray [ 0 ] . props . name ) . toBe ( 'Create' ) ;
119- expect ( initialArray [ 1 ] . props . group ) . toBe ( 'Structure' ) ;
120- expect ( initialArray [ 1 ] . props . name ) . toBe ( 'Subplots' ) ;
121- expect ( initialArray [ 2 ] . props . group ) . toBe ( 'Style' ) ;
122- expect ( initialArray [ 2 ] . props . name ) . toBe ( 'Color Bars' ) ;
123- expect ( initialArray [ 3 ] . props . group ) . toBe ( 'Style' ) ;
124- expect ( initialArray [ 3 ] . props . name ) . toBe ( 'Annotation' ) ;
121+ expect ( stringify ( initialArray ) ) . toBe (
122+ stringify ( [
123+ { props : { group : 'Structure' , name : 'Create' } } ,
124+ { props : { group : 'Structure' , name : 'Subplots' } } ,
125+ { props : { group : 'Style' , name : 'Color Bars' } } ,
126+ { props : { group : 'Style' , name : 'Annotation' } } ,
127+ ] )
128+ ) ;
125129 } ) ;
126130
127131 it ( 'ignores non existent panel names' , ( ) => {
@@ -139,14 +143,14 @@ describe('sortMenu', () => {
139143 ] ;
140144
141145 sortMenu ( initialArray , orderProp ) ;
142- expect ( initialArray [ 0 ] . props . group ) . toBe ( 'Style' ) ;
143- expect ( initialArray [ 0 ] . props . name ) . toBe ( 'Color Bars' ) ;
144- expect ( initialArray [ 1 ] . props . group ) . toBe ( 'Style' ) ;
145- expect ( initialArray [ 1 ] . props . name ) . toBe ( 'Annotation' ) ;
146- expect ( initialArray [ 2 ] . props . group ) . toBe ( 'Structure' ) ;
147- expect ( initialArray [ 2 ] . props . name ) . toBe ( 'Create' ) ;
148- expect ( initialArray [ 3 ] . props . group ) . toBe ( 'Structure' ) ;
149- expect ( initialArray [ 3 ] . props . name ) . toBe ( 'Subplots' ) ;
146+ expect ( stringify ( initialArray ) ) . toBe (
147+ stringify ( [
148+ { props : { group : 'Style' , name : 'Color Bars' } } ,
149+ { props : { group : 'Style' , name : 'Annotation' } } ,
150+ { props : { group : 'Structure' , name : 'Create' } } ,
151+ { props : { group : 'Structure' , name : 'Subplots' } } ,
152+ ] )
153+ ) ;
150154 } ) ;
151155
152156 it ( 'ignores invalid combinations' , ( ) => {
@@ -164,13 +168,13 @@ describe('sortMenu', () => {
164168 ] ;
165169
166170 sortMenu ( initialArray , orderProp ) ;
167- expect ( initialArray [ 0 ] . props . group ) . toBe ( 'Style' ) ;
168- expect ( initialArray [ 0 ] . props . name ) . toBe ( 'Color Bars' ) ;
169- expect ( initialArray [ 1 ] . props . group ) . toBe ( 'Style' ) ;
170- expect ( initialArray [ 1 ] . props . name ) . toBe ( 'Annotation' ) ;
171- expect ( initialArray [ 2 ] . props . group ) . toBe ( 'Structure' ) ;
172- expect ( initialArray [ 2 ] . props . name ) . toBe ( 'Create' ) ;
173- expect ( initialArray [ 3 ] . props . group ) . toBe ( 'Structure' ) ;
174- expect ( initialArray [ 3 ] . props . name ) . toBe ( 'Subplots' ) ;
171+ expect ( stringify ( initialArray ) ) . toBe (
172+ stringify ( [
173+ { props : { group : 'Style' , name : 'Color Bars' } } ,
174+ { props : { group : 'Style' , name : 'Annotation' } } ,
175+ { props : { group : 'Structure' , name : 'Create' } } ,
176+ { props : { group : 'Structure' , name : 'Subplots' } } ,
177+ ] )
178+ ) ;
175179 } ) ;
176180} ) ;
0 commit comments