mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
More tests (#395)
* Test UtilsService.newGuid * Replace UtilsService.extendObject with Object.assign. * Test getBrowser. * Replace var with const.
This commit is contained in:
committed by
Kyle Spearrin
parent
2b042da237
commit
a45f2c2fd7
@@ -1,4 +1,5 @@
|
||||
import UtilsService from './utils.service';
|
||||
import { BrowserType } from '../enums/browserType.enum';
|
||||
|
||||
describe('Utils Service', () => {
|
||||
describe('getDomain', () => {
|
||||
@@ -51,4 +52,62 @@ describe('Utils Service', () => {
|
||||
expect(UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('newGuid', () => {
|
||||
it('should create a valid guid', () => {
|
||||
const validGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
expect(UtilsService.newGuid()).toMatch(validGuid);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBrowser', () => {
|
||||
const original = navigator.userAgent;
|
||||
|
||||
// Reset the userAgent.
|
||||
afterAll(() => {
|
||||
Object.defineProperty(navigator, 'userAgent', {
|
||||
value: original
|
||||
});
|
||||
});
|
||||
|
||||
it('should detect chrome', () => {
|
||||
Object.defineProperty(navigator, 'userAgent', {
|
||||
configurable: true,
|
||||
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'
|
||||
});
|
||||
|
||||
const utilsService = new UtilsService();
|
||||
expect(utilsService.getBrowser()).toBe(BrowserType.Chrome);
|
||||
});
|
||||
|
||||
it('should detect firefox', () => {
|
||||
Object.defineProperty(navigator, 'userAgent', {
|
||||
configurable: true,
|
||||
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0'
|
||||
});
|
||||
|
||||
const utilsService = new UtilsService();
|
||||
expect(utilsService.getBrowser()).toBe(BrowserType.Firefox);
|
||||
});
|
||||
|
||||
it('should detect opera', () => {
|
||||
Object.defineProperty(navigator, 'userAgent', {
|
||||
configurable: true,
|
||||
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3175.3 Safari/537.36 OPR/49.0.2695.0 (Edition developer)'
|
||||
});
|
||||
|
||||
const utilsService = new UtilsService();
|
||||
expect(utilsService.getBrowser()).toBe(BrowserType.Opera);
|
||||
});
|
||||
|
||||
it('should detect edge', () => {
|
||||
Object.defineProperty(navigator, 'userAgent', {
|
||||
configurable: true,
|
||||
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063'
|
||||
});
|
||||
|
||||
const utilsService = new UtilsService();
|
||||
expect(utilsService.getBrowser()).toBe(BrowserType.Edge);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user