From db574447385bd78690b1ff6492828f8141bdaa7e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 10 Apr 2015 18:00:13 -0700 Subject: [PATCH] [Containment] Update specs for coverage Update existing specs for code coverage after changes for WTD-962, composition policy. --- .../browse/test/creation/CreateWizardSpec.js | 31 ++++++++++++++++++- .../test/creation/LocatorControllerSpec.js | 27 ++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/platform/commonUI/browse/test/creation/CreateWizardSpec.js b/platform/commonUI/browse/test/creation/CreateWizardSpec.js index fc46f2904b..6b21c5ae72 100644 --- a/platform/commonUI/browse/test/creation/CreateWizardSpec.js +++ b/platform/commonUI/browse/test/creation/CreateWizardSpec.js @@ -12,6 +12,7 @@ define( var mockType, mockParent, mockProperties, + mockPolicyService, testModel, wizard; @@ -46,6 +47,7 @@ define( ] ); mockProperties = [ "A", "B", "C" ].map(createMockProperty); + mockPolicyService = jasmine.createSpyObj('policyService', ['allow']); testModel = { someKey: "some value" }; @@ -58,7 +60,8 @@ define( wizard = new CreateWizard( mockType, - mockParent + mockParent, + mockPolicyService ); }); @@ -104,6 +107,32 @@ define( }); }); + it("validates selection types using policy", function () { + var mockDomainObject = jasmine.createSpyObj( + 'domainObject', + ['getCapability'] + ), + mockOtherType = jasmine.createSpyObj( + 'otherType', + ['getKey'] + ), + structure = wizard.getFormStructure(), + sections = structure.sections, + rows = structure.sections[sections.length - 1].rows, + locationRow = rows[rows.length - 1]; + + mockDomainObject.getCapability.andReturn(mockOtherType); + locationRow.validate(mockDomainObject); + + // Should check policy to see if the user-selected location + // can actually contain objects of this type + expect(mockPolicyService.allow).toHaveBeenCalledWith( + 'composition', + mockOtherType, + mockType + ); + }); + }); } diff --git a/platform/commonUI/browse/test/creation/LocatorControllerSpec.js b/platform/commonUI/browse/test/creation/LocatorControllerSpec.js index 605e98f1dc..a39f899477 100644 --- a/platform/commonUI/browse/test/creation/LocatorControllerSpec.js +++ b/platform/commonUI/browse/test/creation/LocatorControllerSpec.js @@ -68,6 +68,33 @@ define( .toHaveBeenCalledWith("context"); }); + it("rejects changes which fail validation", function () { + mockScope.structure = { validate: jasmine.createSpy('validate') }; + mockScope.structure.validate.andReturn(false); + + // Pass selection change + mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + + expect(mockScope.structure.validate).toHaveBeenCalled(); + // Change should have been rejected + expect(mockScope.ngModel.someField).not.toEqual(mockDomainObject); + }); + + it("treats a lack of a selection as invalid", function () { + mockScope.ngModelController = jasmine.createSpyObj( + 'ngModelController', + [ '$setValidity' ] + ); + + mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + expect(mockScope.ngModelController.$setValidity) + .toHaveBeenCalledWith(jasmine.any(String), true); + + mockScope.$watch.mostRecentCall.args[1](undefined); + expect(mockScope.ngModelController.$setValidity) + .toHaveBeenCalledWith(jasmine.any(String), false); + }); + }); } ); \ No newline at end of file