mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Fix SelectionManagerTest by using a clipboard event mock
This commit is contained in:
parent
0a43f6bbec
commit
e1797b2008
@ -103,7 +103,7 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.SelectionManager.prototype.paste = function() {
|
ns.SelectionManager.prototype.paste = function(event) {
|
||||||
var items = event.clipboardData.items;
|
var items = event.clipboardData.items;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -29,6 +29,19 @@ describe("SelectionManager suite", function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Mock
|
||||||
|
*/
|
||||||
|
var createMockCopyEvent = function () {
|
||||||
|
return {
|
||||||
|
clipboardData: {
|
||||||
|
items: [],
|
||||||
|
setData: function () {}
|
||||||
|
},
|
||||||
|
preventDefault: function () {}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
currentFrame = pskl.model.Frame.fromPixelGrid([
|
currentFrame = pskl.model.Frame.fromPixelGrid([
|
||||||
[B, R, T],
|
[B, R, T],
|
||||||
@ -52,7 +65,7 @@ describe("SelectionManager suite", function() {
|
|||||||
selectMiddleLine();
|
selectMiddleLine();
|
||||||
|
|
||||||
console.log('[SelectionManager] ... copy');
|
console.log('[SelectionManager] ... copy');
|
||||||
selectionManager.copy();
|
selectionManager.copy(createMockCopyEvent());
|
||||||
|
|
||||||
console.log('[SelectionManager] ... check selection content after copy contains correct colors');
|
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/
|
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);
|
checkContainsPixel(selection.pixels, 2, 2, R);
|
||||||
|
|
||||||
console.log('[SelectionManager] ... paste');
|
console.log('[SelectionManager] ... paste');
|
||||||
selectionManager.paste();
|
selectionManager.paste(createMockCopyEvent());
|
||||||
|
|
||||||
console.log('[SelectionManager] ... check last line is identical to middle line after paste');
|
console.log('[SelectionManager] ... check last line is identical to middle line after paste');
|
||||||
frameEqualsGrid(currentFrame, [
|
frameEqualsGrid(currentFrame, [
|
||||||
@ -87,7 +100,7 @@ describe("SelectionManager suite", function() {
|
|||||||
selectMiddleLine();
|
selectMiddleLine();
|
||||||
|
|
||||||
console.log('[SelectionManager] ... cut');
|
console.log('[SelectionManager] ... cut');
|
||||||
selectionManager.cut();
|
selectionManager.cut(createMockCopyEvent());
|
||||||
|
|
||||||
console.log('[SelectionManager] ... check middle line was cut in the source frame');
|
console.log('[SelectionManager] ... check middle line was cut in the source frame');
|
||||||
frameEqualsGrid(currentFrame, [
|
frameEqualsGrid(currentFrame, [
|
||||||
@ -97,7 +110,7 @@ describe("SelectionManager suite", function() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
console.log('[SelectionManager] ... paste');
|
console.log('[SelectionManager] ... paste');
|
||||||
selectionManager.paste();
|
selectionManager.paste(createMockCopyEvent());
|
||||||
|
|
||||||
console.log('[SelectionManager] ... check middle line was restored by paste');
|
console.log('[SelectionManager] ... check middle line was restored by paste');
|
||||||
frameEqualsGrid(currentFrame, [
|
frameEqualsGrid(currentFrame, [
|
||||||
@ -118,7 +131,7 @@ describe("SelectionManager suite", function() {
|
|||||||
selection.move(2, 0);
|
selection.move(2, 0);
|
||||||
|
|
||||||
console.log('[SelectionManager] ... copy out of bounds');
|
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');
|
console.log('[SelectionManager] ... check out of bound pixels were replaced by transparent pixels');
|
||||||
checkContainsPixel(selection.pixels, 1, 2, R);
|
checkContainsPixel(selection.pixels, 1, 2, R);
|
||||||
checkContainsPixel(selection.pixels, 1, 3, T);
|
checkContainsPixel(selection.pixels, 1, 3, T);
|
||||||
@ -133,7 +146,7 @@ describe("SelectionManager suite", function() {
|
|||||||
checkContainsPixel(selection.pixels, 1, 3, T);
|
checkContainsPixel(selection.pixels, 1, 3, T);
|
||||||
|
|
||||||
console.log('[SelectionManager] ... paste out of bounds');
|
console.log('[SelectionManager] ... paste out of bounds');
|
||||||
selectionManager.paste();
|
selectionManager.paste(createMockCopyEvent());
|
||||||
|
|
||||||
console.log('[SelectionManager] ... check pixel at (1,1) is red after paste');
|
console.log('[SelectionManager] ... check pixel at (1,1) is red after paste');
|
||||||
frameEqualsGrid(currentFrame, [
|
frameEqualsGrid(currentFrame, [
|
||||||
@ -154,7 +167,7 @@ describe("SelectionManager suite", function() {
|
|||||||
selection.move(2, 0);
|
selection.move(2, 0);
|
||||||
|
|
||||||
console.log('[SelectionManager] ... cut out of bounds');
|
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');
|
console.log('[SelectionManager] ... check last pixel of midle line was cut in the source frame');
|
||||||
frameEqualsGrid(currentFrame, [
|
frameEqualsGrid(currentFrame, [
|
||||||
[B, R, T],
|
[B, R, T],
|
||||||
@ -165,7 +178,7 @@ describe("SelectionManager suite", function() {
|
|||||||
selection.move(-1, 0);
|
selection.move(-1, 0);
|
||||||
|
|
||||||
console.log('[SelectionManager] ... paste out of bounds');
|
console.log('[SelectionManager] ... paste out of bounds');
|
||||||
selectionManager.paste();
|
selectionManager.paste(createMockCopyEvent());
|
||||||
|
|
||||||
console.log('[SelectionManager] ... check middle line final state');
|
console.log('[SelectionManager] ... check middle line final state');
|
||||||
frameEqualsGrid(currentFrame, [
|
frameEqualsGrid(currentFrame, [
|
||||||
|
Loading…
Reference in New Issue
Block a user