forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl-generator.test.ts
More file actions
47 lines (42 loc) · 1.21 KB
/
url-generator.test.ts
File metadata and controls
47 lines (42 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { gitHubRepoPattern, gitHubToSandboxUrl } from './url-generator';
const invalidUrls = [
'github.com/',
'github.com/user/',
'http://github.com/',
'http://github.com/user/',
'http://www.github.com/',
'http://www.github.com/user/',
'https://github.com/user/',
'https://www.github.com/user/',
'www.github.com/',
'www.github.com/user/',
];
const validUrls = [
'github.com/user/repo',
'http://github.com/user/repo',
'http://www.github.com/user/repo',
'https://github.com/user/repo',
'https://www.github.com/user/repo',
'www.github.com/user/repo',
];
describe('url-generator', () => {
describe('gitHubToSandboxUrl', () => {
validUrls.forEach(inputUrl => {
test(`handles ${inputUrl} urls`, () => {
expect(gitHubToSandboxUrl(inputUrl)).toBe('/s/github/user/repo');
});
});
});
describe('gitHubRepoPattern', () => {
validUrls.forEach(inputUrl => {
test(`validates ${inputUrl} as truthy`, () => {
expect(gitHubRepoPattern.test(inputUrl)).toBeTruthy();
});
});
invalidUrls.forEach(inputUrl => {
test(`validates ${inputUrl} as falsy`, () => {
expect(gitHubRepoPattern.test(inputUrl)).toBeFalsy();
});
});
});
});