From 27a8c0c1a5848623ae91e2015a10594c2430639d Mon Sep 17 00:00:00 2001 From: tsmsogn Date: Fri, 19 Dec 2014 11:46:06 +0900 Subject: [PATCH 1/3] Update Transform tests --- test/TransformSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/TransformSpec.js b/test/TransformSpec.js index 43a9911..8c73da0 100644 --- a/test/TransformSpec.js +++ b/test/TransformSpec.js @@ -13,7 +13,7 @@ describe("jsCanvasNinja.Transform", function () { }).toThrow(); }); - describe("::rotate()", function () { + describe("rotate()", function () { it("should rotate central coordinate object base on it's center point", function () { var scaleX = 2; @@ -67,7 +67,7 @@ describe("jsCanvasNinja.Transform", function () { }); - describe("::scale()", function () { + describe("scale()", function () { it("should scale with object's scale when arguments are null", function () { var scaleX = 2; From eca56d468543bca7dc599e29d08b25f53bf5d192 Mon Sep 17 00:00:00 2001 From: tsmsogn Date: Fri, 19 Dec 2014 11:47:03 +0900 Subject: [PATCH 2/3] Update Utility tests --- test/UtilitySpec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/UtilitySpec.js b/test/UtilitySpec.js index 2288a5c..ff62b9e 100644 --- a/test/UtilitySpec.js +++ b/test/UtilitySpec.js @@ -6,7 +6,7 @@ describe("jsCanvasNinja.Utility", function () { }).toThrow(); }); - describe("::isText()", function () { + describe("isText()", function () { it("should return true with object having text property.", function () { expect(jsCanvasNinja.Utility.isText({text: "foo"})).toBeTruthy(); @@ -22,7 +22,7 @@ describe("jsCanvasNinja.Utility", function () { }); - describe("::hasColor()", function () { + describe("hasColor()", function () { it("should return true with object having color property.", function () { expect(jsCanvasNinja.Utility.hasColor({color: "foo"})).toBeTruthy(); @@ -38,7 +38,7 @@ describe("jsCanvasNinja.Utility", function () { }); - describe("::hasHeight()", function () { + describe("hasHeight()", function () { it("should return true with object having valid height.", function () { expect(jsCanvasNinja.Utility.hasHeight({height: 1})).toBeTruthy(); @@ -58,7 +58,7 @@ describe("jsCanvasNinja.Utility", function () { }); - describe("::hasWidth()", function () { + describe("hasWidth()", function () { it("should return true with object having valid width.", function () { expect(jsCanvasNinja.Utility.hasWidth({width: 1})).toBeTruthy(); @@ -78,7 +78,7 @@ describe("jsCanvasNinja.Utility", function () { }); - describe("::isCentralCoordinate()", function () { + describe("isCentralCoordinate()", function () { it("should return true with object having center coordinate type.", function () { expect(jsCanvasNinja.Utility.isCentralCoordinate({_type: 1})).toBeTruthy(); From 8750e7ac0f79f238957e164be8d7c481a81a5fa5 Mon Sep 17 00:00:00 2001 From: tsmsogn Date: Fri, 19 Dec 2014 13:50:38 +0900 Subject: [PATCH 3/3] Add Stage tests insure toDataURL(), canUndo(), undo(), canRedo() and redo() --- test/StageSpec.js | 233 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 232 insertions(+), 1 deletion(-) diff --git a/test/StageSpec.js b/test/StageSpec.js index 332353d..7b02e4f 100644 --- a/test/StageSpec.js +++ b/test/StageSpec.js @@ -1,4 +1,4 @@ -describe("Stage", function () { +describe("jsCanvasNinja.Stage", function () { var stage; beforeEach(function () { @@ -14,4 +14,235 @@ describe("Stage", function () { expect(stage.getMode()).toEqual('insert'); }); + describe("toDataURL()", function () { + + it("should not trigger beforeToDataURL when it's not function.", function () { + pending(); + }); + + it("should trigger beforeToDataURL before Stage_toDataURL().", function () { + var count = 0; + + stage.beforeToDataURL = function () { + count = 1; + } + spyOn(stage, 'Stage_toDataURL').and.callFake(function () { + count = 2; + }); + + spyOn(stage, 'beforeToDataURL').and.callThrough(); + + stage.toDataURL(); + + expect(stage.beforeToDataURL).toHaveBeenCalled(); + expect(count).toBe(2); + }); + + it("should not trigger afterToDataURL when it's not function.", function () { + pending(); + }); + + it("should trigger afterToDataURL after Stage_toDataUR().", function () { + var count = 0; + + stage.afterToDataURL = function () { + count = 1; + } + spyOn(stage, 'Stage_toDataURL').and.callFake(function () { + count = 2; + }); + + spyOn(stage, 'afterToDataURL').and.callThrough(); + + stage.toDataURL(); + + expect(stage.afterToDataURL).toHaveBeenCalled(); + expect(count).toBe(1); + }); + + }); + + describe("update()", function () { + + it("should not trigger _createHistory() when argument is not truth.", function () { + spyOn(stage, '_createHistory'); + stage.update(); + expect(stage._createHistory).not.toHaveBeenCalled(); + }); + + it("should trigger _createHistory() when argument is truth.", function () { + spyOn(stage, '_createHistory'); + stage.update(true); + expect(stage._createHistory).toHaveBeenCalled(); + }); + + it("should trigger _updateFrame(), Stage_update() and _createHistory() with right order.", function () { + var count = 0; + + spyOn(stage, '_updateFrame').and.callFake(function () { + count = 0; + }); + spyOn(stage, 'Stage_update').and.callFake(function () { + count++; + }); + spyOn(stage, '_createHistory').and.callFake(function () { + count *= 2; + }); + + stage.update(true); + + expect(stage._updateFrame.calls.count()).toEqual(1); + expect(stage.Stage_update.calls.count()).toEqual(1); + expect(stage._createHistory.calls.count()).toEqual(1); + expect(count).toEqual(2); + }); + + }); + + describe("canUndo()", function () { + + it("should return false when there are not anything to undo.", function () { + expect(stage.canUndo()).toBeFalsy(); + + stage.update(true); + stage.undo(); + expect(stage.canUndo()).toBeFalsy(); + }); + + it("should return true when there are something to undo.", function () { + stage.update(true); + expect(stage.canUndo()).toBeTruthy(); + }); + + }); + + describe("canRedo()", function () { + + it("should return false when there are not anything to redo.", function () { + expect(stage.canRedo()).toBeFalsy(); + + stage.update(true); + stage.undo(); + stage.redo(); + expect(stage.canRedo()).toBeFalsy(); + }); + + it("should return true when there are something to redo.", function () { + stage.update(true); + stage.undo(); + expect(stage.canRedo()).toBeTruthy(); + }); + + }); + + describe("undo()", function () { + + it("should not trigger onUndo when it's not function.", function () { + pending(); + }); + + it("should trigger onUndo.", function () { + stage.onUndo = function () { + }; + spyOn(stage, 'onUndo'); + + stage.update(true); + stage.undo(); + + expect(stage.onUndo).toHaveBeenCalledWith({canRedo: true, canUndo: false}); + }); + + it("should pop command from 'didCommands', then trigger it's unexecute() and push to 'undidCommands'.", function () { + stage.update(true); + stage.update(true); + + expect(stage.didCommands.length).toEqual(2); + expect(stage.undidCommands.length).toEqual(0); + + var command1 = stage.didCommands[0]; + var command2 = stage.didCommands[1]; + + spyOn(command2, 'unexecute'); + stage.undo(); + + expect(stage.didCommands.length).toEqual(1); + expect(stage.undidCommands.length).toEqual(1); + expect(stage.didCommands[0]).toBe(command1); + expect(stage.undidCommands[0]).toBe(command2); + + expect(command2.unexecute).toHaveBeenCalled(); + }); + + }); + + describe("redo()", function () { + + it("should not trigger onRedo when it's not function.", function () { + pending(); + }); + + it("should trigger onRedo.", function () { + stage.onRedo = function () { + }; + spyOn(stage, 'onRedo'); + + stage.update(true); + stage.undo(); + stage.redo(); + + expect(stage.onRedo).toHaveBeenCalledWith({canRedo: false, canUndo: true}); + }); + + it("should pop command from 'undidCommands', then trigger it's execute() and push to 'didCommands'.", function () { + stage.update(true); + stage.update(true); + stage.undo(); + + expect(stage.didCommands.length).toEqual(1); + expect(stage.undidCommands.length).toEqual(1); + + var command1 = stage.didCommands[0]; + var command2 = stage.undidCommands[0]; + + spyOn(command2, 'execute'); + stage.redo(); + + expect(stage.didCommands.length).toEqual(2); + expect(stage.undidCommands.length).toEqual(0); + expect(stage.didCommands[0]).toBe(command1); + expect(stage.didCommands[1]).toBe(command2); + + expect(command2.execute).toHaveBeenCalled(); + }); + + }); + + describe("undo() and redo()", function () { + + it("should store undidCommand and didCommand appropriately.", function () { + expect(stage.didCommands.length).toEqual(0); + expect(stage.undidCommands.length).toEqual(0); + + stage.update(true); + stage.update(true); + expect(stage.didCommands.length).toEqual(2); + expect(stage.undidCommands.length).toEqual(0); + + stage.undo(); + expect(stage.didCommands.length).toEqual(1); + expect(stage.undidCommands.length).toEqual(1); + + stage.redo(); + expect(stage.didCommands.length).toEqual(2); + expect(stage.undidCommands.length).toEqual(0); + + stage.undo(); + stage.undo(); + stage.update(true); + expect(stage.didCommands.length).toEqual(1); + expect(stage.undidCommands.length).toEqual(0); + }); + + }); + }); \ No newline at end of file