Add a test for issue #8

This commit is contained in:
Faisal Salman 2013-01-25 20:23:43 +07:00
parent 249dcf0c80
commit 59714adea3
4 changed files with 51 additions and 17 deletions

View File

@ -1,7 +1,7 @@
{ {
"title": "UA-Parser.JS", "title": "UA-Parser.JS",
"name": "ua-parser-js", "name": "ua-parser-js",
"version": "0.5.0", "version": "0.5.1",
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)", "author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
"description": "Lightweight JavaScript-based user-agent string parser", "description": "Lightweight JavaScript-based user-agent string parser",
"keywords": [ "keywords": [

40
test.js
View File

@ -1238,6 +1238,17 @@ var os = [
version : '' version : ''
} }
}]; }];
var devices = [
{
desc : 'HTC Evo Shift 4G',
ua : 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0',
expect :
{
vendor : 'HTC',
model : 'Evo Shift 4G',
type : 'mobile'
}
}];
describe('getBrowser', function () { describe('getBrowser', function () {
@ -1311,3 +1322,32 @@ describe('getOS', function () {
} }
} }
}); });
describe('getDevice', function () {
for (var i in devices) {
if (devices[i].ua) {
describe('[' + devices[i].desc + ']', function () {
describe('"' + devices[i].ua + '"', function () {
var expect = devices[i].expect;
var result = parser.setUA(devices[i].ua).getDevice();
it('should return device vendor: ' + expect.vendor, function () {
assert.equal(result.vendor, expect.vendor);
});
it('should return device model: ' + expect.model, function () {
assert.equal(result.model, expect.model);
});
it('should return device type: ' + expect.type, function () {
assert.equal(result.type, expect.type);
});
});
});
}
}
});

View File

@ -1,4 +1,4 @@
// UA-Parser.JS v0.5.0 // UA-Parser.JS v0.5.1
// Lightweight JavaScript-based User-Agent string parser // Lightweight JavaScript-based User-Agent string parser
// https://github.com/faisalman/ua-parser-js // https://github.com/faisalman/ua-parser-js
// //
@ -97,11 +97,9 @@
}; };
var maps = { var maps = {
browser : {
oldsafari : { browser : {
oldsafari : {
major : { major : {
'1' : ['/85', '/125', '/312'], '1' : ['/85', '/125', '/312'],
'2' : ['/412', '/416', '/417', '/419'], '2' : ['/412', '/416', '/417', '/419'],
@ -120,20 +118,16 @@
} }
}, },
device : { device : {
htc : {
htc : {
model : { model : {
'Evo Shift 4G' : '7373KT' 'Evo Shift 4G' : '7373KT'
} }
} }
}, },
os : { os : {
windows : {
windows : {
version : { version : {
'ME' : '4.90', 'ME' : '4.90',
'NT 3.11' : 'NT3.51', 'NT 3.11' : 'NT3.51',
@ -251,7 +245,7 @@
], [VENDOR, MODEL, [TYPE, CONSOLE]], [ ], [VENDOR, MODEL, [TYPE, CONSOLE]], [
/(sprint\sapa)(\w+)/i /(sprint\sapa)(\w+)/i
], [[VENDOR, 'HTC'], [MODEL, maps.device.htc.model], [TYPE, MOBILE]], [ ], [[VENDOR, 'HTC'], [MODEL, mapper.string, maps.device.htc.model], [TYPE, MOBILE]], [
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC /(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
/(zte)-(\w+)*/i // ZTE /(zte)-(\w+)*/i // ZTE

4
ua-parser.min.js vendored

File diff suppressed because one or more lines are too long