From 8c653d39d79fa7948acc05b68f25f5d9dd17d00e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 19 Feb 2015 12:44:00 -0800 Subject: [PATCH] [Edit] Update specs Update specs for toolbars in Edit mode to reflect changes for WTD-879. --- .../representers/EditToolbarRepresenter.js | 2 ++ .../EditToolbarRepresenterSpec.js | 2 +- .../edit/test/representers/EditToolbarSpec.js | 22 ++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js b/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js index 4c983bcd41..8e4958d5df 100644 --- a/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js +++ b/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js @@ -48,6 +48,8 @@ define( state.forEach(function (value, index) { toolbar.updateState(index, value); }); + // Commit the changes. + commit("Changes from toolbar."); } // Represent a domain object using this definition diff --git a/platform/commonUI/edit/test/representers/EditToolbarRepresenterSpec.js b/platform/commonUI/edit/test/representers/EditToolbarRepresenterSpec.js index 134f5c0261..9ca9bb65d4 100644 --- a/platform/commonUI/edit/test/representers/EditToolbarRepresenterSpec.js +++ b/platform/commonUI/edit/test/representers/EditToolbarRepresenterSpec.js @@ -15,7 +15,7 @@ define( beforeEach(function () { mockScope = jasmine.createSpyObj( '$scope', - [ '$on', '$watch', '$watchCollection' ] + [ '$on', '$watch', '$watchCollection', "commit" ] ); mockElement = {}; testAttrs = { toolbar: 'testToolbar' }; diff --git a/platform/commonUI/edit/test/representers/EditToolbarSpec.js b/platform/commonUI/edit/test/representers/EditToolbarSpec.js index de22fe03e4..6f93bf04e8 100644 --- a/platform/commonUI/edit/test/representers/EditToolbarSpec.js +++ b/platform/commonUI/edit/test/representers/EditToolbarSpec.js @@ -11,7 +11,8 @@ define( testABC, testABC2, testABCXYZ, - testABCYZ; + testABCYZ, + testM; beforeEach(function () { testStructure = { @@ -29,6 +30,11 @@ define( { name: "Y", property: "y" }, { name: "Z", property: "z" } ] + }, + { + items: [ + { name: "M", method: "m" } + ] } ] }; @@ -37,6 +43,7 @@ define( testABC2 = { a: 4, b: 1, c: 2 }; // For inconsistent-state checking testABCXYZ = { a: 0, b: 1, c: 2, x: 'X!', y: 'Y!', z: 'Z!' }; testABCYZ = { a: 0, b: 1, c: 2, y: 'Y!', z: 'Z!' }; + testM = { m: jasmine.createSpy("method") }; }); it("provides properties from the original structure", function () { @@ -182,6 +189,19 @@ define( .length ).toEqual(2); }); + + it("adds click functions when a method is specified", function () { + var testCommit = jasmine.createSpy('commit'), + toolbar = new EditToolbar(testStructure, [ testM ], testCommit); + // Verify precondition + expect(testM.m).not.toHaveBeenCalled(); + // Click! + toolbar.getStructure().sections[0].items[0].click(); + // Should have called the underlying function + expect(testM.m).toHaveBeenCalled(); + // Should also have committed the change + expect(testCommit).toHaveBeenCalled(); + }); }); } );