17337: Added another edge case handling
[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, encodeHash } from './url';
6
7 describe('url', () => {
8     describe('encodeHash', () => {
9         it('should ignore path without hash', () => {
10             // given
11             const path = 'path/without/hash';
12
13             // when
14             const result = encodeHash(path);
15
16             // then
17             expect(result).toEqual(path);
18         });
19
20         it('should replace all hashes within the path', () => {
21             // given
22             const path = 'path/with/hash # and one more #';
23             const expectedResult = 'path/with/hash %23 and one more %23';
24
25             // when
26             const result = encodeHash(path);
27
28             // then
29             expect(result).toEqual(expectedResult);
30         });
31     });
32
33     describe('customDecodeURI', () => {
34         it('should decode encoded URI', () => {
35             // given
36             const path = 'test%23test%2Ftest';
37             const expectedResult = 'test#test%2Ftest';
38
39             // when
40             const result = customDecodeURI(path);
41
42             // then
43             expect(result).toEqual(expectedResult);
44         });
45
46         it('ignores non parsable URI and return its original form', () => {
47             // given
48             const path = 'test/path/with%wrong/sign';
49
50             // when
51             const result = customDecodeURI(path);
52
53             // then
54             expect(result).toEqual(path);
55         });
56     });
57
58     describe('customEncodeURI', () => {
59         it('should encode URI', () => {
60             // given
61             const path = 'test#test/test';
62             const expectedResult = 'test%23test/test';
63
64             // when
65             const result = customEncodeURI(path);
66
67             // then
68             expect(result).toEqual(expectedResult);
69         });
70
71         it('ignores non encodable URI and return its original form', () => {
72             // given
73             const path = 22;
74
75             // when
76             const result = customEncodeURI(path as any);
77
78             // then
79             expect(result).toEqual(path);
80         });
81     });
82 });