@@ -7,13 +7,13 @@ import { mock, when, anyString, instance, anyNumber, verify } from 'ts-mockito';
7
7
import { ColorService } from '../adapters/ColorService' ;
8
8
import { AssetService } from '../adapters/AssetResolver' ;
9
9
import { Deprecations } from './Deprecations' ;
10
+ import { CommandName } from '../interfaces/CommandName' ;
10
11
11
12
describe ( 'navigation options' , ( ) => {
12
13
let uut : OptionsProcessor ;
13
14
let optionProcessorsRegistry : OptionProcessorsStore ;
14
15
const mockedStore = mock ( Store ) as Store ;
15
16
const store = instance ( mockedStore ) as Store ;
16
- const setRootCommandName = 'setRoot' ;
17
17
beforeEach ( ( ) => {
18
18
const mockedAssetService = mock ( AssetService ) as AssetService ;
19
19
when ( mockedAssetService . resolveFromRequire ( anyNumber ( ) ) ) . thenReturn ( {
@@ -45,7 +45,7 @@ describe('navigation options', () => {
45
45
modalPresentationStyle : OptionsModalPresentationStyle . fullScreen ,
46
46
animations : { dismissModal : { alpha : { from : 0 , to : 1 } } } ,
47
47
} ;
48
- uut . processOptions ( options , setRootCommandName ) ;
48
+ uut . processOptions ( options , CommandName . SetRoot ) ;
49
49
expect ( options ) . toEqual ( {
50
50
blurOnUnmount : false ,
51
51
popGesture : false ,
@@ -65,14 +65,43 @@ describe('navigation options', () => {
65
65
return ! value ;
66
66
} ) ;
67
67
68
- uut . processOptions ( options , setRootCommandName ) ;
68
+ uut . processOptions ( options , CommandName . SetRoot ) ;
69
69
expect ( options ) . toEqual ( {
70
70
topBar : {
71
71
visible : false ,
72
72
} ,
73
73
} ) ;
74
74
} ) ;
75
75
76
+ it ( 'process options object with multiple values using registered processor' , ( ) => {
77
+ const options : Options = {
78
+ topBar : {
79
+ visible : true ,
80
+ background : {
81
+ translucent : true ,
82
+ } ,
83
+ } ,
84
+ } ;
85
+
86
+ optionProcessorsRegistry . addProcessor ( 'topBar.visible' , ( value : boolean ) => {
87
+ return ! value ;
88
+ } ) ;
89
+
90
+ optionProcessorsRegistry . addProcessor ( 'topBar.background.translucent' , ( value : boolean ) => {
91
+ return ! value ;
92
+ } ) ;
93
+
94
+ uut . processOptions ( options , CommandName . SetRoot ) ;
95
+ expect ( options ) . toEqual ( {
96
+ topBar : {
97
+ visible : false ,
98
+ background : {
99
+ translucent : false ,
100
+ } ,
101
+ } ,
102
+ } ) ;
103
+ } ) ;
104
+
76
105
it ( 'passes commandName to registered processor' , ( ) => {
77
106
const options : Options = {
78
107
topBar : {
@@ -81,10 +110,10 @@ describe('navigation options', () => {
81
110
} ;
82
111
83
112
optionProcessorsRegistry . addProcessor ( 'topBar.visible' , ( _value , commandName ) => {
84
- expect ( commandName ) . toEqual ( setRootCommandName ) ;
113
+ expect ( commandName ) . toEqual ( CommandName . SetRoot ) ;
85
114
} ) ;
86
115
87
- uut . processOptions ( options , setRootCommandName ) ;
116
+ uut . processOptions ( options , CommandName . SetRoot ) ;
88
117
} ) ;
89
118
90
119
it ( 'supports multiple registered processors' , ( ) => {
@@ -97,7 +126,7 @@ describe('navigation options', () => {
97
126
optionProcessorsRegistry . addProcessor ( 'topBar.visible' , ( ) => false ) ;
98
127
optionProcessorsRegistry . addProcessor ( 'topBar.visible' , ( ) => true ) ;
99
128
100
- uut . processOptions ( options , setRootCommandName ) ;
129
+ uut . processOptions ( options , CommandName . SetRoot ) ;
101
130
expect ( options ) . toEqual ( {
102
131
topBar : {
103
132
visible : true ,
@@ -110,7 +139,7 @@ describe('navigation options', () => {
110
139
statusBar : { backgroundColor : 'red' } ,
111
140
topBar : { background : { color : 'blue' } } ,
112
141
} ;
113
- uut . processOptions ( options , setRootCommandName ) ;
142
+ uut . processOptions ( options , CommandName . SetRoot ) ;
114
143
expect ( options ) . toEqual ( {
115
144
statusBar : { backgroundColor : 666 } ,
116
145
topBar : { background : { color : 666 } } ,
@@ -123,7 +152,7 @@ describe('navigation options', () => {
123
152
rootBackgroundImage : 234 ,
124
153
bottomTab : { icon : 345 , selectedIcon : 345 } ,
125
154
} ;
126
- uut . processOptions ( options , setRootCommandName ) ;
155
+ uut . processOptions ( options , CommandName . SetRoot ) ;
127
156
expect ( options ) . toEqual ( {
128
157
backgroundImage : { height : 100 , scale : 1 , uri : 'lol' , width : 100 } ,
129
158
rootBackgroundImage : { height : 100 , scale : 1 , uri : 'lol' , width : 100 } ,
@@ -138,15 +167,15 @@ describe('navigation options', () => {
138
167
const passProps = { some : 'thing' } ;
139
168
const options = { topBar : { title : { component : { passProps, name : 'a' } } } } ;
140
169
141
- uut . processOptions ( options , setRootCommandName ) ;
170
+ uut . processOptions ( options , CommandName . SetRoot ) ;
142
171
143
172
verify ( mockedStore . updateProps ( 'CustomComponent1' , passProps ) ) . called ( ) ;
144
173
} ) ;
145
174
146
175
it ( 'generates componentId for component id was not passed' , ( ) => {
147
176
const options = { topBar : { title : { component : { name : 'a' } } } } ;
148
177
149
- uut . processOptions ( options , setRootCommandName ) ;
178
+ uut . processOptions ( options , CommandName . SetRoot ) ;
150
179
151
180
expect ( options ) . toEqual ( {
152
181
topBar : { title : { component : { name : 'a' , componentId : 'CustomComponent1' } } } ,
@@ -156,7 +185,7 @@ describe('navigation options', () => {
156
185
it ( 'copies passed id to componentId key' , ( ) => {
157
186
const options = { topBar : { title : { component : { name : 'a' , id : 'Component1' } } } } ;
158
187
159
- uut . processOptions ( options , setRootCommandName ) ;
188
+ uut . processOptions ( options , CommandName . SetRoot ) ;
160
189
161
190
expect ( options ) . toEqual ( {
162
191
topBar : { title : { component : { name : 'a' , id : 'Component1' , componentId : 'Component1' } } } ,
@@ -167,7 +196,7 @@ describe('navigation options', () => {
167
196
const passProps = { prop : 'prop' } ;
168
197
const options = { topBar : { rightButtons : [ { passProps, id : '1' } ] } } ;
169
198
170
- uut . processOptions ( options , setRootCommandName ) ;
199
+ uut . processOptions ( options , CommandName . SetRoot ) ;
171
200
172
201
verify ( mockedStore . updateProps ( '1' , passProps ) ) . called ( ) ;
173
202
} ) ;
@@ -176,7 +205,7 @@ describe('navigation options', () => {
176
205
const passProps = { prop : 'prop' } ;
177
206
const options = { topBar : { rightButtons : [ { passProps } as any ] } } ;
178
207
179
- uut . processOptions ( options , setRootCommandName ) ;
208
+ uut . processOptions ( options , CommandName . SetRoot ) ;
180
209
181
210
expect ( options ) . toEqual ( { topBar : { rightButtons : [ { passProps } ] } } ) ;
182
211
} ) ;
@@ -190,7 +219,7 @@ describe('navigation options', () => {
190
219
background : { component : { name : 'helloThere2' , passProps : { } } } ,
191
220
} ,
192
221
} ;
193
- uut . processOptions ( options , setRootCommandName ) ;
222
+ uut . processOptions ( options , CommandName . SetRoot ) ;
194
223
expect ( options . topBar . rightButtons [ 0 ] . passProps ) . toBeUndefined ( ) ;
195
224
expect ( options . topBar . leftButtons [ 0 ] . passProps ) . toBeUndefined ( ) ;
196
225
expect ( options . topBar . title . component . passProps ) . toBeUndefined ( ) ;
@@ -204,14 +233,14 @@ describe('navigation options', () => {
204
233
background : { component : { name : 'helloThere2' , passProps : { } } } ,
205
234
} ,
206
235
} ;
207
- uut . processOptions ( options , setRootCommandName ) ;
236
+ uut . processOptions ( options , CommandName . SetRoot ) ;
208
237
verify ( mockedStore . ensureClassForName ( 'helloThere1' ) ) . called ( ) ;
209
238
verify ( mockedStore . ensureClassForName ( 'helloThere2' ) ) . called ( ) ;
210
239
} ) ;
211
240
212
241
it ( 'show warning on iOS when toggling bottomTabs visibility through mergeOptions' , ( ) => {
213
242
jest . spyOn ( console , 'warn' ) ;
214
- uut . processOptions ( { bottomTabs : { visible : false } } , 'mergeOptions' ) ;
243
+ uut . processOptions ( { bottomTabs : { visible : false } } , CommandName . MergeOptions ) ;
215
244
expect ( console . warn ) . toBeCalledWith (
216
245
'toggling bottomTabs visibility is deprecated on iOS. For more information see https://github.com/wix/react-native-navigation/issues/6416' ,
217
246
{
0 commit comments