From 795544a14ccd58b99627946fcec9067e7cdf0823 Mon Sep 17 00:00:00 2001 From: Griffithtp Date: Sat, 13 Jul 2019 15:28:25 +0100 Subject: [PATCH] test: add unit test for url utils --- src/utils/url.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/utils/url.test.ts diff --git a/src/utils/url.test.ts b/src/utils/url.test.ts new file mode 100644 index 0000000..33b99b1 --- /dev/null +++ b/src/utils/url.test.ts @@ -0,0 +1,27 @@ +import { isURL, isEmail, getRegistryURL } from './url'; + +describe('url', () => { + 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'); + }); +});