[Edit] Add test cases

Add test cases for EditController to account for changes to
support warning dialog when unsaved changes are present,
WTD-1035.
This commit is contained in:
Victor Woeltjen 2015-03-31 15:58:13 -07:00
parent dc7d504691
commit 0b0753df31

View File

@ -41,17 +41,17 @@ define(
);
});
it("places the currently-navigated object in scope", function () {
expect(mockScope.navigatedObject).toBeDefined();
expect(mockScope.navigatedObject.getId()).toEqual("test");
it("exposes the currently-navigated object", function () {
expect(controller.navigatedObject()).toBeDefined();
expect(controller.navigatedObject().getId()).toEqual("test");
});
it("adds an editor capability to the navigated object", function () {
// Should provide an editor capability...
expect(mockScope.navigatedObject.getCapability("editor"))
expect(controller.navigatedObject().getCapability("editor"))
.toBeDefined();
// Shouldn't have been the mock capability we provided
expect(mockScope.navigatedObject.getCapability("editor"))
expect(controller.navigatedObject().getCapability("editor"))
.not.toEqual(mockCapability);
});
@ -76,6 +76,23 @@ define(
.toHaveBeenCalledWith(navCallback);
});
it("exposes a warning message for unload", function () {
var obj = controller.navigatedObject(),
mockEditor = jasmine.createSpyObj('editor', ['dirty']);
// Normally, should be undefined
expect(controller.getUnloadWarning()).toBeUndefined();
// Override the object's editor capability, make it look
// like there are unsaved changes.
obj.getCapability = jasmine.createSpy();
obj.getCapability.andReturn(mockEditor);
mockEditor.dirty.andReturn(true);
// Should have some warning message here now
expect(controller.getUnloadWarning()).toEqual(jasmine.any(String));
});
});
}
);