1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { customDecodeURI, customEncodeURI, encodeHash } from './url';
7 describe('url', () => {
8 describe('encodeHash', () => {
9 it('should ignore path without hash', () => {
11 const path = 'path/without/hash';
14 const result = encodeHash(path);
17 expect(result).toEqual(path);
20 it('should replace all hashes within the path', () => {
22 const path = 'path/with/hash # and one more #';
23 const expectedResult = 'path/with/hash %23 and one more %23';
26 const result = encodeHash(path);
29 expect(result).toEqual(expectedResult);
33 describe('customDecodeURI', () => {
34 it('should decode encoded URI', () => {
36 const path = 'test%23test%2Ftest';
37 const expectedResult = 'test#test%2Ftest';
40 const result = customDecodeURI(path);
43 expect(result).toEqual(expectedResult);
46 it('ignores non parsable URI and return its original form', () => {
48 const path = 'test/path/with%wrong/sign';
51 const result = customDecodeURI(path);
54 expect(result).toEqual(path);
58 describe('customEncodeURI', () => {
59 it('should encode URI', () => {
61 const path = 'test#test/test';
62 const expectedResult = 'test%23test/test';
65 const result = customEncodeURI(path);
68 expect(result).toEqual(expectedResult);
71 it('ignores non encodable URI and return its original form', () => {
76 const result = customEncodeURI(path as any);
79 expect(result).toEqual(path);