add unit test to addProtocol
This commit is contained in:
parent
dbef194fff
commit
67811bb36b
|
@ -0,0 +1,20 @@
|
|||
import addProtocol from './addProtocol';
|
||||
|
||||
describe('Add the protocol https at the begin of the URL', () => {
|
||||
it('return the link as original when sent with https at the begin', () => {
|
||||
const linkHttps = 'https://www.google.com';
|
||||
expect(addProtocol(linkHttps)).toBe(linkHttps);
|
||||
});
|
||||
it('return the link as original when sent with http at the begin', () => {
|
||||
const linkHttp = 'http://www.google.com';
|
||||
expect(addProtocol(linkHttp)).toBe(linkHttp);
|
||||
});
|
||||
it("return a new link with protocol at the begin when there isn't the protocol at the begin", () => {
|
||||
const linkWithoutProtocol = 'www.google.com';
|
||||
expect(addProtocol(linkWithoutProtocol)).toBe('https://www.google.com');
|
||||
});
|
||||
it('return the link correctly when the original starts with double slash, because the server is returning that', () => {
|
||||
const linkWithDoubleSlashAtBegin = '//www.google.com';
|
||||
expect(addProtocol(linkWithDoubleSlashAtBegin)).toBe('https://www.google.com');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,8 @@
|
|||
const addProtocol = (url: string): string => {
|
||||
if (!url.toLowerCase().startsWith('http')) {
|
||||
return `https://${url.replace('//', '')}`;
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
export default addProtocol;
|
|
@ -5,6 +5,7 @@ import parse from 'url-parse';
|
|||
import { themes } from '../../constants';
|
||||
import { TSupportedThemes } from '../../../theme';
|
||||
import UserPreferences from '../userPreferences';
|
||||
import addProtocol from './addProtocol';
|
||||
|
||||
export const DEFAULT_BROWSER_KEY = 'DEFAULT_BROWSER_KEY';
|
||||
|
||||
|
@ -36,13 +37,6 @@ const appSchemeURL = (url: string, browser: string): string => {
|
|||
return schemeUrl;
|
||||
};
|
||||
|
||||
const addProtocol = (url: string): string => {
|
||||
if (!url.toLowerCase().startsWith('http')) {
|
||||
return `https://${url.replace('//', '')}`;
|
||||
}
|
||||
return url;
|
||||
};
|
||||
|
||||
const openLink = async (url: string, theme: TSupportedThemes = 'light'): Promise<void> => {
|
||||
url = addProtocol(url);
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue