Update tests and correct style
Update tests to reflect new functionality. Closes https://github.com/nasa/openmct/issues/1360
This commit is contained in:
@@ -44,10 +44,6 @@ define(
|
|||||||
* navigation has been updated
|
* navigation has been updated
|
||||||
*/
|
*/
|
||||||
NavigateAction.prototype.perform = function () {
|
NavigateAction.prototype.perform = function () {
|
||||||
var self = this,
|
|
||||||
navigateTo = this.domainObject,
|
|
||||||
currentObject = self.navigationService.getNavigation();
|
|
||||||
|
|
||||||
if (this.navigationService.shouldNavigate()) {
|
if (this.navigationService.shouldNavigate()) {
|
||||||
this.navigationService.setNavigation(this.domainObject, true);
|
this.navigationService.setNavigation(this.domainObject, true);
|
||||||
return Promise.resolve({});
|
return Promise.resolve({});
|
||||||
|
|||||||
@@ -24,8 +24,14 @@
|
|||||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
||||||
*/
|
*/
|
||||||
define(
|
define(
|
||||||
["../src/BrowseController"],
|
[
|
||||||
function (BrowseController) {
|
"../src/BrowseController",
|
||||||
|
"../src/navigation/NavigationService"
|
||||||
|
],
|
||||||
|
function (
|
||||||
|
BrowseController,
|
||||||
|
NavigationService
|
||||||
|
) {
|
||||||
|
|
||||||
describe("The browse controller", function () {
|
describe("The browse controller", function () {
|
||||||
var mockScope,
|
var mockScope,
|
||||||
@@ -44,7 +50,7 @@ define(
|
|||||||
function waitsForNavigation() {
|
function waitsForNavigation() {
|
||||||
var calls = mockNavigationService.setNavigation.calls.length;
|
var calls = mockNavigationService.setNavigation.calls.length;
|
||||||
waitsFor(function () {
|
waitsFor(function () {
|
||||||
return mockNavigationService.setNavigation.calls.length > calls ;
|
return mockNavigationService.setNavigation.calls.length > calls;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,15 +98,16 @@ define(
|
|||||||
"objectService",
|
"objectService",
|
||||||
["getObjects"]
|
["getObjects"]
|
||||||
);
|
);
|
||||||
mockNavigationService = jasmine.createSpyObj(
|
mockNavigationService = new NavigationService({});
|
||||||
"navigationService",
|
[
|
||||||
[
|
"getNavigation",
|
||||||
"getNavigation",
|
"setNavigation",
|
||||||
"setNavigation",
|
"addListener",
|
||||||
"addListener",
|
"removeListener"
|
||||||
"removeListener"
|
].forEach(function (method) {
|
||||||
]
|
spyOn(mockNavigationService, method)
|
||||||
);
|
.andCallThrough();
|
||||||
|
});
|
||||||
mockRootObject = jasmine.createSpyObj(
|
mockRootObject = jasmine.createSpyObj(
|
||||||
"rootObjectContainer",
|
"rootObjectContainer",
|
||||||
["getId", "getCapability", "getModel", "useCapability", "hasCapability"]
|
["getId", "getCapability", "getModel", "useCapability", "hasCapability"]
|
||||||
|
|||||||
@@ -23,145 +23,74 @@
|
|||||||
/**
|
/**
|
||||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
||||||
*/
|
*/
|
||||||
define(
|
define([
|
||||||
["../../src/navigation/NavigateAction"],
|
"../../src/navigation/NavigateAction"
|
||||||
function (NavigateAction) {
|
], function (
|
||||||
|
NavigateAction
|
||||||
|
) {
|
||||||
|
|
||||||
describe("The navigate action", function () {
|
describe("The navigate action", function () {
|
||||||
var mockNavigationService,
|
var mockNavigationService,
|
||||||
mockQ,
|
mockDomainObject,
|
||||||
mockDomainObject,
|
action;
|
||||||
mockPolicyService,
|
|
||||||
mockNavigatedObject,
|
|
||||||
mockWindow,
|
|
||||||
capabilities,
|
|
||||||
action;
|
|
||||||
|
|
||||||
function mockPromise(value) {
|
|
||||||
return {
|
|
||||||
then: function (callback) {
|
|
||||||
return mockPromise(callback(value));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(function () {
|
function waitForCall() {
|
||||||
capabilities = {};
|
var called = false;
|
||||||
|
waitsFor(function () {
|
||||||
mockQ = { when: mockPromise };
|
return called;
|
||||||
mockNavigatedObject = jasmine.createSpyObj(
|
|
||||||
"domainObject",
|
|
||||||
[
|
|
||||||
"getId",
|
|
||||||
"getModel",
|
|
||||||
"hasCapability",
|
|
||||||
"getCapability"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
capabilities.editor = jasmine.createSpyObj("editorCapability", [
|
|
||||||
"isEditContextRoot",
|
|
||||||
"finish"
|
|
||||||
]);
|
|
||||||
|
|
||||||
mockNavigatedObject.getCapability.andCallFake(function (capability) {
|
|
||||||
return capabilities[capability];
|
|
||||||
});
|
|
||||||
mockNavigatedObject.hasCapability.andReturn(false);
|
|
||||||
|
|
||||||
mockNavigationService = jasmine.createSpyObj(
|
|
||||||
"navigationService",
|
|
||||||
[
|
|
||||||
"setNavigation",
|
|
||||||
"getNavigation"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
mockNavigationService.getNavigation.andReturn(mockNavigatedObject);
|
|
||||||
|
|
||||||
mockDomainObject = jasmine.createSpyObj(
|
|
||||||
"domainObject",
|
|
||||||
[
|
|
||||||
"getId",
|
|
||||||
"getModel"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
mockPolicyService = jasmine.createSpyObj("policyService",
|
|
||||||
[
|
|
||||||
"allow"
|
|
||||||
]);
|
|
||||||
mockWindow = jasmine.createSpyObj("$window",
|
|
||||||
[
|
|
||||||
"confirm"
|
|
||||||
]);
|
|
||||||
|
|
||||||
action = new NavigateAction(
|
|
||||||
mockNavigationService,
|
|
||||||
mockQ,
|
|
||||||
mockPolicyService,
|
|
||||||
mockWindow,
|
|
||||||
{ domainObject: mockDomainObject }
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
return function () {
|
||||||
|
called = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
it("invokes the policy service to determine if navigation" +
|
beforeEach(function () {
|
||||||
" allowed", function () {
|
mockNavigationService = jasmine.createSpyObj(
|
||||||
action.perform();
|
"navigationService",
|
||||||
expect(mockPolicyService.allow)
|
[
|
||||||
.toHaveBeenCalledWith("navigation", jasmine.any(Object), jasmine.any(Object), jasmine.any(Function));
|
"shouldNavigate",
|
||||||
});
|
"setNavigation"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
it("prompts user if policy rejection", function () {
|
mockDomainObject = {};
|
||||||
action.perform();
|
|
||||||
expect(mockPolicyService.allow).toHaveBeenCalled();
|
|
||||||
mockPolicyService.allow.mostRecentCall.args[3]();
|
|
||||||
expect(mockWindow.confirm).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("shows a prompt", function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
// Ensure the allow callback is called synchronously
|
|
||||||
mockPolicyService.allow.andCallFake(function () {
|
|
||||||
return arguments[3]();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it("does not navigate on prompt rejection", function () {
|
|
||||||
mockWindow.confirm.andReturn(false);
|
|
||||||
action.perform();
|
|
||||||
expect(mockNavigationService.setNavigation)
|
|
||||||
.not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does navigate on prompt acceptance", function () {
|
|
||||||
mockWindow.confirm.andReturn(true);
|
|
||||||
action.perform();
|
|
||||||
expect(mockNavigationService.setNavigation)
|
|
||||||
.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("in edit mode", function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
mockNavigatedObject.hasCapability.andCallFake(function (capability) {
|
|
||||||
return capability === "editor";
|
|
||||||
});
|
|
||||||
capabilities.editor.isEditContextRoot.andReturn(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("finishes editing if in edit mode", function () {
|
|
||||||
action.perform();
|
|
||||||
expect(capabilities.editor.finish)
|
|
||||||
.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("is only applicable when a domain object is in context", function () {
|
|
||||||
expect(NavigateAction.appliesTo({})).toBeFalsy();
|
|
||||||
expect(NavigateAction.appliesTo({
|
|
||||||
domainObject: mockDomainObject
|
|
||||||
})).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
action = new NavigateAction(
|
||||||
|
mockNavigationService,
|
||||||
|
{ domainObject: mockDomainObject }
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
);
|
it("sets navigation if it is allowed", function () {
|
||||||
|
mockNavigationService.shouldNavigate.andReturn(true);
|
||||||
|
action.perform()
|
||||||
|
.then(waitForCall());
|
||||||
|
runs(function () {
|
||||||
|
expect(mockNavigationService.setNavigation)
|
||||||
|
.toHaveBeenCalledWith(mockDomainObject, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not set navigation if it is not allowed", function () {
|
||||||
|
mockNavigationService.shouldNavigate.andReturn(false);
|
||||||
|
var onSuccess = jasmine.createSpy('onSuccess');
|
||||||
|
action.perform()
|
||||||
|
.then(onSuccess, waitForCall());
|
||||||
|
runs(function () {
|
||||||
|
expect(onSuccess).not.toHaveBeenCalled();
|
||||||
|
expect(mockNavigationService.setNavigation)
|
||||||
|
.not
|
||||||
|
.toHaveBeenCalledWith(mockDomainObject);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is only applicable when a domain object is in context", function () {
|
||||||
|
expect(NavigateAction.appliesTo({})).toBeFalsy();
|
||||||
|
expect(NavigateAction.appliesTo({
|
||||||
|
domainObject: mockDomainObject
|
||||||
|
})).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ define(
|
|||||||
function (NavigationService) {
|
function (NavigationService) {
|
||||||
|
|
||||||
describe("The navigation service", function () {
|
describe("The navigation service", function () {
|
||||||
var navigationService;
|
var $window,
|
||||||
|
navigationService;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
navigationService = new NavigationService();
|
$window = jasmine.createSpyObj('$window', ['confirm']);
|
||||||
|
navigationService = new NavigationService($window);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("stores navigation state", function () {
|
it("stores navigation state", function () {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ define(
|
|||||||
cancelEditing(domainObject);
|
cancelEditing(domainObject);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setViewForDomainObject(domainObject) {
|
function setViewForDomainObject() {
|
||||||
|
|
||||||
var locationViewKey = $location.search().view;
|
var locationViewKey = $location.search().view;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setViewForDomainObject($scope.domainObject);
|
setViewForDomainObject();
|
||||||
|
|
||||||
$scope.doAction = function (action) {
|
$scope.doAction = function (action) {
|
||||||
return $scope[action] && $scope[action]();
|
return $scope[action] && $scope[action]();
|
||||||
|
|||||||
@@ -24,32 +24,19 @@ define(
|
|||||||
["../../src/controllers/EditObjectController"],
|
["../../src/controllers/EditObjectController"],
|
||||||
function (EditObjectController) {
|
function (EditObjectController) {
|
||||||
|
|
||||||
describe("The Edit mode controller", function () {
|
describe("The Edit Object controller", function () {
|
||||||
var mockScope,
|
var mockScope,
|
||||||
mockObject,
|
mockObject,
|
||||||
mockType,
|
testViews,
|
||||||
|
mockEditorCapability,
|
||||||
mockLocation,
|
mockLocation,
|
||||||
|
mockNavigationService,
|
||||||
|
removeCheck,
|
||||||
mockStatusCapability,
|
mockStatusCapability,
|
||||||
mockCapabilities,
|
mockCapabilities,
|
||||||
mockPolicyService,
|
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
// Utility function; look for a $watch on scope and fire it
|
|
||||||
function fireWatch(expr, value) {
|
|
||||||
mockScope.$watch.calls.forEach(function (call) {
|
|
||||||
if (call.args[0] === expr) {
|
|
||||||
call.args[1](value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockPolicyService = jasmine.createSpyObj(
|
|
||||||
"policyService",
|
|
||||||
[
|
|
||||||
"allow"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
mockScope = jasmine.createSpyObj(
|
mockScope = jasmine.createSpyObj(
|
||||||
"$scope",
|
"$scope",
|
||||||
["$on", "$watch"]
|
["$on", "$watch"]
|
||||||
@@ -58,16 +45,16 @@ define(
|
|||||||
"domainObject",
|
"domainObject",
|
||||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||||
);
|
);
|
||||||
mockType = jasmine.createSpyObj(
|
mockEditorCapability = jasmine.createSpyObj(
|
||||||
"type",
|
"mockEditorCapability",
|
||||||
["hasFeature"]
|
["isEditContextRoot", "dirty", "finish"]
|
||||||
);
|
);
|
||||||
mockStatusCapability = jasmine.createSpyObj('statusCapability',
|
mockStatusCapability = jasmine.createSpyObj('statusCapability',
|
||||||
["get"]
|
["get"]
|
||||||
);
|
);
|
||||||
|
|
||||||
mockCapabilities = {
|
mockCapabilities = {
|
||||||
"type" : mockType,
|
"editor" : mockEditorCapability,
|
||||||
"status": mockStatusCapability
|
"status": mockStatusCapability
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,52 +62,70 @@ define(
|
|||||||
["search"]
|
["search"]
|
||||||
);
|
);
|
||||||
mockLocation.search.andReturn({"view": "fixed"});
|
mockLocation.search.andReturn({"view": "fixed"});
|
||||||
|
mockNavigationService = jasmine.createSpyObj('navigationService',
|
||||||
|
["checkBeforeNavigation"]
|
||||||
|
);
|
||||||
|
|
||||||
|
removeCheck = jasmine.createSpy('removeCheck');
|
||||||
|
mockNavigationService.checkBeforeNavigation.andReturn(removeCheck);
|
||||||
|
|
||||||
mockObject.getId.andReturn("test");
|
mockObject.getId.andReturn("test");
|
||||||
mockObject.getModel.andReturn({ name: "Test object" });
|
mockObject.getModel.andReturn({ name: "Test object" });
|
||||||
mockObject.getCapability.andCallFake(function (key) {
|
mockObject.getCapability.andCallFake(function (key) {
|
||||||
return mockCapabilities[key];
|
return mockCapabilities[key];
|
||||||
});
|
});
|
||||||
mockType.hasFeature.andReturn(true);
|
|
||||||
|
|
||||||
mockScope.domainObject = mockObject;
|
testViews = [
|
||||||
|
{ key: 'abc' },
|
||||||
controller = new EditObjectController(
|
{ key: 'def', someKey: 'some value' },
|
||||||
mockScope,
|
{ key: 'xyz' }
|
||||||
mockLocation,
|
];
|
||||||
mockPolicyService
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("exposes a warning message for unload", function () {
|
|
||||||
var errorMessage = "Unsaved changes";
|
|
||||||
|
|
||||||
// Normally, should be undefined
|
|
||||||
expect(controller.getUnloadWarning()).toBeUndefined();
|
|
||||||
|
|
||||||
// Override the policy service to prevent navigation
|
|
||||||
mockPolicyService.allow.andCallFake(function (category, object, context, callback) {
|
|
||||||
callback(errorMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Should have some warning message here now
|
|
||||||
expect(controller.getUnloadWarning()).toEqual(errorMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it("sets the active view from query parameters", function () {
|
|
||||||
var testViews = [
|
|
||||||
{ key: 'abc' },
|
|
||||||
{ key: 'def', someKey: 'some value' },
|
|
||||||
{ key: 'xyz' }
|
|
||||||
];
|
|
||||||
|
|
||||||
mockObject.useCapability.andCallFake(function (c) {
|
mockObject.useCapability.andCallFake(function (c) {
|
||||||
return (c === 'view') && testViews;
|
return (c === 'view') && testViews;
|
||||||
});
|
});
|
||||||
mockLocation.search.andReturn({ view: 'def' });
|
mockLocation.search.andReturn({ view: 'def' });
|
||||||
|
|
||||||
fireWatch('domainObject', mockObject);
|
mockScope.domainObject = mockObject;
|
||||||
|
|
||||||
|
controller = new EditObjectController(
|
||||||
|
mockScope,
|
||||||
|
mockLocation,
|
||||||
|
mockNavigationService
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds a check before navigation", function () {
|
||||||
|
expect(mockNavigationService.checkBeforeNavigation)
|
||||||
|
.toHaveBeenCalledWith(jasmine.any(Function));
|
||||||
|
|
||||||
|
var checkFn = mockNavigationService.checkBeforeNavigation.mostRecentCall.args[0];
|
||||||
|
|
||||||
|
mockEditorCapability.isEditContextRoot.andReturn(false);
|
||||||
|
mockEditorCapability.dirty.andReturn(false);
|
||||||
|
|
||||||
|
expect(checkFn()).toBe(false);
|
||||||
|
|
||||||
|
mockEditorCapability.isEditContextRoot.andReturn(true);
|
||||||
|
expect(checkFn()).toBe(false);
|
||||||
|
|
||||||
|
mockEditorCapability.dirty.andReturn(true);
|
||||||
|
expect(checkFn())
|
||||||
|
.toBe("Continuing will cause the loss of any unsaved changes.");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("cleans up on destroy", function () {
|
||||||
|
expect(mockScope.$on)
|
||||||
|
.toHaveBeenCalledWith("$destroy", jasmine.any(Function));
|
||||||
|
|
||||||
|
mockScope.$on.mostRecentCall.args[1]();
|
||||||
|
|
||||||
|
expect(mockEditorCapability.finish).toHaveBeenCalled();
|
||||||
|
expect(removeCheck).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("sets the active view from query parameters", function () {
|
||||||
expect(mockScope.representation.selected)
|
expect(mockScope.representation.selected)
|
||||||
.toEqual(testViews[1]);
|
.toEqual(testViews[1]);
|
||||||
});
|
});
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* Open MCT, Copyright (c) 2014-2016, United States Government
|
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
* Administration. All rights reserved.
|
|
||||||
*
|
|
||||||
* Open MCT 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 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.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
define(
|
|
||||||
["../../src/representers/EditRepresenter"],
|
|
||||||
function (EditRepresenter) {
|
|
||||||
|
|
||||||
describe("The Edit mode representer", function () {
|
|
||||||
var mockQ,
|
|
||||||
mockLog,
|
|
||||||
mockScope,
|
|
||||||
testRepresentation,
|
|
||||||
mockDomainObject,
|
|
||||||
mockStatusCapability,
|
|
||||||
mockEditorCapability,
|
|
||||||
mockCapabilities,
|
|
||||||
representer;
|
|
||||||
|
|
||||||
function mockPromise(value) {
|
|
||||||
return {
|
|
||||||
then: function (callback) {
|
|
||||||
return mockPromise(callback(value));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
mockQ = { when: mockPromise };
|
|
||||||
mockLog = jasmine.createSpyObj("$log", ["info", "debug"]);
|
|
||||||
mockScope = jasmine.createSpyObj("$scope", ["$watch", "$on"]);
|
|
||||||
testRepresentation = { key: "test" };
|
|
||||||
mockDomainObject = jasmine.createSpyObj("domainObject", [
|
|
||||||
"getId",
|
|
||||||
"getModel",
|
|
||||||
"getCapability",
|
|
||||||
"useCapability",
|
|
||||||
"hasCapability"
|
|
||||||
]);
|
|
||||||
mockStatusCapability =
|
|
||||||
jasmine.createSpyObj("statusCapability", ["listen"]);
|
|
||||||
mockEditorCapability =
|
|
||||||
jasmine.createSpyObj("editorCapability", ["isEditContextRoot"]);
|
|
||||||
|
|
||||||
mockCapabilities = {
|
|
||||||
'status': mockStatusCapability,
|
|
||||||
'editor': mockEditorCapability
|
|
||||||
};
|
|
||||||
|
|
||||||
mockDomainObject.getModel.andReturn({});
|
|
||||||
mockDomainObject.hasCapability.andReturn(true);
|
|
||||||
mockDomainObject.useCapability.andReturn(true);
|
|
||||||
mockDomainObject.getCapability.andCallFake(function (capability) {
|
|
||||||
return mockCapabilities[capability];
|
|
||||||
});
|
|
||||||
|
|
||||||
representer = new EditRepresenter(mockQ, mockLog, mockScope);
|
|
||||||
representer.represent(testRepresentation, mockDomainObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("provides a commit method in scope", function () {
|
|
||||||
expect(mockScope.commit).toEqual(jasmine.any(Function));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Sets edit view template on edit mode", function () {
|
|
||||||
mockStatusCapability.listen.mostRecentCall.args[0](['editing']);
|
|
||||||
mockEditorCapability.isEditContextRoot.andReturn(true);
|
|
||||||
expect(mockScope.viewObjectTemplate).toEqual('edit-object');
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Cleans up listeners on scope destroy", function () {
|
|
||||||
representer.listenHandle = jasmine.createSpy('listen');
|
|
||||||
mockScope.$on.mostRecentCall.args[1]();
|
|
||||||
expect(representer.listenHandle).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("mutates upon observed changes", function () {
|
|
||||||
mockScope.model = { someKey: "some value" };
|
|
||||||
mockScope.configuration = { someConfiguration: "something" };
|
|
||||||
|
|
||||||
mockScope.commit("Some message");
|
|
||||||
|
|
||||||
// Should have mutated the object...
|
|
||||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith(
|
|
||||||
"mutation",
|
|
||||||
jasmine.any(Function)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Finally, check that the provided mutation function
|
|
||||||
// includes both model and configuration
|
|
||||||
expect(
|
|
||||||
mockDomainObject.useCapability.mostRecentCall.args[1]()
|
|
||||||
).toEqual({
|
|
||||||
someKey: "some value",
|
|
||||||
configuration: {
|
|
||||||
test: { someConfiguration: "something" }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
@@ -29,7 +29,7 @@ define([
|
|||||||
if (!scope.allowSelection) {
|
if (!scope.allowSelection) {
|
||||||
scope.allowSelection = function () {
|
scope.allowSelection = function () {
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
if (!scope.onSelection) {
|
if (!scope.onSelection) {
|
||||||
scope.onSelection = function () {};
|
scope.onSelection = function () {};
|
||||||
|
|||||||
@@ -19,10 +19,12 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
/* global console*/
|
||||||
|
|
||||||
define([
|
define([
|
||||||
'../../src/directives/MCTTree'
|
'../../src/directives/MCTTree',
|
||||||
], function (MCTTree) {
|
'../../src/ui/TreeView'
|
||||||
|
], function (MCTTree, TreeView) {
|
||||||
describe("The mct-tree directive", function () {
|
describe("The mct-tree directive", function () {
|
||||||
var mockParse,
|
var mockParse,
|
||||||
mockGestureService,
|
mockGestureService,
|
||||||
@@ -50,6 +52,7 @@ define([
|
|||||||
mockExpr = jasmine.createSpy('expr');
|
mockExpr = jasmine.createSpy('expr');
|
||||||
mockExpr.assign = jasmine.createSpy('assign');
|
mockExpr.assign = jasmine.createSpy('assign');
|
||||||
mockParse.andReturn(mockExpr);
|
mockParse.andReturn(mockExpr);
|
||||||
|
spyOn(TreeView.prototype, 'observe').andCallThrough();
|
||||||
|
|
||||||
mctTree = new MCTTree(mockParse, mockGestureService);
|
mctTree = new MCTTree(mockParse, mockGestureService);
|
||||||
});
|
});
|
||||||
@@ -58,8 +61,13 @@ define([
|
|||||||
expect(mctTree.restrict).toEqual("E");
|
expect(mctTree.restrict).toEqual("E");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("two-way binds to mctObject and mctModel", function () {
|
it("two-way binds", function () {
|
||||||
expect(mctTree.scope).toEqual({ mctObject: "=", mctModel: "=" });
|
expect(mctTree.scope).toEqual({
|
||||||
|
rootObject: "=",
|
||||||
|
selectedObject: "=",
|
||||||
|
allowSelection: "=?",
|
||||||
|
onSelection: "=?"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("link", function () {
|
describe("link", function () {
|
||||||
@@ -81,16 +89,16 @@ define([
|
|||||||
expect(mockElement.append).toHaveBeenCalled();
|
expect(mockElement.append).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("watches for mct-model's expression in the parent", function () {
|
it("watches for selected-object expression in the parent", function () {
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
"mctModel",
|
"selectedObject",
|
||||||
jasmine.any(Function)
|
jasmine.any(Function)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("watches for changes to mct-object", function () {
|
it("watches for changes to root-object", function () {
|
||||||
expect(mockScope.$watch).toHaveBeenCalledWith(
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
"mctObject",
|
"rootObject",
|
||||||
jasmine.any(Function)
|
jasmine.any(Function)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -102,6 +110,10 @@ define([
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("watches for changes in tree view", function () {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// https://github.com/nasa/openmct/issues/1114
|
// https://github.com/nasa/openmct/issues/1114
|
||||||
it("does not trigger $apply during $watches", function () {
|
it("does not trigger $apply during $watches", function () {
|
||||||
mockScope.mctObject = makeMockDomainObject('root');
|
mockScope.mctObject = makeMockDomainObject('root');
|
||||||
@@ -111,14 +123,18 @@ define([
|
|||||||
});
|
});
|
||||||
expect(mockScope.$apply).not.toHaveBeenCalled();
|
expect(mockScope.$apply).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it("does trigger $apply from other value changes", function () {
|
it("does trigger $apply from tree manipulation", function () {
|
||||||
|
if (/PhantomJS/g.test(window.navigator.userAgent)) {
|
||||||
|
console.log('Unable to run test in PhantomJS due to lack of support for event constructors');
|
||||||
|
return;
|
||||||
|
}
|
||||||
// White-boxy; we know this is the setter for the tree's value
|
// White-boxy; we know this is the setter for the tree's value
|
||||||
var treeValueFn = mockScope.$watch.calls[0].args[1];
|
var treeValueFn = TreeView.prototype.observe.calls[0].args[0];
|
||||||
|
|
||||||
mockScope.mctObject = makeMockDomainObject('root');
|
mockScope.mctObject = makeMockDomainObject('root');
|
||||||
mockScope.mctMode = makeMockDomainObject('selection');
|
mockScope.mctMode = makeMockDomainObject('selection');
|
||||||
|
|
||||||
treeValueFn(makeMockDomainObject('other'));
|
treeValueFn(makeMockDomainObject('other'), new MouseEvent("click"));
|
||||||
|
|
||||||
expect(mockScope.$apply).toHaveBeenCalled();
|
expect(mockScope.$apply).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -289,8 +289,9 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("notifies listeners when value is changed", function () {
|
it("notifies listeners when value is changed", function () {
|
||||||
treeView.value(mockDomainObject);
|
treeView.value(mockDomainObject, {some: event});
|
||||||
expect(mockCallback).toHaveBeenCalledWith(mockDomainObject);
|
expect(mockCallback)
|
||||||
|
.toHaveBeenCalledWith(mockDomainObject, {some: event});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not notify listeners when deactivated", function () {
|
it("does not notify listeners when deactivated", function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user