diff --git a/platform/commonUI/edit/test/policies/EditActionPolicySpec.js b/platform/commonUI/edit/test/policies/EditActionPolicySpec.js index 79b7d585c8..1a2be2bad1 100644 --- a/platform/commonUI/edit/test/policies/EditActionPolicySpec.js +++ b/platform/commonUI/edit/test/policies/EditActionPolicySpec.js @@ -6,24 +6,72 @@ define( "use strict"; describe("The Edit action policy", function () { - it("allows the edit action when there are editable views", function () { + var editableView, + nonEditableView, + undefinedView, + testViews, + testContext, + mockDomainObject, + mockEditAction, + mockPropertiesAction, + policy; + beforeEach(function () { + mockDomainObject = jasmine.createSpyObj( + 'domainObject', + [ 'useCapability' ] + ); + mockEditAction = jasmine.createSpyObj('edit', ['getMetadata']); + mockPropertiesAction = jasmine.createSpyObj('edit', ['getMetadata']); + + editableView = { editable: true }; + nonEditableView = { editable: false }; + undefinedView = { someKey: "some value" }; + testViews = []; + + mockDomainObject.useCapability.andCallFake(function (c) { + // Provide test views, only for the view capability + return c === 'view' && testViews; + }); + + mockEditAction.getMetadata.andReturn({ key: 'edit' }); + mockPropertiesAction.getMetadata.andReturn({ key: 'properties' }); + + testContext = { + domainObject: mockDomainObject, + category: 'view-control' + }; + + policy = new EditActionPolicy(); + }); + + it("allows the edit action when there are editable views", function () { + testViews = [ editableView ]; + expect(policy.allow(mockEditAction, testContext)).toBeTruthy(); + // No edit flag defined; should be treated as editable + testViews = [ undefinedView, undefinedView ]; + expect(policy.allow(mockEditAction, testContext)).toBeTruthy(); }); it("allows the edit properties action when there are no editable views", function () { - + testViews = [ nonEditableView, nonEditableView ]; + expect(policy.allow(mockPropertiesAction, testContext)).toBeTruthy(); }); it("disallows the edit action when there are no editable views", function () { - + testViews = [ nonEditableView, nonEditableView ]; + expect(policy.allow(mockEditAction, testContext)).toBeFalsy(); }); it("disallows the edit properties action when there are editable views", function () { - + testViews = [ editableView ]; + expect(policy.allow(mockPropertiesAction, testContext)).toBeFalsy(); }); it("allows the edit properties outside of the 'view-control' category", function () { - + testViews = [ nonEditableView ]; + testContext.category = "something-else"; + expect(policy.allow(mockPropertiesAction, testContext)).toBeTruthy(); }); }); } diff --git a/platform/commonUI/edit/test/policies/EditableViewPolicySpec.js b/platform/commonUI/edit/test/policies/EditableViewPolicySpec.js index 0883f7636a..b4a4730125 100644 --- a/platform/commonUI/edit/test/policies/EditableViewPolicySpec.js +++ b/platform/commonUI/edit/test/policies/EditableViewPolicySpec.js @@ -6,14 +6,50 @@ define( "use strict"; describe("The editable view policy", function () { + var testView, + mockDomainObject, + testMode, + policy; + + beforeEach(function () { + testMode = true; // Act as if we're in Edit mode by default + mockDomainObject = jasmine.createSpyObj( + 'domainObject', + ['hasCapability'] + ); + mockDomainObject.hasCapability.andCallFake(function (c) { + return (c === 'editor') && testMode; + }); + + policy = new EditableViewPolicy(); + }); + it("disallows views in edit mode that are flagged as non-editable", function () { - + expect(policy.allow({ editable: false }, mockDomainObject)) + .toBeFalsy(); }); + + it("allows views in edit mode that are flagged as editable", function () { + expect(policy.allow({ editable: true }, mockDomainObject)) + .toBeTruthy(); + }); + it("allows any view outside of edit mode", function () { + var testViews = [ + { editable: false }, + { editable: true }, + { someKey: "some value" } + ]; + testMode = false; // Act as if we're not in Edit mode + testViews.forEach(function (testView) { + expect(policy.allow(testView, mockDomainObject)).toBeTruthy(); + }); }); - it("treats views with no defined 'editable' property as editable", function () { + it("treats views with no defined 'editable' property as editable", function () { + expect(policy.allow({ someKey: "some value" }, mockDomainObject)) + .toBeTruthy(); }); }); }