1
0
mirror of https://github.com/SomboChea/ui synced 2024-11-24 15:04:27 +07:00

test: add unit test for extractFileName

This commit is contained in:
Juan Picado @jotadeveloper 2019-07-28 16:44:31 +02:00
parent f47ab2490b
commit 12974ea54f
No known key found for this signature in database
GPG Key ID: 15AA875EF3768142

View File

@ -1,27 +1,36 @@
import { isURL, isEmail, getRegistryURL } from './url'; import { isURL, isEmail, getRegistryURL, extractFileName } from './url';
describe('url', () => { describe('utils', () => {
test('isURL() - should return true for localhost', () => { describe('url', () => {
expect(isURL('http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeTruthy(); test('isURL() - should return true for localhost', () => {
expect(isURL('http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeTruthy();
});
test('isURL() - should return false when protocol is missing', () => {
expect(isURL('localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeFalsy();
});
test('isEmail() - should return true if valid', () => {
expect(isEmail('email@domain.com')).toBeTruthy();
});
test('isEmail() - should return false if invalid', () => {
expect(isEmail('')).toBeFalsy();
});
test('getRegistryURL() - should keep slash if location is a sub directory', () => {
history.pushState({}, 'page title', '/-/web/detail');
expect(getRegistryURL()).toBe('http://localhost/-/web/detail');
history.pushState({}, 'page title', '/');
});
test('getRegistryURL() - should not add slash if location is not a sub directory', () => {
expect(getRegistryURL()).toBe('http://localhost');
});
}); });
test('isURL() - should return false when protocol is missing', () => { describe('extractFileName', () => {
expect(isURL('localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeFalsy(); test('should return the file name', () => {
}); expect(extractFileName('http://localhost:4872/juan_test_webpack1/-/test-10.0.0.tgz')).toBe('test-10.0.0.tgz');
});
test('isEmail() - should return true if valid', () => {
expect(isEmail('email@domain.com')).toBeTruthy();
});
test('isEmail() - should return false if invalid', () => {
expect(isEmail('')).toBeFalsy();
});
test('getRegistryURL() - should keep slash if location is a sub directory', () => {
history.pushState({}, 'page title', '/-/web/detail');
expect(getRegistryURL()).toBe('http://localhost/-/web/detail');
history.pushState({}, 'page title', '/');
});
test('getRegistryURL() - should not add slash if location is not a sub directory', () => {
expect(getRegistryURL()).toBe('http://localhost');
}); });
}); });