This repository was archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathparams.spec.ts
67 lines (57 loc) · 1.98 KB
/
params.spec.ts
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
import { SkyAppRuntimeConfigParams } from './params';
describe('SkyAppRuntimeConfigParams', () => {
const allowed = [
'a1',
'a3'
];
it('should parse allowed params from a url', () => {
const params: SkyAppRuntimeConfigParams = new SkyAppRuntimeConfigParams(
'https://example.com/?a1=a&b2=jkl&a3=b',
allowed
);
expect(params.getAllKeys()).toEqual(['a1', 'a3']);
expect(params.get('a1')).toEqual('a');
expect(params.get('b2')).not.toEqual('jkl');
expect(params.get('a3')).toEqual('b');
expect(params.getAll()).toEqual({
a1: 'a',
a3: 'b'
});
});
it('should only let allowed params be set', () => {
const params: SkyAppRuntimeConfigParams = new SkyAppRuntimeConfigParams(
'?a1=b&b2=c',
allowed
);
expect(params.get('a1')).toEqual('b');
expect(params.get('b2')).not.toEqual('c');
});
it('should add the current params to a url with a querystring', () => {
const params: SkyAppRuntimeConfigParams = new SkyAppRuntimeConfigParams(
'?a1=b',
allowed
);
expect(params.getUrl('https://mysite.com?c=d')).toEqual('https://mysite.com?c=d&a1=b');
});
it('should not add a current param if the url already has it', () => {
const params: SkyAppRuntimeConfigParams = new SkyAppRuntimeConfigParams(
'?a1=b',
allowed
);
expect(params.getUrl('https://mysite.com?a1=c&a3=e')).toEqual('https://mysite.com?a1=c&a3=e');
});
it('should add the current params to a url without a querystring', () => {
const params: SkyAppRuntimeConfigParams = new SkyAppRuntimeConfigParams(
'?a1=b',
allowed
);
expect(params.getUrl('https://mysite.com')).toEqual('https://mysite.com?a1=b');
});
it('should return the current url if no params set (do not add ?)', () => {
const params: SkyAppRuntimeConfigParams = new SkyAppRuntimeConfigParams(
'',
allowed
);
expect(params.getUrl('https://mysite.com')).toEqual('https://mysite.com');
});
});