2017-04-09 14:13:00 +00:00
|
|
|
import test from 'ava';
|
2017-04-09 19:36:03 +00:00
|
|
|
import sinon from 'sinon';
|
2017-04-09 14:13:00 +00:00
|
|
|
import Parser from '../../src/parser';
|
|
|
|
|
|
|
|
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36 OPR/43.0.2442.1165';
|
|
|
|
const parser = new Parser(UA);
|
|
|
|
|
|
|
|
test('constructor', t => {
|
|
|
|
t.truthy(parser instanceof Parser);
|
|
|
|
});
|
|
|
|
|
2017-08-19 16:55:31 +00:00
|
|
|
test('Parser.getUA returns a correct UA', t => {
|
2017-04-09 14:13:00 +00:00
|
|
|
t.is(parser.getUA(), UA);
|
|
|
|
});
|
|
|
|
|
2017-08-19 16:55:31 +00:00
|
|
|
test('Parser.test', t => {
|
2017-04-09 14:13:00 +00:00
|
|
|
t.truthy(parser.test(/Chrome/i));
|
|
|
|
});
|
2017-04-09 19:09:47 +00:00
|
|
|
|
2017-08-19 16:55:31 +00:00
|
|
|
test('Parser._parseBrowser is being called when the Parser.getBrowser() is called', t => {
|
2017-04-09 19:36:03 +00:00
|
|
|
const spy = sinon.spy(parser, '_parseBrowser');
|
|
|
|
const b = parser.getBrowser();
|
|
|
|
t.truthy(spy.called);
|
2017-04-09 19:09:47 +00:00
|
|
|
t.is(b.name, 'Opera');
|
2017-04-09 19:30:19 +00:00
|
|
|
t.is(b.version, '43.0.2442.1165');
|
2017-04-09 19:46:23 +00:00
|
|
|
parser._parseBrowser.restore();
|
|
|
|
});
|
|
|
|
|
2017-08-19 16:55:31 +00:00
|
|
|
test('Parser.getBrowserName returns a correct result', t => {
|
2017-04-09 19:46:23 +00:00
|
|
|
t.is(parser.getBrowserName(), 'Opera');
|
|
|
|
});
|
|
|
|
|
2017-08-19 16:55:31 +00:00
|
|
|
test('Parser.getBrowserVersion returns a correct result', t => {
|
2017-04-09 19:46:23 +00:00
|
|
|
t.is(parser.getBrowserVersion(), '43.0.2442.1165');
|
2017-04-09 19:09:47 +00:00
|
|
|
});
|
2017-04-15 19:46:18 +00:00
|
|
|
|
2017-08-19 16:55:31 +00:00
|
|
|
test('Parser._parseOS is being called when getOS() called', t => {
|
2017-04-15 19:46:18 +00:00
|
|
|
const spy = sinon.spy(parser, '_parseOS');
|
|
|
|
parser.getOS();
|
|
|
|
t.truthy(spy.called);
|
|
|
|
parser._parseOS.restore();
|
|
|
|
});
|
|
|
|
|
2017-08-19 16:55:31 +00:00
|
|
|
test('Parser.getOSName gives a name of the browser', t => {
|
2017-04-15 19:46:18 +00:00
|
|
|
t.is(parser.getOSName(), 'macOS');
|
|
|
|
});
|
|
|
|
|
2017-08-19 16:55:31 +00:00
|
|
|
test('Parser.getOSName gives a lower-cased name of the browser', t => {
|
|
|
|
t.is(parser.getOSName(true), 'macos');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Parser.getOSVersion returns a correct result', t => {
|
2017-04-15 19:46:18 +00:00
|
|
|
t.is(parser.getOSVersion(), '10.12.4');
|
|
|
|
});
|