1
1
import sortMenu from '../sortMenu' ;
2
2
3
3
describe ( 'sortMenu' , ( ) => {
4
- it ( 'modifies original array to follow the group, then name order provided ' , ( ) => {
4
+ it ( 'returns a new array of sorted children ' , ( ) => {
5
5
const initialArray = [
6
6
{ props : { group : 'DEV' , name : 'Inspector' } } ,
7
7
{ props : { group : 'DEV' , name : 'JSON' } } ,
8
8
] ;
9
9
const orderProp = [ { group : 'DEV' , name : 'JSON' } , { group : 'DEV' , name : 'Inspector' } ] ;
10
+ const newArray = sortMenu ( initialArray , orderProp ) ;
10
11
11
- sortMenu ( initialArray , orderProp ) ;
12
12
expect ( initialArray ) . toEqual ( [
13
+ { props : { group : 'DEV' , name : 'Inspector' } } ,
14
+ { props : { group : 'DEV' , name : 'JSON' } } ,
15
+ ] ) ;
16
+ expect ( newArray ) . toEqual ( [
13
17
{ props : { group : 'DEV' , name : 'JSON' } } ,
14
18
{ props : { group : 'DEV' , name : 'Inspector' } } ,
15
19
] ) ;
@@ -32,9 +36,9 @@ describe('sortMenu', () => {
32
36
{ group : 'Style' , name : 'Color Bars' } ,
33
37
{ group : 'Style' , name : 'Annotation' } ,
34
38
] ;
39
+ const newArray = sortMenu ( initialArray , orderProp ) ;
35
40
36
- sortMenu ( initialArray , orderProp ) ;
37
- expect ( initialArray ) . toEqual ( [
41
+ expect ( newArray ) . toEqual ( [
38
42
{ props : { group : 'DEV' , name : 'JSON' } } ,
39
43
{ props : { group : 'DEV' , name : 'Inspector' } } ,
40
44
{ props : { group : 'Structure' , name : 'Subplots' } } ,
@@ -59,9 +63,9 @@ describe('sortMenu', () => {
59
63
{ group : 'Style' , name : 'Color Bars' } ,
60
64
{ group : 'Style' , name : 'Annotation' } ,
61
65
] ;
66
+ const newArray = sortMenu ( initialArray , orderProp ) ;
62
67
63
- sortMenu ( initialArray , orderProp ) ;
64
- expect ( initialArray ) . toEqual ( [
68
+ expect ( newArray ) . toEqual ( [
65
69
{ props : { group : 'Structure' , name : 'Subplots' } } ,
66
70
{ props : { group : 'Structure' , name : 'Create' } } ,
67
71
{ props : { group : 'Style' , name : 'Color Bars' } } ,
@@ -79,9 +83,9 @@ describe('sortMenu', () => {
79
83
{ props : { group : 'Structure' , name : 'Create' } } ,
80
84
] ;
81
85
const orderProp = [ { group : 'Style' , name : 'Traces' } ] ;
86
+ const newArray = sortMenu ( initialArray , orderProp ) ;
82
87
83
- sortMenu ( initialArray , orderProp ) ;
84
- expect ( initialArray ) . toEqual ( [
88
+ expect ( newArray ) . toEqual ( [
85
89
{ props : { group : 'Style' , name : 'Traces' } } ,
86
90
{ props : { group : 'Style' , name : 'Axes' } } ,
87
91
{ props : { group : 'Style' , name : 'General' } } ,
@@ -96,16 +100,15 @@ describe('sortMenu', () => {
96
100
{ props : { group : 'Style' , name : 'Color Bars' } } ,
97
101
{ props : { group : 'Style' , name : 'Annotation' } } ,
98
102
] ;
99
-
100
103
const orderProp = [
101
104
{ group : 'Non Existent' , name : 'Subplots' } ,
102
105
{ group : 'Structure' , name : 'Create' } ,
103
106
{ group : 'Style' , name : 'Color Bars' } ,
104
107
{ group : 'Style' , name : 'Annotation' } ,
105
108
] ;
109
+ const newArray = sortMenu ( initialArray , orderProp ) ;
106
110
107
- sortMenu ( initialArray , orderProp ) ;
108
- expect ( initialArray ) . toEqual ( [
111
+ expect ( newArray ) . toEqual ( [
109
112
{ props : { group : 'Structure' , name : 'Create' } } ,
110
113
{ props : { group : 'Structure' , name : 'Subplots' } } ,
111
114
{ props : { group : 'Style' , name : 'Color Bars' } } ,
@@ -120,15 +123,14 @@ describe('sortMenu', () => {
120
123
{ props : { group : 'Style' , name : 'Color Bars' } } ,
121
124
{ props : { group : 'Style' , name : 'Annotation' } } ,
122
125
] ;
123
-
124
126
const orderProp = [
125
127
{ group : 'Structure' , name : 'Non Existent' } ,
126
128
{ group : 'Style' , name : 'Color Bars' } ,
127
129
{ group : 'Style' , name : 'Annotation' } ,
128
130
] ;
131
+ const newArray = sortMenu ( initialArray , orderProp ) ;
129
132
130
- sortMenu ( initialArray , orderProp ) ;
131
- expect ( initialArray ) . toEqual ( [
133
+ expect ( newArray ) . toEqual ( [
132
134
{ props : { group : 'Style' , name : 'Color Bars' } } ,
133
135
{ props : { group : 'Style' , name : 'Annotation' } } ,
134
136
{ props : { group : 'Structure' , name : 'Create' } } ,
@@ -143,19 +145,43 @@ describe('sortMenu', () => {
143
145
{ props : { group : 'Style' , name : 'Color Bars' } } ,
144
146
{ props : { group : 'Style' , name : 'Annotation' } } ,
145
147
] ;
146
-
147
148
const orderProp = [
148
149
{ group : 'Structure' , name : 'Annotation' } ,
149
150
{ group : 'Style' , name : 'Color Bars' } ,
150
151
{ group : 'Style' , name : 'Annotation' } ,
151
152
] ;
153
+ const newArray = sortMenu ( initialArray , orderProp ) ;
152
154
153
- sortMenu ( initialArray , orderProp ) ;
154
- expect ( initialArray ) . toEqual ( [
155
+ expect ( newArray ) . toEqual ( [
155
156
{ props : { group : 'Style' , name : 'Color Bars' } } ,
156
157
{ props : { group : 'Style' , name : 'Annotation' } } ,
157
158
{ props : { group : 'Structure' , name : 'Create' } } ,
158
159
{ props : { group : 'Structure' , name : 'Subplots' } } ,
159
160
] ) ;
160
161
} ) ;
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
+ } ) ;
161
187
} ) ;
0 commit comments