|
1 |
| -import { isURL, isEmail, getRegistryURL } from './url'; |
| 1 | +import { isURL, isEmail, getRegistryURL, extractFileName } from './url'; |
2 | 2 |
|
3 |
| -describe('url', () => { |
4 |
| - test('isURL() - should return true for localhost', () => { |
5 |
| - expect(isURL('http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeTruthy(); |
6 |
| - }); |
| 3 | +describe('utils', () => { |
| 4 | + describe('url', () => { |
| 5 | + test('isURL() - should return true for localhost', () => { |
| 6 | + expect(isURL('http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeTruthy(); |
| 7 | + }); |
7 | 8 |
|
8 |
| - test('isURL() - should return false when protocol is missing', () => { |
9 |
| - expect(isURL('localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeFalsy(); |
10 |
| - }); |
| 9 | + test('isURL() - should return false when protocol is missing', () => { |
| 10 | + expect(isURL('localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeFalsy(); |
| 11 | + }); |
11 | 12 |
|
12 |
| - test('isEmail() - should return true if valid', () => { |
13 |
| - expect(isEmail('[email protected]')).toBeTruthy(); |
14 |
| - }); |
15 |
| - test('isEmail() - should return false if invalid', () => { |
16 |
| - expect(isEmail('')).toBeFalsy(); |
17 |
| - }); |
| 13 | + test('isEmail() - should return true if valid', () => { |
| 14 | + expect(isEmail('[email protected]')).toBeTruthy(); |
| 15 | + }); |
| 16 | + test('isEmail() - should return false if invalid', () => { |
| 17 | + expect(isEmail('')).toBeFalsy(); |
| 18 | + }); |
| 19 | + |
| 20 | + test('getRegistryURL() - should keep slash if location is a sub directory', () => { |
| 21 | + history.pushState({}, 'page title', '/-/web/detail'); |
| 22 | + expect(getRegistryURL()).toBe('http://localhost/-/web/detail'); |
| 23 | + history.pushState({}, 'page title', '/'); |
| 24 | + }); |
18 | 25 |
|
19 |
| - test('getRegistryURL() - should keep slash if location is a sub directory', () => { |
20 |
| - history.pushState({}, 'page title', '/-/web/detail'); |
21 |
| - expect(getRegistryURL()).toBe('http://localhost/-/web/detail'); |
22 |
| - history.pushState({}, 'page title', '/'); |
| 26 | + test('getRegistryURL() - should not add slash if location is not a sub directory', () => { |
| 27 | + expect(getRegistryURL()).toBe('http://localhost'); |
| 28 | + }); |
23 | 29 | });
|
24 |
| - test('getRegistryURL() - should not add slash if location is not a sub directory', () => { |
25 |
| - expect(getRegistryURL()).toBe('http://localhost'); |
| 30 | + |
| 31 | + describe('extractFileName', () => { |
| 32 | + test('should return the file name', () => { |
| 33 | + expect(extractFileName('http://localhost:4872/juan_test_webpack1/-/test-10.0.0.tgz')).toBe('test-10.0.0.tgz'); |
| 34 | + }); |
26 | 35 | });
|
27 | 36 | });
|
0 commit comments