mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 14:07:50 +00:00
[Forms] Complete specs
Fill in new specs and amend existing specs to ensure full coverage after integration of forms component, and associated changes. WTD-593.
This commit is contained in:
parent
6fb5da1b35
commit
ba14aeabc6
@ -12,6 +12,7 @@ define(
|
|||||||
var mockType,
|
var mockType,
|
||||||
mockParent,
|
mockParent,
|
||||||
mockProperties,
|
mockProperties,
|
||||||
|
testModel,
|
||||||
wizard;
|
wizard;
|
||||||
|
|
||||||
function createMockProperty(name) {
|
function createMockProperty(name) {
|
||||||
@ -20,6 +21,7 @@ define(
|
|||||||
[ "getDefinition", "getValue", "setValue" ]
|
[ "getDefinition", "getValue", "setValue" ]
|
||||||
);
|
);
|
||||||
mockProperty.getDefinition.andReturn({});
|
mockProperty.getDefinition.andReturn({});
|
||||||
|
mockProperty.getValue.andReturn(name);
|
||||||
return mockProperty;
|
return mockProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,11 +47,13 @@ define(
|
|||||||
);
|
);
|
||||||
mockProperties = [ "A", "B", "C" ].map(createMockProperty);
|
mockProperties = [ "A", "B", "C" ].map(createMockProperty);
|
||||||
|
|
||||||
|
testModel = { someKey: "some value" };
|
||||||
|
|
||||||
mockType.getKey.andReturn("test");
|
mockType.getKey.andReturn("test");
|
||||||
mockType.getGlyph.andReturn("T");
|
mockType.getGlyph.andReturn("T");
|
||||||
mockType.getDescription.andReturn("a test type");
|
mockType.getDescription.andReturn("a test type");
|
||||||
mockType.getName.andReturn("Test");
|
mockType.getName.andReturn("Test");
|
||||||
mockType.getInitialModel.andReturn({});
|
mockType.getInitialModel.andReturn(testModel);
|
||||||
mockType.getProperties.andReturn(mockProperties);
|
mockType.getProperties.andReturn(mockProperties);
|
||||||
|
|
||||||
wizard = new CreateWizard(
|
wizard = new CreateWizard(
|
||||||
@ -80,12 +84,24 @@ define(
|
|||||||
// Should have gotten a setValue call
|
// Should have gotten a setValue call
|
||||||
mockProperties.forEach(function (mockProperty, i) {
|
mockProperties.forEach(function (mockProperty, i) {
|
||||||
expect(mockProperty.setValue).toHaveBeenCalledWith(
|
expect(mockProperty.setValue).toHaveBeenCalledWith(
|
||||||
{ type: 'test' },
|
{ someKey: "some value", type: 'test' },
|
||||||
"field " + i
|
"field " + i
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("looks up initial values from properties", function () {
|
||||||
|
var initialValue = wizard.getInitialFormValue();
|
||||||
|
|
||||||
|
expect(initialValue[0]).toEqual("A");
|
||||||
|
expect(initialValue[1]).toEqual("B");
|
||||||
|
expect(initialValue[2]).toEqual("C");
|
||||||
|
|
||||||
|
// Verify that expected argument was passed
|
||||||
|
mockProperties.forEach(function (mockProperty) {
|
||||||
|
expect(mockProperty.getValue)
|
||||||
|
.toHaveBeenCalledWith(testModel);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,64 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The locator controller", function () {
|
describe("The locator controller", function () {
|
||||||
|
var mockScope,
|
||||||
|
mockDomainObject,
|
||||||
|
mockRootObject,
|
||||||
|
mockContext,
|
||||||
|
controller;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockScope = jasmine.createSpyObj(
|
||||||
|
"$scope",
|
||||||
|
[ "$watch" ]
|
||||||
|
);
|
||||||
|
mockDomainObject = jasmine.createSpyObj(
|
||||||
|
"domainObject",
|
||||||
|
[ "getCapability" ]
|
||||||
|
);
|
||||||
|
mockRootObject = jasmine.createSpyObj(
|
||||||
|
"rootObject",
|
||||||
|
[ "getCapability" ]
|
||||||
|
);
|
||||||
|
mockContext = jasmine.createSpyObj(
|
||||||
|
"context",
|
||||||
|
[ "getRoot" ]
|
||||||
|
);
|
||||||
|
|
||||||
|
mockDomainObject.getCapability.andReturn(mockContext);
|
||||||
|
mockContext.getRoot.andReturn(mockRootObject);
|
||||||
|
|
||||||
|
mockScope.ngModel = {};
|
||||||
|
mockScope.field = "someField";
|
||||||
|
|
||||||
|
controller = new LocatorController(mockScope);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds a treeModel to scope", function () {
|
||||||
|
expect(mockScope.treeModel).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("watches for changes to treeModel", function () {
|
||||||
|
// This is what the embedded tree representation
|
||||||
|
// will be modifying.
|
||||||
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
|
"treeModel.selectedObject",
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("changes its own model on embedded model updates", function () {
|
||||||
|
// Need to pass on selection changes as updates to
|
||||||
|
// the control's value
|
||||||
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
||||||
|
expect(mockScope.ngModel.someField).toEqual(mockDomainObject);
|
||||||
|
expect(mockScope.rootObject).toEqual(mockRootObject);
|
||||||
|
|
||||||
|
// Verify that the capability we expect to have been used
|
||||||
|
// was used.
|
||||||
|
expect(mockDomainObject.getCapability)
|
||||||
|
.toHaveBeenCalledWith("context");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*global define,describe,it,xit,expect,beforeEach*/
|
/*global define,describe,it,xit,expect,beforeEach,jasmine*/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
['../../src/actions/PropertiesAction'],
|
['../../src/actions/PropertiesAction'],
|
||||||
@ -6,9 +6,7 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("Properties action", function () {
|
describe("Properties action", function () {
|
||||||
var captured, model, object, context, input, dialogService, action;
|
var capabilities, model, object, context, input, dialogService, action;
|
||||||
|
|
||||||
function capture(k) { return function (v) { captured[k] = v; }; }
|
|
||||||
|
|
||||||
function mockPromise(value) {
|
function mockPromise(value) {
|
||||||
return {
|
return {
|
||||||
@ -19,17 +17,19 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
var capabilities = {
|
capabilities = {
|
||||||
type: { getProperties: function () { return []; } },
|
type: { getProperties: function () { return []; } },
|
||||||
persistence: {},
|
persistence: jasmine.createSpyObj("persistence", ["persist"]),
|
||||||
mutation: {}
|
mutation: jasmine.createSpy("mutation")
|
||||||
};
|
};
|
||||||
model = {};
|
model = {};
|
||||||
input = {};
|
input = {};
|
||||||
object = {
|
object = {
|
||||||
getId: function () { return 'test-id'; },
|
getId: function () { return 'test-id'; },
|
||||||
getCapability: function (k) { return capabilities[k]; },
|
getCapability: function (k) { return capabilities[k]; },
|
||||||
getModel: function () { return model; }
|
getModel: function () { return model; },
|
||||||
|
useCapability: function (k, v) { return capabilities[k](v); },
|
||||||
|
hasCapability: function () { return true; }
|
||||||
};
|
};
|
||||||
context = { someKey: "some value", domainObject: object };
|
context = { someKey: "some value", domainObject: object };
|
||||||
dialogService = {
|
dialogService = {
|
||||||
@ -37,18 +37,34 @@ define(
|
|||||||
return mockPromise(input);
|
return mockPromise(input);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
captured = {};
|
|
||||||
action = new PropertiesAction(object, context, dialogService);
|
capabilities.mutation.andReturn(true);
|
||||||
|
|
||||||
|
action = new PropertiesAction(dialogService, context);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("persists when an action is performed", function () {
|
it("persists when an action is performed", function () {
|
||||||
|
action.perform();
|
||||||
|
expect(capabilities.persistence.persist)
|
||||||
|
.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not persist any changes upon cancel", function () {
|
it("does not persist any changes upon cancel", function () {
|
||||||
// input = undefined;
|
input = undefined;
|
||||||
// action.perform();
|
action.perform();
|
||||||
// expect(captured.persisted).toBeFalsy();
|
expect(capabilities.persistence.persist)
|
||||||
|
.not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("mutates an object when performed", function () {
|
||||||
|
action.perform();
|
||||||
|
expect(capabilities.mutation).toHaveBeenCalled();
|
||||||
|
capabilities.mutation.mostRecentCall.args[0]({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is only applicable when a domain object is in context", function () {
|
||||||
|
expect(PropertiesAction.appliesTo(context)).toBeTruthy();
|
||||||
|
expect(PropertiesAction.appliesTo({})).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,13 @@ define(
|
|||||||
// Verify precondition
|
// Verify precondition
|
||||||
expect(controller.isSelected()).toBeFalsy();
|
expect(controller.isSelected()).toBeFalsy();
|
||||||
|
|
||||||
// mockNavigationService.getNavigation.andReturn(obj);
|
// Change the represented domain object
|
||||||
// mockScope.domainObject = obj;
|
mockScope.domainObject = obj;
|
||||||
// mockNavigationService.addListener.mostRecentCall.args[0](obj);
|
|
||||||
|
|
||||||
//expect(controller.isSelected()).toBeTruthy();
|
// Invoke the watch with the new selection
|
||||||
|
mockScope.$watch.calls[0].args[1](obj);
|
||||||
|
|
||||||
|
expect(controller.isSelected()).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("expands a node if it is on the navigation path", function () {
|
it("expands a node if it is on the navigation path", function () {
|
||||||
@ -80,9 +82,12 @@ define(
|
|||||||
mockScope.domainObject = parent;
|
mockScope.domainObject = parent;
|
||||||
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
|
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
|
||||||
|
|
||||||
// expect(mockScope.toggle.setState).toHaveBeenCalledWith(true);
|
// Invoke the watch with the new selection
|
||||||
// expect(controller.hasBeenExpanded()).toBeTruthy();
|
mockScope.$watch.calls[0].args[1](child);
|
||||||
// expect(controller.isSelected()).toBeFalsy();
|
|
||||||
|
expect(mockScope.toggle.setState).toHaveBeenCalledWith(true);
|
||||||
|
expect(controller.hasBeenExpanded()).toBeTruthy();
|
||||||
|
expect(controller.isSelected()).toBeFalsy();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -107,12 +112,12 @@ define(
|
|||||||
mockScope.domainObject = parent;
|
mockScope.domainObject = parent;
|
||||||
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
|
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
|
||||||
|
|
||||||
// Trigger update
|
// Invoke the watch with the new selection
|
||||||
// mockNavigationService.addListener.mostRecentCall.args[0](child);
|
mockScope.$watch.calls[0].args[1](child);
|
||||||
//
|
|
||||||
// expect(mockScope.toggle.setState).not.toHaveBeenCalled();
|
expect(mockScope.toggle.setState).not.toHaveBeenCalled();
|
||||||
// expect(controller.hasBeenExpanded()).toBeFalsy();
|
expect(controller.hasBeenExpanded()).toBeFalsy();
|
||||||
// expect(controller.isNavigated()).toBeFalsy();
|
expect(controller.isSelected()).toBeFalsy();
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -75,6 +75,32 @@ define(
|
|||||||
expect(property.getValue(model)).toBeUndefined();
|
expect(property.getValue(model)).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("provides empty arrays for values that are array-like", function () {
|
||||||
|
var definition = {
|
||||||
|
property: "someProperty",
|
||||||
|
items: [ {}, {}, {} ]
|
||||||
|
},
|
||||||
|
model = {},
|
||||||
|
property = new TypeProperty(definition);
|
||||||
|
expect(property.getValue(model))
|
||||||
|
.toEqual([undefined, undefined, undefined]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("detects and ignores empty arrays on setValue", function () {
|
||||||
|
var definition = {
|
||||||
|
property: "someProperty",
|
||||||
|
items: [ {}, {}, {} ]
|
||||||
|
},
|
||||||
|
model = {},
|
||||||
|
property = new TypeProperty(definition);
|
||||||
|
|
||||||
|
property.setValue(model, [undefined, undefined, undefined]);
|
||||||
|
expect(model.someProperty).toBeUndefined();
|
||||||
|
|
||||||
|
// Verify that this only happens when all are undefined
|
||||||
|
property.setValue(model, [undefined, "x", 42]);
|
||||||
|
expect(model.someProperty).toEqual([undefined, "x", 42]);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user