diff --git a/platform/commonUI/general/test/TreeNodeControllerSpec.js b/platform/commonUI/general/test/TreeNodeControllerSpec.js index 655368a35f..9e6fbf1bb9 100644 --- a/platform/commonUI/general/test/TreeNodeControllerSpec.js +++ b/platform/commonUI/general/test/TreeNodeControllerSpec.js @@ -7,6 +7,7 @@ define( describe("The tree node controller", function () { var mockScope, + mockTimeout, controller; function TestObject(id, context) { @@ -19,13 +20,9 @@ define( } beforeEach(function () { - mockScope = jasmine.createSpyObj( - "$scope", - [ "$watch", "$on" ] - ); - controller = new TreeNodeController( - mockScope - ); + mockScope = jasmine.createSpyObj("$scope", ["$watch", "$on"]); + mockTimeout = jasmine.createSpy("$timeout"); + controller = new TreeNodeController(mockScope, mockTimeout); }); it("allows tracking of expansion state", function () { @@ -34,6 +31,12 @@ define( // portion of the tree. expect(controller.hasBeenExpanded()).toBeFalsy(); controller.trackExpansion(); + + // Expansion is tracked on a timeout, because too + // much expansion can result in an unstable digest. + expect(mockTimeout).toHaveBeenCalled(); + mockTimeout.mostRecentCall.args[0](); + expect(controller.hasBeenExpanded()).toBeTruthy(); controller.trackExpansion(); expect(controller.hasBeenExpanded()).toBeTruthy(); @@ -85,6 +88,12 @@ define( // Invoke the watch with the new selection mockScope.$watch.calls[0].args[1](child); + // Expansion is tracked on a timeout, because too + // much expansion can result in an unstable digest. + // Trigger that timeout. + expect(mockTimeout).toHaveBeenCalled(); + mockTimeout.mostRecentCall.args[0](); + expect(mockScope.toggle.setState).toHaveBeenCalledWith(true); expect(controller.hasBeenExpanded()).toBeTruthy(); expect(controller.isSelected()).toBeFalsy(); diff --git a/platform/representation/test/MCTRepresentationSpec.js b/platform/representation/test/MCTRepresentationSpec.js index 51cadf6594..ee44c626a6 100644 --- a/platform/representation/test/MCTRepresentationSpec.js +++ b/platform/representation/test/MCTRepresentationSpec.js @@ -15,13 +15,13 @@ define( describe("The mct-representation directive", function () { var testRepresentations, testViews, - mockGestureService, - mockGestureHandle, + mockRepresenters, mockQ, mockLog, mockScope, mockElement, mockDomainObject, + testModel, mctRepresentation; function mockPromise(value) { @@ -61,10 +61,17 @@ define( } ]; - mockGestureService = jasmine.createSpyObj("gestureService", [ "attachGestures" ]); - mockGestureHandle = jasmine.createSpyObj("gestureHandle", [ "destroy" ]); + testModel = { someKey: "some value" }; - mockGestureService.attachGestures.andReturn(mockGestureHandle); + mockRepresenters = ["A", "B"].map(function (name) { + var constructor = jasmine.createSpy("Representer" + name), + representer = jasmine.createSpyObj( + "representer" + name, + [ "represent", "destroy" ] + ); + constructor.andReturn(representer); + return constructor; + }); mockQ = { when: mockPromise }; mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS); @@ -73,10 +80,12 @@ define( mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); + mockDomainObject.getModel.andReturn(testModel); + mctRepresentation = new MCTRepresentation( testRepresentations, testViews, - mockGestureService, + mockRepresenters, mockQ, mockLog ); @@ -137,32 +146,6 @@ define( .toHaveBeenCalledWith("otherTestCapability"); }); - it("attaches declared gestures, and detaches on refresh", function () { - mctRepresentation.link(mockScope, mockElement); - - mockScope.key = "uvw"; - mockScope.domainObject = mockDomainObject; - - // Trigger the watch - mockScope.$watch.mostRecentCall.args[1](); - - expect(mockGestureService.attachGestures).toHaveBeenCalledWith( - mockElement, - mockDomainObject, - [ "testGesture", "otherTestGesture" ] - ); - - expect(mockGestureHandle.destroy).not.toHaveBeenCalled(); - - // Refresh, expect a detach - mockScope.key = "abc"; - mockScope.$watch.mostRecentCall.args[1](); - - // Should have destroyed those old gestures - expect(mockGestureHandle.destroy).toHaveBeenCalled(); - }); - - it("logs when no representation is available for a key", function () { mctRepresentation.link(mockScope, mockElement); diff --git a/platform/representation/test/gestures/GestureRepresenterSpec.js b/platform/representation/test/gestures/GestureRepresenterSpec.js index 03fa5d8fdb..ce677c940b 100644 --- a/platform/representation/test/gestures/GestureRepresenterSpec.js +++ b/platform/representation/test/gestures/GestureRepresenterSpec.js @@ -6,6 +6,32 @@ define( "use strict"; describe("A gesture representer", function () { + +// it("attaches declared gestures, and detaches on refresh", function () { +// mctRepresentation.link(mockScope, mockElement); +// +// mockScope.key = "uvw"; +// mockScope.domainObject = mockDomainObject; +// +// // Trigger the watch +// mockScope.$watch.mostRecentCall.args[1](); +// +// expect(mockGestureService.attachGestures).toHaveBeenCalledWith( +// mockElement, +// mockDomainObject, +// [ "testGesture", "otherTestGesture" ] +// ); +// +// expect(mockGestureHandle.destroy).not.toHaveBeenCalled(); +// +// // Refresh, expect a detach +// mockScope.key = "abc"; +// mockScope.$watch.mostRecentCall.args[1](); +// +// // Should have destroyed those old gestures +// expect(mockGestureHandle.destroy).toHaveBeenCalled(); +// }); + }); } ); \ No newline at end of file