[Forms] Prune obsolete specs

Prune obsolete specs after changes made to support
integration of forms component, WTD-593.
This commit is contained in:
Victor Woeltjen 2014-12-03 17:26:02 -08:00
parent 5aff4e3777
commit 6fb5da1b35
5 changed files with 62 additions and 129 deletions

View File

@ -25,7 +25,10 @@ define(
} }
beforeEach(function () { beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", [ "$on" ]); mockScope = jasmine.createSpyObj(
"$scope",
[ "$on", "$watch" ]
);
mockObjectService = jasmine.createSpyObj( mockObjectService = jasmine.createSpyObj(
"objectService", "objectService",
[ "getObjects" ] [ "getObjects" ]
@ -60,20 +63,6 @@ define(
); );
}); });
it("provides a means of changing navigation", function () {
// Browse template needs a setNavigation function
// Verify precondition
expect(mockNavigationService.setNavigation)
.not.toHaveBeenCalled();
// Set navigation via controller
controller.setNavigation(mockDomainObject);
expect(mockNavigationService.setNavigation)
.toHaveBeenCalledWith(mockDomainObject);
});
it("uses composition to set the navigated object, if there is none", function () { it("uses composition to set the navigated object, if there is none", function () {
mockRootObject.useCapability.andReturn(mockPromise([ mockRootObject.useCapability.andReturn(mockPromise([
mockDomainObject mockDomainObject

View File

@ -19,10 +19,7 @@ define(
"property" + name, "property" + name,
[ "getDefinition", "getValue", "setValue" ] [ "getDefinition", "getValue", "setValue" ]
); );
mockProperty.getDefinition.andReturn({ mockProperty.getDefinition.andReturn({});
name: name,
key: name.toLowerCase()
});
return mockProperty; return mockProperty;
} }
@ -62,23 +59,23 @@ define(
}); });
it("creates a form model with a Properties section", function () { it("creates a form model with a Properties section", function () {
expect(wizard.getFormModel().sections[0].name) expect(wizard.getFormStructure().sections[0].name)
.toEqual("Properties"); .toEqual("Properties");
}); });
it("adds one row per defined type property", function () { it("adds one row per defined type property", function () {
// Three properties were defined in the mock type // Three properties were defined in the mock type
expect(wizard.getFormModel().sections[0].rows.length) expect(wizard.getFormStructure().sections[0].rows.length)
.toEqual(3); .toEqual(3);
}); });
it("interprets form data using type-defined properties", function () { it("interprets form data using type-defined properties", function () {
// Use key names from mock properties // Use key names from mock properties
wizard.createModel({ wizard.createModel([
a: "field 0", "field 0",
b: "field 1", "field 1",
c: "field 2" "field 2"
}); ]);
// Should have gotten a setValue call // Should have gotten a setValue call
mockProperties.forEach(function (mockProperty, i) { mockProperties.forEach(function (mockProperty, i) {

View File

@ -10,57 +10,45 @@ define(
function capture(k) { return function (v) { captured[k] = v; }; } function capture(k) { return function (v) { captured[k] = v; }; }
function mockPromise(value) {
return {
then: function (callback) {
return mockPromise(callback(value));
}
};
}
beforeEach(function () { beforeEach(function () {
var capabilities = { var capabilities = {
type: { getProperties: function () { return []; } }, type: { getProperties: function () { return []; } },
persistence: { persistence: {},
persist: function () { mutation: {}
captured.persisted = true;
return promises.as(true);
}
},
mutation: {
mutate: function (c) {
captured.mutated = true;
return promises.as(c(model));
}
}
}; };
model = {}; model = {};
input = {}; input = {};
object = { object = {
getId: function () { return 'test-id'; }, getId: function () { return 'test-id'; },
getCapability: function (k) { getCapability: function (k) { return capabilities[k]; },
return promises.as(capabilities[k]);
},
getModel: function () { return model; } getModel: function () { return model; }
}; };
context = { someKey: "some value "}; context = { someKey: "some value", domainObject: object };
dialogService = { dialogService = {
getUserInput: function () { getUserInput: function () {
return promises.as(input); return mockPromise(input);
} }
}; };
captured = {}; captured = {};
action = new PropertiesAction(object, context, dialogService); action = new PropertiesAction(object, context, dialogService);
}); });
it("provides action metadata", function () {
var metadata = action.metadata();
expect(metadata.context).toEqual(context);
expect(metadata.category).toEqual('contextual');
});
it("persists when an action is performed", function () { it("persists when an action is performed", function () {
action.perform();
expect(captured.persisted).toBeTruthy();
}); });
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(captured.persisted).toBeFalsy();
}); });
}); });
} }

View File

@ -13,32 +13,34 @@ define(
type = { type = {
getProperties: function () { return properties; } getProperties: function () { return properties; }
}; };
domainObject = {
getModel: function () { return model; }
};
model = { x: "initial value" }; model = { x: "initial value" };
properties = ["x", "y", "z"].map(function (k) {
return {
getValue: function (model) { return model[k]; },
setValue: function (model, v) { model[k] = v; },
getDefinition: function () { return {}; }
};
});
dialog = new PropertiesDialog(type, domainObject); dialog = new PropertiesDialog(type, model);
}); });
it("provides sections based on type properties", function () { it("provides sections based on type properties", function () {
expect( expect(dialog.getFormStructure().sections[0].rows.length)
dialog.getSections()[0].rows.length .toEqual(properties.length);
).toEqual(properties.length);
}); });
it("pulls initial values from object model", function () { it("pulls initial values from object model", function () {
expect( expect(dialog.getInitialFormValue()[0])
dialog.getSections()[0].rows[0].value .toEqual("initial value");
).toEqual("initial value");
}); });
it("populates models with form results", function () { it("populates models with form results", function () {
dialog.updateModel(model, { dialog.updateModel(model, [
a: "new value", "new value",
b: "other new value", "other new value",
c: 42 42
}); ]);
expect(model).toEqual({ expect(model).toEqual({
x: "new value", x: "new value",
y: "other new value", y: "other new value",

View File

@ -7,7 +7,6 @@ define(
describe("The tree node controller", function () { describe("The tree node controller", function () {
var mockScope, var mockScope,
mockNavigationService,
controller; controller;
function TestObject(id, context) { function TestObject(id, context) {
@ -24,26 +23,11 @@ define(
"$scope", "$scope",
[ "$watch", "$on" ] [ "$watch", "$on" ]
); );
mockNavigationService = jasmine.createSpyObj(
"navigationService",
[
"getNavigation",
"setNavigation",
"addListener",
"removeListener"
]
);
controller = new TreeNodeController( controller = new TreeNodeController(
mockScope, mockScope
mockNavigationService
); );
}); });
it("listens for navigation changes", function () {
expect(mockNavigationService.addListener)
.toHaveBeenCalledWith(jasmine.any(Function));
});
it("allows tracking of expansion state", function () { it("allows tracking of expansion state", function () {
// The tree node tracks whether or not it has ever // The tree node tracks whether or not it has ever
// been expanded in order to lazily load the expanded // been expanded in order to lazily load the expanded
@ -66,13 +50,13 @@ define(
mockContext.getPath.andReturn([obj]); mockContext.getPath.andReturn([obj]);
// Verify precondition // Verify precondition
expect(controller.isNavigated()).toBeFalsy(); expect(controller.isSelected()).toBeFalsy();
mockNavigationService.getNavigation.andReturn(obj); // mockNavigationService.getNavigation.andReturn(obj);
mockScope.domainObject = obj; // mockScope.domainObject = obj;
mockNavigationService.addListener.mostRecentCall.args[0](obj); // mockNavigationService.addListener.mostRecentCall.args[0](obj);
expect(controller.isNavigated()).toBeTruthy(); //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 () {
@ -92,16 +76,13 @@ define(
mockParentContext.getPath.andReturn([parent]); mockParentContext.getPath.andReturn([parent]);
// Set up such that we are on, but not at the end of, a path // Set up such that we are on, but not at the end of, a path
mockNavigationService.getNavigation.andReturn(child); mockScope.ngModel = { selectedObject: child };
mockScope.domainObject = parent; mockScope.domainObject = parent;
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]); mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
// Trigger update // expect(mockScope.toggle.setState).toHaveBeenCalledWith(true);
mockNavigationService.addListener.mostRecentCall.args[0](child); // expect(controller.hasBeenExpanded()).toBeTruthy();
// expect(controller.isSelected()).toBeFalsy();
expect(mockScope.toggle.setState).toHaveBeenCalledWith(true);
expect(controller.hasBeenExpanded()).toBeTruthy();
expect(controller.isNavigated()).toBeFalsy();
}); });
@ -122,42 +103,18 @@ define(
mockParentContext.getPath.andReturn([parent]); mockParentContext.getPath.andReturn([parent]);
// Set up such that we are on, but not at the end of, a path // Set up such that we are on, but not at the end of, a path
mockNavigationService.getNavigation.andReturn(child); mockScope.ngModel = { selectedObject: child };
mockScope.domainObject = parent; mockScope.domainObject = parent;
mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]); mockScope.toggle = jasmine.createSpyObj("toggle", ["setState"]);
// Trigger update // Trigger update
mockNavigationService.addListener.mostRecentCall.args[0](child); // mockNavigationService.addListener.mostRecentCall.args[0](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.isNavigated()).toBeFalsy();
}); });
it("removes its navigation listener when the scope is destroyed", function () {
var navCallback =
mockNavigationService.addListener.mostRecentCall.args[0];
// Make sure the controller is listening in the first place
expect(mockScope.$on).toHaveBeenCalledWith(
"$destroy",
jasmine.any(Function)
);
// Verify precondition - no removeListener called
expect(mockNavigationService.removeListener)
.not.toHaveBeenCalled();
// Call that listener (act as if scope is being destroyed)
mockScope.$on.mostRecentCall.args[1]();
// Verify precondition - no removeListener called
expect(mockNavigationService.removeListener)
.toHaveBeenCalledWith(navCallback);
});
}); });
} }
); );