17337: Added custom encode functions with tests
[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('customEncodeURI', () => {
34         it('should decode', () => {
35             // given
36             const path = 'test%23test%2Ftest';
37             const expectedResult = 'test#test/test';
38
39             // when
40             const result = customDecodeURI(path);
41
42             // then
43             expect(result).toEqual(expectedResult);
44         });
45     });
46
47     describe('customEncodeURI', () => {
48         it('should encode', () => {
49             // given
50             const path = 'test#test/test';
51             const expectedResult = 'test%23test%2Ftest';
52
53             // when
54             const result = customEncodeURI(path);
55
56             // then
57             expect(result).toEqual(expectedResult);
58         });
59     });
60 });