diff options
author | Aditya Mangalampalli <aditya.mangalampalli@gmail.com> | 2022-05-12 16:34:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-12 23:34:53 +0000 |
commit | cc3303cbd87b1dbfe4e41ff8acf4df9e3dc0805d (patch) | |
tree | 73fd8c74939bda1ead888d6b6dccbdf68646fabb /src | |
parent | fix: preload script detection in unit tests (diff) | |
download | ferdium-app-cc3303cbd87b1dbfe4e41ff8acf4df9e3dc0805d.tar.gz ferdium-app-cc3303cbd87b1dbfe4e41ff8acf4df9e3dc0805d.tar.zst ferdium-app-cc3303cbd87b1dbfe4e41ff8acf4df9e3dc0805d.zip |
Add Unit Testing for `url-helpers.ts`; Moved all tests into single pattern so they are run as a suite (#112)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/helpers/url-helpers.test.ts | 116 | ||||
-rw-r--r-- | src/themes/index.test.ts | 17 |
2 files changed, 133 insertions, 0 deletions
diff --git a/src/helpers/url-helpers.test.ts b/src/helpers/url-helpers.test.ts new file mode 100644 index 000000000..5ea6fa1a8 --- /dev/null +++ b/src/helpers/url-helpers.test.ts | |||
@@ -0,0 +1,116 @@ | |||
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 | |||
78 | it('handles string starting with https://', () => { | ||
79 | expect(url_helpers.fixUrl('https://some/random/url')).toEqual('https://some/random/url'); | ||
80 | expect(url_helpers.fixUrl('https://some//random//url')).toEqual('https://some/random/url'); | ||
81 | }); | ||
82 | |||
83 | it('handles string starting with file://', () => { | ||
84 | expect(url_helpers.fixUrl('file://some/random/url')).toEqual('file://some/random/url'); | ||
85 | expect(url_helpers.fixUrl('file://some//random//url')).toEqual('file://some/random/url'); | ||
86 | }); | ||
87 | }); | ||
88 | |||
89 | describe('isValidFileUrl', () => { | ||
90 | it('returns false for empty string', () => { | ||
91 | const result = url_helpers.isValidFileUrl(''); | ||
92 | expect(result).toBe(false); | ||
93 | }); | ||
94 | |||
95 | it('returns false for whitespace string', () => { | ||
96 | const result = url_helpers.isValidFileUrl(' '); | ||
97 | expect(result).toBe(false); | ||
98 | }); | ||
99 | |||
100 | it('returns false for random string', () => { | ||
101 | const result = url_helpers.isValidFileUrl('some random string'); | ||
102 | expect(result).toBe(false); | ||
103 | }); | ||
104 | |||
105 | it('returns false for invalid url', () => { | ||
106 | const result = url_helpers.isValidFileUrl('sfile://google'); | ||
107 | expect(result).toBe(false); | ||
108 | }); | ||
109 | |||
110 | it('returns true for valid file url', () => { | ||
111 | const fileName = process.platform === 'win32' ? 'file:///c:\\' : 'file:///'; | ||
112 | const result = url_helpers.isValidFileUrl(fileName); | ||
113 | expect(result).toBe(true); | ||
114 | }); | ||
115 | }); | ||
116 | }); | ||
diff --git a/src/themes/index.test.ts b/src/themes/index.test.ts new file mode 100644 index 000000000..e9f0f391b --- /dev/null +++ b/src/themes/index.test.ts | |||
@@ -0,0 +1,17 @@ | |||
1 | import makeDefaultThemeConfig from './default'; | ||
2 | import makeDarkThemeConfig from './dark'; | ||
3 | import { theme, ThemeType } from '.'; | ||
4 | |||
5 | describe('Load theme', () => { | ||
6 | it('loads default theme', () => { | ||
7 | const { colorBackground } = theme('default' as ThemeType); | ||
8 | expect(colorBackground).toBe( | ||
9 | makeDefaultThemeConfig('default').colorBackground, | ||
10 | ); | ||
11 | }); | ||
12 | |||
13 | it('loads dark theme', () => { | ||
14 | const { colorBackground } = theme('dark' as ThemeType); | ||
15 | expect(colorBackground).toBe(makeDarkThemeConfig('dark').colorBackground); | ||
16 | }); | ||
17 | }); | ||