|
| 1 | +/***************************************************************************** |
| 2 | + * Open MCT Web, Copyright (c) 2014-2015, United States Government |
| 3 | + * as represented by the Administrator of the National Aeronautics and Space |
| 4 | + * Administration. All rights reserved. |
| 5 | + * |
| 6 | + * Open MCT Web is licensed under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0. |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | + * License for the specific language governing permissions and limitations |
| 15 | + * under the License. |
| 16 | + * |
| 17 | + * Open MCT Web includes source code licensed under additional open source |
| 18 | + * licenses. See the Open Source Licenses file (LICENSES.md) included with |
| 19 | + * this source code distribution or the Licensing information page available |
| 20 | + * at runtime from the About dialog for additional information. |
| 21 | + *****************************************************************************/ |
| 22 | + |
| 23 | +define( |
| 24 | + ["../src/InspectorPaneController"], |
| 25 | + function (InspectorPaneController) { |
| 26 | + |
| 27 | + describe("The InspectorPaneController", function () { |
| 28 | + var mockScope, |
| 29 | + mockAgentService, |
| 30 | + mockDomainObject, |
| 31 | + mockWindow, |
| 32 | + mockStatusCapability, |
| 33 | + mockNavigationService, |
| 34 | + mockNavigationUnlistener, |
| 35 | + mockStatusUnlistener, |
| 36 | + controller; |
| 37 | + |
| 38 | + beforeEach(function () { |
| 39 | + mockScope = jasmine.createSpyObj("$scope", ["$on"]); |
| 40 | + mockWindow = jasmine.createSpyObj("$window", ["open"]); |
| 41 | + mockAgentService = jasmine.createSpyObj( |
| 42 | + "agentService", |
| 43 | + ["isMobile", "isPhone", "isTablet", "isPortrait", "isLandscape"] |
| 44 | + ); |
| 45 | + |
| 46 | + mockNavigationUnlistener = jasmine.createSpy("navigationUnlistener"); |
| 47 | + mockNavigationService = jasmine.createSpyObj( |
| 48 | + "navigationService", |
| 49 | + ["getNavigation", "addListener"] |
| 50 | + ); |
| 51 | + mockNavigationService.addListener.andReturn(mockNavigationUnlistener); |
| 52 | + |
| 53 | + mockStatusUnlistener = jasmine.createSpy("statusUnlistener"); |
| 54 | + mockStatusCapability = jasmine.createSpyObj( |
| 55 | + "statusCapability", |
| 56 | + ["listen"] |
| 57 | + ); |
| 58 | + mockStatusCapability.listen.andReturn(mockStatusUnlistener); |
| 59 | + |
| 60 | + mockDomainObject = jasmine.createSpyObj( |
| 61 | + 'domainObject', |
| 62 | + [ |
| 63 | + 'getId', |
| 64 | + 'getModel', |
| 65 | + 'getCapability', |
| 66 | + 'hasCapability' |
| 67 | + ] |
| 68 | + ); |
| 69 | + mockDomainObject.getId.andReturn("domainObject"); |
| 70 | + mockDomainObject.getModel.andReturn({}); |
| 71 | + mockDomainObject.hasCapability.andReturn(true); |
| 72 | + mockDomainObject.getCapability.andReturn(mockStatusCapability); |
| 73 | + |
| 74 | + controller = new InspectorPaneController(mockScope, mockAgentService, mockWindow, mockNavigationService); |
| 75 | + }); |
| 76 | + |
| 77 | + it("listens for changes to navigation and attaches a status" + |
| 78 | + " listener", function () { |
| 79 | + expect(mockNavigationService.addListener).toHaveBeenCalledWith(jasmine.any(Function)); |
| 80 | + mockNavigationService.addListener.mostRecentCall.args[0](mockDomainObject); |
| 81 | + expect(mockStatusCapability.listen).toHaveBeenCalledWith(jasmine.any(Function)); |
| 82 | + }); |
| 83 | + |
| 84 | + it("if hidden, shows the inspector when domain object switches to" + |
| 85 | + " edit mode", function () { |
| 86 | + controller.toggle(); |
| 87 | + // test pre-condition that inspector is hidden |
| 88 | + expect(controller.visible()).toBe(false); |
| 89 | + mockNavigationService.addListener.mostRecentCall.args[0](mockDomainObject); |
| 90 | + mockStatusCapability.listen.mostRecentCall.args[0](["editing"]); |
| 91 | + expect(controller.visible()).toBe(true); |
| 92 | + }); |
| 93 | + |
| 94 | + }); |
| 95 | + } |
| 96 | +); |
0 commit comments