From 6b65ae77e7d1e980977d2ad110ca55f197234c6f Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Tue, 4 Aug 2015 16:48:41 -0700 Subject: [PATCH] [Mobile] Tests Completed tests for AgentService, InfoService, and ContextMenuAction. ContextMenu and InfoButton Gesture tests remain. Also resized info button icon. --- platform/commonUI/general/res/css/items.css | 2 +- .../general/res/sass/mobile/_item.scss | 2 +- .../general/test/services/AgentServiceSpec.js | 3 + .../test/gestures/InfoButtonGestureSpec.js | 102 ++++++++++++++++++ .../inspect/test/services/InfoServiceSpec.js | 17 ++- platform/commonUI/inspect/test/suite.json | 1 + .../test/actions/ContextMenuActionSpec.js | 29 +++-- .../test/gestures/ContextMenuGestureSpec.js | 9 +- 8 files changed, 147 insertions(+), 18 deletions(-) create mode 100644 platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js diff --git a/platform/commonUI/general/res/css/items.css b/platform/commonUI/general/res/css/items.css index 3e650d8156..d669127598 100644 --- a/platform/commonUI/general/res/css/items.css +++ b/platform/commonUI/general/res/css/items.css @@ -378,7 +378,7 @@ width: 50px; right: 0px; left: auto; - font-size: 1.5em; } + font-size: 1.3em; } /* line 47, ../sass/mobile/_item.scss */ .items-holder .item.grid-item .bar.bottom-bar.abs { top: 0px; diff --git a/platform/commonUI/general/res/sass/mobile/_item.scss b/platform/commonUI/general/res/sass/mobile/_item.scss index 8ce7576f1e..4db43b885b 100644 --- a/platform/commonUI/general/res/sass/mobile/_item.scss +++ b/platform/commonUI/general/res/sass/mobile/_item.scss @@ -41,7 +41,7 @@ width: 50px; right: 0px; left: auto; - font-size: 1.5em; + font-size: 1.3em; } .bar { &.bottom-bar.abs { diff --git a/platform/commonUI/general/test/services/AgentServiceSpec.js b/platform/commonUI/general/test/services/AgentServiceSpec.js index 6207267da2..e0f689ddfc 100644 --- a/platform/commonUI/general/test/services/AgentServiceSpec.js +++ b/platform/commonUI/general/test/services/AgentServiceSpec.js @@ -53,8 +53,11 @@ define( it("get current device user agent", 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"; agentService.isMobile(mockNavigator.userAgent); + agentService.isPhone(mockNavigator.userAgent); 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"; agentService.isMobile(mockNavigator.userAgent); + 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 () { diff --git a/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js b/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js new file mode 100644 index 0000000000..7ccff88343 --- /dev/null +++ b/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js @@ -0,0 +1,102 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/ + +define( + ['../../src/gestures/InfoButtonGesture'], + function (InfoButtonGesture) { + "use strict"; + + describe("The info button gesture", function () { + var mockDocument, + mockAgentService, + mockInfoService, + testDelay = 12321, + mockElement, + mockDomainObject, + mockScope, + mockOff, + testMetadata, + mockPromise, + mockHide, + gesture; + + beforeEach(function () { + mockDocument = jasmine.createSpyObj('$document', ['find']); + mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']); + mockInfoService = jasmine.createSpyObj( + 'infoService', + [ 'display' ] + ); + mockElement = jasmine.createSpyObj( + 'element', + [ 'on', 'off', 'scope', 'css' ] + ); + mockDomainObject = jasmine.createSpyObj( + 'domainObject', + [ 'getId', 'getCapability', 'useCapability', 'getModel' ] + ); + mockDocument = jasmine.createSpyObj('$document', ['find']); + mockAgentService = jasmine.createSpyObj('agentService', ['isMobile']); + mockInfoService = jasmine.createSpyObj( + 'infoService', + [ 'display' ] + ); + mockElement = jasmine.createSpyObj( + 'element', + [ 'on', 'off', 'scope', 'css' ] + ); + mockDomainObject = jasmine.createSpyObj( + 'domainObject', + [ 'getId', 'getCapability', 'useCapability', 'getModel' ] + ); + + mockScope = jasmine.createSpyObj('$scope', [ '$on' ]); + mockOff = jasmine.createSpy('$off'); + testMetadata = [ { name: "Test name", value: "Test value" } ]; + mockHide = jasmine.createSpy('hide'); + + mockDomainObject.getModel.andReturn({ name: "Test Object" }); + mockDomainObject.useCapability.andCallFake(function (c) { + return (c === 'metadata') ? testMetadata : undefined; + }); + mockElement.scope.andReturn(mockScope); + mockScope.$on.andReturn(mockOff); + mockInfoService.display.andReturn(mockHide); + mockAgentService.isMobile.andReturn(true); + gesture = new InfoButtonGesture( + mockDocument, + mockAgentService, + mockInfoService, + mockElement, + mockDomainObject + ); + }); + + it("listens for click on the representation", function () { + expect(mockElement.on) + .toHaveBeenCalledWith('click', jasmine.any(Function)); + }); + + }); + } +); diff --git a/platform/commonUI/inspect/test/services/InfoServiceSpec.js b/platform/commonUI/inspect/test/services/InfoServiceSpec.js index 858427fe84..58adbbec51 100644 --- a/platform/commonUI/inspect/test/services/InfoServiceSpec.js +++ b/platform/commonUI/inspect/test/services/InfoServiceSpec.js @@ -31,6 +31,7 @@ define( mockDocument, testWindow, mockRootScope, + mockAgentService, mockCompiledTemplate, testScope, mockBody, @@ -42,6 +43,7 @@ define( mockDocument = jasmine.createSpyObj('$document', ['find']); testWindow = { innerWidth: 1000, innerHeight: 100 }; mockRootScope = jasmine.createSpyObj('$rootScope', ['$new']); + mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']); mockCompiledTemplate = jasmine.createSpy('template'); testScope = {}; mockBody = jasmine.createSpyObj('body', ['append']); @@ -58,7 +60,8 @@ define( mockCompile, mockDocument, testWindow, - mockRootScope + mockRootScope, + mockAgentService ); }); @@ -124,6 +127,18 @@ define( (40 + InfoConstants.BUBBLE_OFFSET[1]) + 'px' ); }); + + it("when on phone device, positioning is always on bottom", function () { + mockAgentService.isPhone.andReturn(true); + service = new InfoService( + mockCompile, + mockDocument, + testWindow, + mockRootScope, + mockAgentService + ); + service.display('', '', {}, [0, 0]); + }); }); }); diff --git a/platform/commonUI/inspect/test/suite.json b/platform/commonUI/inspect/test/suite.json index 82650e2dff..ca006fdaa7 100644 --- a/platform/commonUI/inspect/test/suite.json +++ b/platform/commonUI/inspect/test/suite.json @@ -1,4 +1,5 @@ [ "gestures/InfoGesture", + "gestures/InfoButtonGesture", "services/InfoService" ] diff --git a/platform/representation/test/actions/ContextMenuActionSpec.js b/platform/representation/test/actions/ContextMenuActionSpec.js index 01ea265f02..9f6c94b910 100644 --- a/platform/representation/test/actions/ContextMenuActionSpec.js +++ b/platform/representation/test/actions/ContextMenuActionSpec.js @@ -53,6 +53,14 @@ define( mockStopPropagation, action; + function fireEvent(evt, value) { + mockElement.on.calls.forEach(function (call) { + if (call.args[0] === evt) { + call.args[1](value); + } + }); + } + beforeEach(function () { mockCompile = jasmine.createSpy("$compile"); mockCompiledTemplate = jasmine.createSpy("template"); @@ -144,13 +152,12 @@ define( it("keeps a menu when menu is clicked", function () { // Show the menu action.perform(); - // Find and fire body's mousedown listener -// mockMenu.on.calls.forEach(function (call) { -// if (call.args[0] === 'mousedown') { -// call.args[1](); -// } -// }); + mockMenu.on.calls.forEach(function (call) { + if (call.args[0] === 'mousedown') { + call.args[1](mockEvent); + } + }); // Menu should have been removed expect(mockMenu.remove).not.toHaveBeenCalled(); @@ -171,11 +178,11 @@ define( ); action.perform(); -// mockMenu.on.calls.forEach(function (call) { -// if (call.args[0] === 'touchstart') { -// call.args[1](); -// } -// }); + mockMenu.on.calls.forEach(function (call) { + if (call.args[0] === 'touchstart') { + call.args[1](mockEvent); + } + }); }); }); } diff --git a/platform/representation/test/gestures/ContextMenuGestureSpec.js b/platform/representation/test/gestures/ContextMenuGestureSpec.js index 031fdfc9e2..8d6b685762 100644 --- a/platform/representation/test/gestures/ContextMenuGestureSpec.js +++ b/platform/representation/test/gestures/ContextMenuGestureSpec.js @@ -82,10 +82,11 @@ define( // Capture the contextmenu callback fireGesture = mockElement.on.mostRecentCall.args[1]; - expect(mockElement.on).toHaveBeenCalledWith( - "touchstart", - jasmine.any(Function) - ); + mockMenu.on.calls.forEach(function (call) { + if (call.args[0] === 'touchstart') { + call.args[1](mockEvent); + } + }); }); }); }