mirror of
https://github.com/nasa/openmct.git
synced 2025-05-29 21:54:20 +00:00
[Mobile] Update spec for AgentService
This commit is contained in:
parent
88bb213162
commit
5a1c83fca8
@ -21,49 +21,66 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||||
|
|
||||||
/**
|
|
||||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
|
||||||
*/
|
|
||||||
define(
|
define(
|
||||||
["../../src/services/AgentService"],
|
["../src/AgentService"],
|
||||||
function (AgentService) {
|
function (AgentService) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The url service", function () {
|
var TEST_USER_AGENTS = {
|
||||||
var agentService,
|
DESKTOP: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36",
|
||||||
mockWindow,
|
IPHONE: "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53",
|
||||||
mockNavigator;
|
IPAD: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53"
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("The AgentService", function () {
|
||||||
|
var testWindow, agentService;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// Creates a mockLocation, used to
|
testWindow = {
|
||||||
// do the view search
|
innerWidth: 640,
|
||||||
mockWindow = jasmine.createSpyObj(
|
innerHeight: 480,
|
||||||
"window",
|
navigator: {
|
||||||
[ "innerWidth", "innerHeight" ]
|
userAgent: TEST_USER_AGENTS.DESKTOP
|
||||||
);
|
}
|
||||||
|
};
|
||||||
mockNavigator = jasmine.createSpyObj(
|
|
||||||
"navigator",
|
|
||||||
[ "userAgent" ]
|
|
||||||
);
|
|
||||||
|
|
||||||
agentService = new AgentService();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("get current device user agent", function () {
|
it("recognizes desktop devices as non-mobile", function () {
|
||||||
mockNavigator.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36";
|
testWindow.navigator.userAgent = TEST_USER_AGENTS.DESKTOP;
|
||||||
agentService.isMobile(mockNavigator.userAgent);
|
agentService = new AgentService(testWindow);
|
||||||
agentService.isPhone(mockNavigator.userAgent);
|
expect(agentService.isMobile()).toBeFalsy();
|
||||||
mockNavigator.userAgent = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53";
|
expect(agentService.isPhone()).toBeFalsy();
|
||||||
agentService.isMobile(mockNavigator.userAgent);
|
expect(agentService.isTablet()).toBeFalsy();
|
||||||
mockNavigator.userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53";
|
|
||||||
agentService.isPhone(mockNavigator.userAgent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("get orientation of the current device", function () {
|
it("detects iPhones", function () {
|
||||||
agentService.getOrientation(1024, 768);
|
testWindow.navigator.userAgent = TEST_USER_AGENTS.IPHONE;
|
||||||
agentService.getOrientation(768, 1024);
|
agentService = new AgentService(testWindow);
|
||||||
|
expect(agentService.isMobile()).toBeTruthy();
|
||||||
|
expect(agentService.isPhone()).toBeTruthy();
|
||||||
|
expect(agentService.isTablet()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("detects iPads", function () {
|
||||||
|
testWindow.navigator.userAgent = TEST_USER_AGENTS.IPAD;
|
||||||
|
agentService = new AgentService(testWindow);
|
||||||
|
expect(agentService.isMobile()).toBeTruthy();
|
||||||
|
expect(agentService.isPhone()).toBeFalsy();
|
||||||
|
expect(agentService.isTablet()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("detects display orientation", function () {
|
||||||
|
var agentService = new AgentService(testWindow);
|
||||||
|
testWindow.innerWidth = 1024;
|
||||||
|
testWindow.innerHeight = 400;
|
||||||
|
expect(agentService.isPortrait()).toBeFalsy();
|
||||||
|
expect(agentService.isLandscape()).toBeTruthy();
|
||||||
|
testWindow.innerWidth = 400;
|
||||||
|
testWindow.innerHeight = 1024;
|
||||||
|
expect(agentService.isPortrait()).toBeTruthy();
|
||||||
|
expect(agentService.isLandscape()).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user