From b1f8a54dab9efc1f17125d372b0b735a855c5d68 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Sat, 6 Dec 2014 09:45:41 -0800 Subject: [PATCH] [Layout] Update specs Update specs to reflect changes made to the manner in which a view may persist view configuration changes, for WTD-535. --- platform/commonUI/edit/src/EditRepresenter.js | 2 +- .../commonUI/edit/test/EditRepresenterSpec.js | 27 +++++-------------- .../layout/test/LayoutControllerSpec.js | 19 +++++++++++++ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/platform/commonUI/edit/src/EditRepresenter.js b/platform/commonUI/edit/src/EditRepresenter.js index d6c988c443..6cf40aadd2 100644 --- a/platform/commonUI/edit/src/EditRepresenter.js +++ b/platform/commonUI/edit/src/EditRepresenter.js @@ -67,7 +67,7 @@ define( // Respond to the destruction of the current representation. function destroy() { - // No op + // Nothing to clean up } // Handle a specific representation of a specific domain object diff --git a/platform/commonUI/edit/test/EditRepresenterSpec.js b/platform/commonUI/edit/test/EditRepresenterSpec.js index 126507461b..85d314fda6 100644 --- a/platform/commonUI/edit/test/EditRepresenterSpec.js +++ b/platform/commonUI/edit/test/EditRepresenterSpec.js @@ -7,6 +7,7 @@ define( describe("The Edit mode representer", function () { var mockQ, + mockLog, mockScope, testRepresentation, mockDomainObject, @@ -23,6 +24,7 @@ define( beforeEach(function () { mockQ = { when: mockPromise }; + mockLog = jasmine.createSpyObj("$log", ["info", "debug"]); mockScope = jasmine.createSpyObj("$scope", ["$watch"]); testRepresentation = { key: "test" }; mockDomainObject = jasmine.createSpyObj("domainObject", [ @@ -35,39 +37,24 @@ define( mockPersistence = jasmine.createSpyObj("persistence", ["persist"]); + mockDomainObject.getModel.andReturn({}); mockDomainObject.hasCapability.andReturn(true); mockDomainObject.useCapability.andReturn(true); mockDomainObject.getCapability.andReturn(mockPersistence); - representer = new EditRepresenter(mockQ, mockScope); + representer = new EditRepresenter(mockQ, mockLog, mockScope); representer.represent(testRepresentation, mockDomainObject); }); - it("watches for changes in view configuration", function () { - // Should watch the configuration field, - // provided by mct-representation - expect(mockScope.$watch).toHaveBeenCalledWith( - "configuration", - jasmine.any(Function), - true // should be a deep watch - ); - }); - - it("watches for changes in domain object model", function () { - // Should watch the model field, - // provided by mct-representation - expect(mockScope.$watch).toHaveBeenCalledWith( - "model", - jasmine.any(Function), - true // should be a deep watch - ); + it("provides a commit method in scope", function () { + expect(mockScope.commit).toEqual(jasmine.any(Function)); }); it("mutates and persists upon observed changes", function () { mockScope.model = { someKey: "some value" }; mockScope.configuration = { someConfiguration: "something" }; - mockScope.$watch.mostRecentCall.args[1].call(); + mockScope.commit("Some message"); // Should have mutated the object... expect(mockDomainObject.useCapability).toHaveBeenCalledWith( diff --git a/platform/features/layout/test/LayoutControllerSpec.js b/platform/features/layout/test/LayoutControllerSpec.js index d99290a3fe..ba21822dec 100644 --- a/platform/features/layout/test/LayoutControllerSpec.js +++ b/platform/features/layout/test/LayoutControllerSpec.js @@ -91,6 +91,25 @@ define( // that a configuration for b has been defined. expect(testConfiguration.panels.b).toBeDefined(); }); + + + it("invokes commit after drag", function () { + // Populate scope + mockScope.$watch.mostRecentCall.args[1](testModel); + + // Add a commit method to scope + mockScope.commit = jasmine.createSpy("commit"); + + // Do a drag + controller.startDrag("b", [1, 1], [0, 0]); + controller.continueDrag([100, 100]); + controller.endDrag(); + + // Should have triggered commit (provided by + // EditRepresenter) with some message. + expect(mockScope.commit) + .toHaveBeenCalledWith(jasmine.any(String)); + }); }); } ); \ No newline at end of file