Skip to content

Commit

Permalink
Unit test of different useragent
Browse files Browse the repository at this point in the history
  • Loading branch information
patw0929 committed May 11, 2017
1 parent 863b424 commit ffb304a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
46 changes: 44 additions & 2 deletions src/components/__tests__/SmartBanner.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable import/first, react/no-find-dom-node, no-eval */
/* eslint-disable import/first, max-len, no-restricted-properties */
jest.mock('cookie-cutter', () => {
return {
set: jest.fn(),
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('SmartBanner', function () { // eslint-disable-line func-names
expect(subject.length).toBeTruthy();
});

describe('snapshots', () => {
describe('type snapshots', () => {
it('should be matched the snapshot (no type)', () => {
const subject = this.makeSubject();

Expand Down Expand Up @@ -153,4 +153,46 @@ describe('SmartBanner', function () { // eslint-disable-line func-names

expect(subject.state('type')).toBe('ios');
});

describe('userAgent', () => {
it('should change type to "ios" if we set iOS user agent', () => {
window.navigator.__defineGetter__('userAgent', () => {
return 'OperaMobile/12.02 (iPad; CPU OS 9_0 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 Mobile Safari/537.36';
});

const subject = this.makeSubject();

expect(subject.state('type')).toBe('ios');
});

it('should change type to "android" if we set android user agent', () => {
window.navigator.__defineGetter__('userAgent', () => {
return 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19';
});

const subject = this.makeSubject();

expect(subject.state('type')).toBe('android');
});

it('should change type to "windows" if we set windows phone user agent', () => {
window.navigator.__defineGetter__('userAgent', () => {
return 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 810)';
});

const subject = this.makeSubject();

expect(subject.state('type')).toBe('windows');
});

it('should change type to "kindle" if we set kindle user agent', () => {
window.navigator.__defineGetter__('userAgent', () => {
return 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true';
});

const subject = this.makeSubject();

expect(subject.state('type')).toBe('kindle');
});
});
});
10 changes: 5 additions & 5 deletions src/components/__tests__/__snapshots__/SmartBanner.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
exports[`SmartBanner snapshots should be matched the snapshot (android) 1`] = `
exports[`SmartBanner type snapshots should be matched the snapshot (android) 1`] = `
"<div class=\"smartbanner smartbanner-android\"><div class=\"smartbanner-container\"><a class=\"smartbanner-close\">×</a><span class=\"smartbanner-icon\" style=\"background-image: url(undefined);\"></span><div class=\"smartbanner-info\"><div class=\"smartbanner-title\"></div><div class=\"smartbanner-author\"></div><div class=\"smartbanner-description\">
Free - In Google Play</div></div><div class=\"smartbanner-wrapper\"><a href=\"http://play.google.com/store/apps/details?id=com.facebook.katana\" class=\"smartbanner-button\"><span class=\"smartbanner-button-text\">View</span></a></div></div></div>"
`;
exports[`SmartBanner snapshots should be matched the snapshot (ios) 1`] = `
exports[`SmartBanner type snapshots should be matched the snapshot (ios) 1`] = `
"<div class=\"smartbanner smartbanner-ios\"><div class=\"smartbanner-container\"><a class=\"smartbanner-close\">×</a><span class=\"smartbanner-icon\" style=\"background-image: url(undefined);\"></span><div class=\"smartbanner-info\"><div class=\"smartbanner-title\"></div><div class=\"smartbanner-author\"></div><div class=\"smartbanner-description\">
Free - On the App Store</div></div><div class=\"smartbanner-wrapper\"><a href=\"https://itunes.apple.com/US/app/id284882215\" class=\"smartbanner-button\"><span class=\"smartbanner-button-text\">View</span></a></div></div></div>"
`;
exports[`SmartBanner snapshots should be matched the snapshot (kindle) 1`] = `
exports[`SmartBanner type snapshots should be matched the snapshot (kindle) 1`] = `
"<div class=\"smartbanner smartbanner-kindle\"><div class=\"smartbanner-container\"><a class=\"smartbanner-close\">×</a><span class=\"smartbanner-icon\" style=\"background-image: url(undefined);\"></span><div class=\"smartbanner-info\"><div class=\"smartbanner-title\"></div><div class=\"smartbanner-author\"></div><div class=\"smartbanner-description\">
Free - In the Amazon Appstore</div></div><div class=\"smartbanner-wrapper\"><a href=\"amzn://apps/android?asin=B0094BB4TW\" class=\"smartbanner-button\"><span class=\"smartbanner-button-text\">View</span></a></div></div></div>"
`;
exports[`SmartBanner snapshots should be matched the snapshot (no type) 1`] = `"<div></div>"`;
exports[`SmartBanner type snapshots should be matched the snapshot (no type) 1`] = `"<div></div>"`;
exports[`SmartBanner snapshots should be matched the snapshot (windows) 1`] = `
exports[`SmartBanner type snapshots should be matched the snapshot (windows) 1`] = `
"<div class=\"smartbanner smartbanner-windows\"><div class=\"smartbanner-container\"><a class=\"smartbanner-close\">×</a><span class=\"smartbanner-icon\" style=\"background-image: url(undefined);\"></span><div class=\"smartbanner-info\"><div class=\"smartbanner-title\"></div><div class=\"smartbanner-author\"></div><div class=\"smartbanner-description\">
Free - In Windows Store</div></div><div class=\"smartbanner-wrapper\"><a href=\"http://www.windowsphone.com/s?appid=82a23635-5bd9-df11-a844-00237de2db9e\" class=\"smartbanner-button\"><span class=\"smartbanner-button-text\">View</span></a></div></div></div>"
`;

0 comments on commit ffb304a

Please sign in to comment.