From e1797b2008c2a15101cc9227f4fe69e7cde9a008 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sun, 3 Sep 2017 14:56:08 +0200 Subject: [PATCH] Fix SelectionManagerTest by using a clipboard event mock --- src/js/selection/SelectionManager.js | 2 +- test/js/selection/SelectionManagerTest.js | 29 ++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/js/selection/SelectionManager.js b/src/js/selection/SelectionManager.js index 1bb224b3..8a7fdc23 100644 --- a/src/js/selection/SelectionManager.js +++ b/src/js/selection/SelectionManager.js @@ -103,7 +103,7 @@ } }; - ns.SelectionManager.prototype.paste = function() { + ns.SelectionManager.prototype.paste = function(event) { var items = event.clipboardData.items; try { diff --git a/test/js/selection/SelectionManagerTest.js b/test/js/selection/SelectionManagerTest.js index 88cb5dbc..61dec309 100644 --- a/test/js/selection/SelectionManagerTest.js +++ b/test/js/selection/SelectionManagerTest.js @@ -29,6 +29,19 @@ describe("SelectionManager suite", function() { } }; + /** + * @Mock + */ + var createMockCopyEvent = function () { + return { + clipboardData: { + items: [], + setData: function () {} + }, + preventDefault: function () {} + }; + }; + beforeEach(function() { currentFrame = pskl.model.Frame.fromPixelGrid([ [B, R, T], @@ -52,7 +65,7 @@ describe("SelectionManager suite", function() { selectMiddleLine(); console.log('[SelectionManager] ... copy'); - selectionManager.copy(); + selectionManager.copy(createMockCopyEvent()); console.log('[SelectionManager] ... check selection content after copy contains correct colors'); expect(selection.pixels.length).toBe(3); // or not to be ... lalalala ... french-only joke \o/ @@ -69,7 +82,7 @@ describe("SelectionManager suite", function() { checkContainsPixel(selection.pixels, 2, 2, R); console.log('[SelectionManager] ... paste'); - selectionManager.paste(); + selectionManager.paste(createMockCopyEvent()); console.log('[SelectionManager] ... check last line is identical to middle line after paste'); frameEqualsGrid(currentFrame, [ @@ -87,7 +100,7 @@ describe("SelectionManager suite", function() { selectMiddleLine(); console.log('[SelectionManager] ... cut'); - selectionManager.cut(); + selectionManager.cut(createMockCopyEvent()); console.log('[SelectionManager] ... check middle line was cut in the source frame'); frameEqualsGrid(currentFrame, [ @@ -97,7 +110,7 @@ describe("SelectionManager suite", function() { ]); console.log('[SelectionManager] ... paste'); - selectionManager.paste(); + selectionManager.paste(createMockCopyEvent()); console.log('[SelectionManager] ... check middle line was restored by paste'); frameEqualsGrid(currentFrame, [ @@ -118,7 +131,7 @@ describe("SelectionManager suite", function() { selection.move(2, 0); console.log('[SelectionManager] ... copy out of bounds'); - selectionManager.copy(); + selectionManager.copy(createMockCopyEvent()); console.log('[SelectionManager] ... check out of bound pixels were replaced by transparent pixels'); checkContainsPixel(selection.pixels, 1, 2, R); checkContainsPixel(selection.pixels, 1, 3, T); @@ -133,7 +146,7 @@ describe("SelectionManager suite", function() { checkContainsPixel(selection.pixels, 1, 3, T); console.log('[SelectionManager] ... paste out of bounds'); - selectionManager.paste(); + selectionManager.paste(createMockCopyEvent()); console.log('[SelectionManager] ... check pixel at (1,1) is red after paste'); frameEqualsGrid(currentFrame, [ @@ -154,7 +167,7 @@ describe("SelectionManager suite", function() { selection.move(2, 0); console.log('[SelectionManager] ... cut out of bounds'); - selectionManager.cut(); + selectionManager.cut(createMockCopyEvent()); console.log('[SelectionManager] ... check last pixel of midle line was cut in the source frame'); frameEqualsGrid(currentFrame, [ [B, R, T], @@ -165,7 +178,7 @@ describe("SelectionManager suite", function() { selection.move(-1, 0); console.log('[SelectionManager] ... paste out of bounds'); - selectionManager.paste(); + selectionManager.paste(createMockCopyEvent()); console.log('[SelectionManager] ... check middle line final state'); frameEqualsGrid(currentFrame, [