forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.spec.ts
More file actions
525 lines (427 loc) · 14.8 KB
/
config.spec.ts
File metadata and controls
525 lines (427 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
import { Config } from '../config';
import { Platform } from '../../platform/platform';
import { QueryParams } from '../../platform/query-params';
import { PLATFORM_CONFIGS } from '../../platform/platform-registry';
import { registerModeConfigs } from '../mode-registry';
describe('Config', () => {
it('should set activator setting to none for old Android Browser on a linux device', () => {
platform.setUserAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
platform.setNavigatorPlatform('linux');
platform.setQueryParams(qp);
platform.init();
config.init(null, qp, platform);
expect(config.get('activator')).toEqual('none');
});
it('should set activator setting to ripple for Android dev tools simulation on a mac', () => {
platform.setUserAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
platform.setNavigatorPlatform('MacIntel');
platform.setQueryParams(qp);
platform.init();
config.init(null, qp, platform);
expect(config.get('activator')).toEqual('ripple');
});
it('should set activator setting to none for Android Chrome versions below v36 on a linux device', () => {
platform.setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1650.59 Mobile Safari/537.36');
platform.setNavigatorPlatform('linux');
platform.setQueryParams(qp);
platform.init();
config.init(null, qp, platform);
expect(config.get('activator')).toEqual('none');
});
it('should set activator setting to ripple for Android Chrome v36 and above on a linux device', () => {
platform.setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1650.59 Mobile Safari/537.36');
platform.setNavigatorPlatform('linux');
platform.setQueryParams(qp);
platform.init();
config.init(null, qp, platform);
expect(config.get('activator')).toEqual('ripple');
});
it('should set activator setting to ripple for Android v5.0 and above on a linux device not using Chrome', () => {
platform.setUserAgent('Mozilla/5.0 (Android 5.0; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
platform.setNavigatorPlatform('linux');
platform.setQueryParams(qp);
platform.init();
config.init(null, qp, platform);
expect(config.get('activator')).toEqual('ripple');
});
it('should set activator setting to none for Android versions below v5.0 on a linux device not using Chrome', () => {
platform.setUserAgent('Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
platform.setNavigatorPlatform('linux');
platform.setQueryParams(qp);
platform.init();
config.init(null, qp, platform);
expect(config.get('activator')).toEqual('none');
});
it('should override mode settings', () => {
platform._platforms = ['ios'];
config.init({
mode: 'md'
}, qp, platform);
expect(config.get('mode')).toEqual('md');
expect(config.get('iconMode')).toEqual('md');
});
it('should override mode settings from platforms setting', () => {
platform._platforms = ['ios'];
config.init({
platforms: {
ios: {
mode: 'md'
}
}
}, qp, platform);
expect(config.get('mode')).toEqual('md');
expect(config.get('iconMode')).toEqual('md');
});
it('should get boolean value from querystring', () => {
qp = new QueryParams('http://biff.com/?ionicanimate=true');
config.init(null, qp, platform);
expect(config.get('animate')).toEqual(true);
config = new Config();
qp = new QueryParams('http://biff.com/?ionicanimate=false');
platform = new Platform();
config.init(null, qp, platform);
expect(config.get('animate')).toEqual(false);
});
it('should get value from case insensitive querystring key', () => {
qp = new QueryParams('http://biff.com/?ionicConfigKey=b');
config.init({
mode: 'a'
}, qp, platform);
expect(config.get('configKey')).toEqual('b');
});
it('should get value from querystring', () => {
qp = new QueryParams('http://biff.com/?ionicmode=modeB');
config.init({
mode: 'modeA'
}, qp, platform);
expect(config.get('mode')).toEqual('modeB');
});
it('should override mode platform', () => {
platform._platforms = ['mobile'];
config.init({
mode: 'modeA',
platforms: {
mobile: {
mode: 'modeB'
},
ios: {
mode: 'modeC'
}
}
}, qp, platform);
expect(config.get('mode')).toEqual('modeB');
});
it('should override mode', () => {
platform._platforms = ['core'];
config.init({
mode: 'modeA'
}, qp, platform);
expect(config.get('mode')).toEqual('modeA');
});
it('should get user settings after user platform settings', () => {
platform._platforms = ['ios'];
config.init({
hoverCSS: true
}, qp, platform);
expect(config.get('hoverCSS')).toEqual(true);
});
it('should get md mode for core platform', () => {
platform._platforms = ['core'];
config.init(null, qp, platform);
expect(config.get('mode')).toEqual('md');
});
it('should get ios mode for ipad platform', () => {
platform._platforms = ['mobile', 'ios', 'ipad', 'tablet'];
config.init(null, qp, platform);
expect(config.get('mode')).toEqual('ios');
});
it('should get md mode for windows platform', () => {
platform._platforms = ['mobile', 'windows'];
config.init(null, qp, platform);
expect(config.get('mode')).toEqual('wp');
});
it('should get md mode for android platform', () => {
platform._platforms = ['mobile', 'android'];
config.init(null, qp, platform);
expect(config.get('mode')).toEqual('md');
});
it('should override ios mode config with user platform setting', () => {
platform._platforms = ['ios'];
config.init({
tabsPlacement: 'hide',
platforms: {
ios: {
tabsPlacement: 'top'
}
}
}, qp, platform);
expect(config.get('tabsPlacement')).toEqual('top');
});
it('should override ios mode config with user setting', () => {
platform._platforms = ['ios'];
config.init({
tabsPlacement: 'top'
}, qp, platform);
expect(config.get('tabsPlacement')).toEqual('top');
});
it('should get setting from md mode', () => {
platform._platforms = ['android'];
config.init(null, qp, platform);
expect(config.get('iconMode')).toEqual('md');
});
it('should get setting from ios mode', () => {
platform._platforms = ['ios'];
config.init(null, qp, platform);
expect(config.get('tabsPlacement')).toEqual('bottom');
});
it('should set/get platform setting from set()', () => {
platform._platforms = ['ios'];
config.init(null, qp, platform);
config.set('tabsPlacement', 'bottom');
config.set('ios', 'tabsPlacement', 'top');
expect(config.get('tabsPlacement')).toEqual('top');
});
it('should set/get setting from set()', () => {
platform._platforms = ['ios'];
config.init(null, qp, platform);
config.set('tabsPlacement', 'top');
expect(config.get('tabsPlacement')).toEqual('top');
});
it('should set ios platform settings from settings()', () => {
platform._platforms = ['ios'];
config.init(null, qp, platform);
config.settings('ios', {
key: 'iosValue'
});
expect(config.get('key')).toEqual('iosValue');
});
it('should set/get mobile setting even w/ higher priority ios', () => {
platform._platforms = ['mobile', 'ios'];
config.init({
key: 'defaultValue',
platforms: {
mobile: {
key: 'mobileValue'
}
}
}, qp, platform);
expect(config.get('key')).toEqual('mobileValue');
});
it('should set/get mobile setting even w/ higher priority ios', () => {
platform._platforms = ['mobile', 'ios'];
config.init({
key: 'defaultValue',
platforms: {
mobile: {
key: 'mobileValue'
}
}
}, qp, platform);
expect(config.get('key')).toEqual('mobileValue');
});
it('should set/get android setting w/ higher priority than mobile', () => {
platform._platforms = ['mobile', 'android'];
config.init({
key: 'defaultValue',
platforms: {
mobile: {
key: 'mobileValue'
},
android: {
key: 'androidValue'
}
}
}, qp, platform);
expect(config.get('key')).toEqual('androidValue');
});
it('should set/get ios setting w/ platforms set', () => {
platform._platforms = ['ios'];
config.init(null, qp, platform);
config.settings({
key: 'defaultValue',
platforms: {
ios: {
key: 'iosValue'
},
android: {
key: 'androidValue'
}
}
});
expect(config.get('key')).toEqual('iosValue');
});
it('should set/get default setting w/ platforms set, but no platform match', () => {
config.settings({
key: 'defaultValue',
platforms: {
ios: {
key: 'iosValue'
},
android: {
key: 'androidValue'
}
}
});
expect(config.get('key')).toEqual('defaultValue');
});
it('should set setting object', () => {
config.settings({
name: 'Doc Brown',
occupation: 'Weather Man'
});
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('occupation')).toEqual('Weather Man');
expect(config.get('occupation')).toEqual('Weather Man');
});
it('should get null setting', () => {
config.init(null, null, null);
expect(config.get('name')).toEqual(null);
expect(config.get('name')).toEqual(null);
expect(config.get('occupation')).toEqual(null);
expect(config.get('occupation')).toEqual(null);
});
it('should set/get single setting', () => {
config.init(null, null, null);
config.set('name', 'Doc Brown');
config.set('occupation', 'Weather Man');
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('occupation')).toEqual('Weather Man');
expect(config.get('occupation')).toEqual('Weather Man');
});
it('should init w/ given config settings', () => {
config.init({
name: 'Doc Brown',
occupation: 'Weather Man'
}, null, null);
expect(config.get('name')).toEqual('Doc Brown');
expect(config.get('occupation')).toEqual('Weather Man');
});
it('should get a fallback value', () => {
config.init({
name: 'Doc Brown'
}, null, null);
expect(config.get('name', 'Marty')).toEqual('Doc Brown');
expect(config.get('occupation', 'Weather Man')).toEqual('Weather Man');
});
it('should get a boolean value with a boolean config value', () => {
config.init({
key1: true,
key2: false
}, null, null);
expect(config.getBoolean('key1')).toEqual(true);
expect(config.getBoolean('key2')).toEqual(false);
});
it('should get a boolean value with a string config value', () => {
config.init({
key1: 'true',
key2: 'false',
key3: 'whatever'
}, null, null);
expect(config.getBoolean('key1')).toEqual(true);
expect(config.getBoolean('key2')).toEqual(false);
expect(config.getBoolean('key3')).toEqual(false);
expect(config.getBoolean('key4')).toEqual(false);
expect(config.getBoolean('key5', true)).toEqual(true);
});
it('should get a boolean value with a number config value', () => {
config.init({
key1: 0,
key2: 1,
key3: 'whatever'
}, null, null);
expect(config.getBoolean('key1')).toEqual(false);
expect(config.getBoolean('key2')).toEqual(true);
});
it('should get a number value with a number config value', () => {
config.init({
key: 6
}, null, null);
expect(config.getNumber('key')).toEqual(6);
});
it('should get a number value with a string config value', () => {
config.init({
key: '6',
numThenString: '6baymax',
stringThenNum: 'baymax6'
}, null, null);
expect(config.getNumber('key', 5)).toEqual(6);
expect(config.getNumber('numThenString', 4)).toEqual(6);
expect( isNaN(config.getNumber('stringThenNum')) ).toEqual(true);
});
it('should get a number NaN value with a NaN config value', () => {
config.init({
allString: 'allstring',
imNull: null,
imUndefined: undefined
}, null, null);
expect( isNaN(config.getNumber('notfound'))).toEqual(true);
expect( isNaN(config.getNumber('allString'))).toEqual(true);
expect( isNaN(config.getNumber('imNull'))).toEqual(true);
expect( isNaN(config.getNumber('imUndefined'))).toEqual(true);
});
it('should get a number fallback value with a NaN config value', () => {
config.init({
allString: 'allstring',
imNull: null,
imUndefined: undefined
}, null, null);
expect( config.getNumber('notfound', 6)).toEqual(6);
expect( config.getNumber('allString', 6)).toEqual(6);
expect( config.getNumber('imNull', 6)).toEqual(6);
expect( config.getNumber('imUndefined', 6)).toEqual(6);
});
it('should get settings object', () => {
config.init({
name: 'Doc Brown',
occupation: 'Weather Man'
}, null, null);
expect(config.settings()).toEqual({
name: 'Doc Brown',
occupation: 'Weather Man'
});
});
it('should create default config w/ bad settings value', () => {
let config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
config = new Config();
config.init(null, null, null);
expect(config.settings()).toEqual({});
});
let platform: Platform;
let config: Config;
let qp: QueryParams;
beforeEach(() => {
config = new Config();
registerModeConfigs(config)();
qp = new QueryParams('');
platform = new Platform();
platform.setPlatformConfigs(PLATFORM_CONFIGS);
});
});