11import sortMenu from '../sortMenu' ;
22
33describe ( 'sortMenu' , ( ) => {
4- it ( 'modifies original array to follow the group, then name order provided ' , ( ) => {
4+ it ( 'returns a new array of sorted children ' , ( ) => {
55 const initialArray = [
66 { props : { group : 'DEV' , name : 'Inspector' } } ,
77 { props : { group : 'DEV' , name : 'JSON' } } ,
88 ] ;
99 const orderProp = [ { group : 'DEV' , name : 'JSON' } , { group : 'DEV' , name : 'Inspector' } ] ;
10+ const newArray = sortMenu ( initialArray , orderProp ) ;
1011
11- sortMenu ( initialArray , orderProp ) ;
1212 expect ( initialArray ) . toEqual ( [
13+ { props : { group : 'DEV' , name : 'Inspector' } } ,
14+ { props : { group : 'DEV' , name : 'JSON' } } ,
15+ ] ) ;
16+ expect ( newArray ) . toEqual ( [
1317 { props : { group : 'DEV' , name : 'JSON' } } ,
1418 { props : { group : 'DEV' , name : 'Inspector' } } ,
1519 ] ) ;
@@ -32,9 +36,9 @@ describe('sortMenu', () => {
3236 { group : 'Style' , name : 'Color Bars' } ,
3337 { group : 'Style' , name : 'Annotation' } ,
3438 ] ;
39+ const newArray = sortMenu ( initialArray , orderProp ) ;
3540
36- sortMenu ( initialArray , orderProp ) ;
37- expect ( initialArray ) . toEqual ( [
41+ expect ( newArray ) . toEqual ( [
3842 { props : { group : 'DEV' , name : 'JSON' } } ,
3943 { props : { group : 'DEV' , name : 'Inspector' } } ,
4044 { props : { group : 'Structure' , name : 'Subplots' } } ,
@@ -59,9 +63,9 @@ describe('sortMenu', () => {
5963 { group : 'Style' , name : 'Color Bars' } ,
6064 { group : 'Style' , name : 'Annotation' } ,
6165 ] ;
66+ const newArray = sortMenu ( initialArray , orderProp ) ;
6267
63- sortMenu ( initialArray , orderProp ) ;
64- expect ( initialArray ) . toEqual ( [
68+ expect ( newArray ) . toEqual ( [
6569 { props : { group : 'Structure' , name : 'Subplots' } } ,
6670 { props : { group : 'Structure' , name : 'Create' } } ,
6771 { props : { group : 'Style' , name : 'Color Bars' } } ,
@@ -79,9 +83,9 @@ describe('sortMenu', () => {
7983 { props : { group : 'Structure' , name : 'Create' } } ,
8084 ] ;
8185 const orderProp = [ { group : 'Style' , name : 'Traces' } ] ;
86+ const newArray = sortMenu ( initialArray , orderProp ) ;
8287
83- sortMenu ( initialArray , orderProp ) ;
84- expect ( initialArray ) . toEqual ( [
88+ expect ( newArray ) . toEqual ( [
8589 { props : { group : 'Style' , name : 'Traces' } } ,
8690 { props : { group : 'Style' , name : 'Axes' } } ,
8791 { props : { group : 'Style' , name : 'General' } } ,
@@ -96,16 +100,15 @@ describe('sortMenu', () => {
96100 { props : { group : 'Style' , name : 'Color Bars' } } ,
97101 { props : { group : 'Style' , name : 'Annotation' } } ,
98102 ] ;
99-
100103 const orderProp = [
101104 { group : 'Non Existent' , name : 'Subplots' } ,
102105 { group : 'Structure' , name : 'Create' } ,
103106 { group : 'Style' , name : 'Color Bars' } ,
104107 { group : 'Style' , name : 'Annotation' } ,
105108 ] ;
109+ const newArray = sortMenu ( initialArray , orderProp ) ;
106110
107- sortMenu ( initialArray , orderProp ) ;
108- expect ( initialArray ) . toEqual ( [
111+ expect ( newArray ) . toEqual ( [
109112 { props : { group : 'Structure' , name : 'Create' } } ,
110113 { props : { group : 'Structure' , name : 'Subplots' } } ,
111114 { props : { group : 'Style' , name : 'Color Bars' } } ,
@@ -120,15 +123,14 @@ describe('sortMenu', () => {
120123 { props : { group : 'Style' , name : 'Color Bars' } } ,
121124 { props : { group : 'Style' , name : 'Annotation' } } ,
122125 ] ;
123-
124126 const orderProp = [
125127 { group : 'Structure' , name : 'Non Existent' } ,
126128 { group : 'Style' , name : 'Color Bars' } ,
127129 { group : 'Style' , name : 'Annotation' } ,
128130 ] ;
131+ const newArray = sortMenu ( initialArray , orderProp ) ;
129132
130- sortMenu ( initialArray , orderProp ) ;
131- expect ( initialArray ) . toEqual ( [
133+ expect ( newArray ) . toEqual ( [
132134 { props : { group : 'Style' , name : 'Color Bars' } } ,
133135 { props : { group : 'Style' , name : 'Annotation' } } ,
134136 { props : { group : 'Structure' , name : 'Create' } } ,
@@ -143,19 +145,43 @@ describe('sortMenu', () => {
143145 { props : { group : 'Style' , name : 'Color Bars' } } ,
144146 { props : { group : 'Style' , name : 'Annotation' } } ,
145147 ] ;
146-
147148 const orderProp = [
148149 { group : 'Structure' , name : 'Annotation' } ,
149150 { group : 'Style' , name : 'Color Bars' } ,
150151 { group : 'Style' , name : 'Annotation' } ,
151152 ] ;
153+ const newArray = sortMenu ( initialArray , orderProp ) ;
152154
153- sortMenu ( initialArray , orderProp ) ;
154- expect ( initialArray ) . toEqual ( [
155+ expect ( newArray ) . toEqual ( [
155156 { props : { group : 'Style' , name : 'Color Bars' } } ,
156157 { props : { group : 'Style' , name : 'Annotation' } } ,
157158 { props : { group : 'Structure' , name : 'Create' } } ,
158159 { props : { group : 'Structure' , name : 'Subplots' } } ,
159160 ] ) ;
160161 } ) ;
162+
163+ it ( 'does not sort children with no group or name props' , ( ) => {
164+ const initialArray = [
165+ { props : { type : 'Logo' } } ,
166+ { props : { group : 'A' , name : 'A' } } ,
167+ { props : { group : 'Structure' , name : 'Subplots' } } ,
168+ { props : { group : 'Structure' , name : 'Create' } } ,
169+ { props : { type : 'ButtonA' } } ,
170+ { props : { type : 'ButtonB' } } ,
171+ ] ;
172+ const orderProp = [
173+ { group : 'Structure' , name : 'Create' } ,
174+ { group : 'Structure' , name : 'Subplots' } ,
175+ ] ;
176+ const newArray = sortMenu ( initialArray , orderProp ) ;
177+
178+ expect ( newArray ) . toEqual ( [
179+ { props : { type : 'Logo' } } ,
180+ { props : { group : 'Structure' , name : 'Create' } } ,
181+ { props : { group : 'Structure' , name : 'Subplots' } } ,
182+ { props : { group : 'A' , name : 'A' } } ,
183+ { props : { type : 'ButtonA' } } ,
184+ { props : { type : 'ButtonB' } } ,
185+ ] ) ;
186+ } ) ;
161187} ) ;
0 commit comments