Merge branch '19627-add-user' refs #19627
[arvados-workbench2.git] / src / common / url.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { customDecodeURI, customEncodeURI } from './url';
6
7 describe('url', () => {
8     describe('customDecodeURI', () => {
9         it('should decode encoded URI', () => {
10             // given
11             const path = 'test%23test%2Ftest';
12             const expectedResult = 'test#test%2Ftest';
13
14             // when
15             const result = customDecodeURI(path);
16
17             // then
18             expect(result).toEqual(expectedResult);
19         });
20
21         it('ignores non parsable URI and return its original form', () => {
22             // given
23             const path = 'test/path/with%wrong/sign';
24
25             // when
26             const result = customDecodeURI(path);
27
28             // then
29             expect(result).toEqual(path);
30         });
31     });
32
33     describe('customEncodeURI', () => {
34         it('should encode URI', () => {
35             // given
36             const path = 'test#test/test';
37             const expectedResult = 'test%23test/test';
38
39             // when
40             const result = customEncodeURI(path);
41
42             // then
43             expect(result).toEqual(expectedResult);
44         });
45
46         it('ignores non encodable URI and return its original form', () => {
47             // given
48             const path = 22;
49
50             // when
51             const result = customEncodeURI(path as any);
52
53             // then
54             expect(result).toEqual(path);
55         });
56     });
57 });