diff options
Diffstat (limited to 'src/helpers/url-helpers.test.ts')
-rw-r--r-- | src/helpers/url-helpers.test.ts | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/src/helpers/url-helpers.test.ts b/src/helpers/url-helpers.test.ts deleted file mode 100644 index 5af3025e9..000000000 --- a/src/helpers/url-helpers.test.ts +++ /dev/null | |||
@@ -1,119 +0,0 @@ | |||
1 | import * as url_helpers from './url-helpers' | ||
2 | |||
3 | describe('url_helpers', () => { | ||
4 | describe('isValidExternalURL', () => { | ||
5 | describe('with string', () => { | ||
6 | it('returns false for empty string', () => { | ||
7 | const result = url_helpers.isValidExternalURL(''); | ||
8 | expect(result).toBe(false); | ||
9 | }); | ||
10 | |||
11 | it('returns false for whitespace string', () => { | ||
12 | const result = url_helpers.isValidExternalURL(' '); | ||
13 | expect(result).toBe(false); | ||
14 | }); | ||
15 | |||
16 | it('returns false for random string', () => { | ||
17 | const result = url_helpers.isValidExternalURL('some random string'); | ||
18 | expect(result).toBe(false); | ||
19 | }); | ||
20 | |||
21 | it('returns false for invalid url', () => { | ||
22 | const result = url_helpers.isValidExternalURL('shttps://google'); | ||
23 | expect(result).toBe(false); | ||
24 | }); | ||
25 | |||
26 | it('returns true for valid http url', () => { | ||
27 | const result = url_helpers.isValidExternalURL('http://google'); | ||
28 | expect(result).toBe(true); | ||
29 | }); | ||
30 | |||
31 | it('returns true for valid https url', () => { | ||
32 | const result = url_helpers.isValidExternalURL('https://google'); | ||
33 | expect(result).toBe(true); | ||
34 | }); | ||
35 | }); | ||
36 | |||
37 | describe('with URL', () => { | ||
38 | // Note: not testing the invalid string urls - since the URL ctor itself will raise an error | ||
39 | |||
40 | it('returns false for invalid url', () => { | ||
41 | const result = url_helpers.isValidExternalURL(new URL('shttps://google')); | ||
42 | expect(result).toBe(false); | ||
43 | }); | ||
44 | |||
45 | it('returns true for valid http url', () => { | ||
46 | const result = url_helpers.isValidExternalURL(new URL('http://google')); | ||
47 | expect(result).toBe(true); | ||
48 | }); | ||
49 | |||
50 | it('returns true for valid https url', () => { | ||
51 | const result = url_helpers.isValidExternalURL(new URL('https://google')); | ||
52 | expect(result).toBe(true); | ||
53 | }); | ||
54 | }); | ||
55 | }); | ||
56 | |||
57 | describe('fixUrl', () => { | ||
58 | it('handles with empty string', () => { | ||
59 | const result = url_helpers.fixUrl(''); | ||
60 | expect(result).toEqual(''); | ||
61 | }); | ||
62 | |||
63 | it('handles with whitespace string', () => { | ||
64 | const result = url_helpers.fixUrl(' '); | ||
65 | expect(result).toEqual(' '); | ||
66 | }); | ||
67 | |||
68 | it('handles with random string', () => { | ||
69 | const result = url_helpers.fixUrl('some random string'); | ||
70 | expect(result).toEqual('some random string'); | ||
71 | }); | ||
72 | |||
73 | it('handles string starting with http://', () => { | ||
74 | expect(url_helpers.fixUrl('http://some/random/url')).toEqual('http://some/random/url'); | ||
75 | expect(url_helpers.fixUrl('http://some//random//url')).toEqual('http://some/random/url'); | ||
76 | |||
77 | const gmailEmbeddedUrl = 'https://www.google.com/url?q=https://github.com/ferdium/ferdium-app/issues/87&source=gmail'; | ||
78 | expect(url_helpers.fixUrl(gmailEmbeddedUrl)).toEqual(gmailEmbeddedUrl); // it should NOT remove the double-slash from the embedded url in the query string | ||
79 | }); | ||
80 | |||
81 | it('handles string starting with https://', () => { | ||
82 | expect(url_helpers.fixUrl('https://some/random/url')).toEqual('https://some/random/url'); | ||
83 | expect(url_helpers.fixUrl('https://some//random//url')).toEqual('https://some/random/url'); | ||
84 | }); | ||
85 | |||
86 | it('handles string starting with file://', () => { | ||
87 | expect(url_helpers.fixUrl('file://some/random/url')).toEqual('file://some/random/url'); | ||
88 | expect(url_helpers.fixUrl('file://some//random//url')).toEqual('file://some/random/url'); | ||
89 | }); | ||
90 | }); | ||
91 | |||
92 | describe('isValidFileUrl', () => { | ||
93 | it('returns false for empty string', () => { | ||
94 | const result = url_helpers.isValidFileUrl(''); | ||
95 | expect(result).toBe(false); | ||
96 | }); | ||
97 | |||
98 | it('returns false for whitespace string', () => { | ||
99 | const result = url_helpers.isValidFileUrl(' '); | ||
100 | expect(result).toBe(false); | ||
101 | }); | ||
102 | |||
103 | it('returns false for random string', () => { | ||
104 | const result = url_helpers.isValidFileUrl('some random string'); | ||
105 | expect(result).toBe(false); | ||
106 | }); | ||
107 | |||
108 | it('returns false for invalid url', () => { | ||
109 | const result = url_helpers.isValidFileUrl('sfile://google'); | ||
110 | expect(result).toBe(false); | ||
111 | }); | ||
112 | |||
113 | it('returns true for valid file url', () => { | ||
114 | const fileName = process.platform === 'win32' ? 'file:///c:\\' : 'file:///'; | ||
115 | const result = url_helpers.isValidFileUrl(fileName); | ||
116 | expect(result).toBe(true); | ||
117 | }); | ||
118 | }); | ||
119 | }); | ||