Skip to content

Commit a888362

Browse files
committed
Add tests for workspace comments
1 parent 32bb84e commit a888362

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/mocha/shortcut_items_test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ suite('Keyboard Shortcut Items', function () {
4747
.returns(block.nextConnection);
4848
}
4949

50+
/**
51+
* Creates a workspace comment and set it as the focused node.
52+
* @param {Blockly.Workspace} workspace The workspace to create a new comment on.
53+
*/
54+
function setSelectedComment(workspace) {
55+
const comment = workspace.newComment();
56+
sinon.stub(Blockly.getFocusManager(), 'getFocusedNode').returns(comment);
57+
return comment;
58+
}
59+
5060
/**
5161
* Creates a test for not running keyDown events when the workspace is in read only mode.
5262
* @param {Object} keyEvent Mocked key down event. Use createKeyDownEvent.
@@ -241,6 +251,22 @@ suite('Keyboard Shortcut Items', function () {
241251
sinon.assert.notCalled(this.copySpy);
242252
sinon.assert.notCalled(this.hideChaffSpy);
243253
});
254+
// Copy a comment.
255+
test('Workspace comment', function () {
256+
testCases.forEach(function (testCase) {
257+
const testCaseName = testCase[0];
258+
const keyEvent = testCase[1];
259+
test(testCaseName, function () {
260+
Blockly.getFocusManager().getFocusedNode.restore();
261+
this.comment = setSelectedComment(this.workspace);
262+
this.copySpy = sinon.spy(this.comment, 'toCopyData');
263+
264+
this.injectionDiv.dispatchEvent(keyEvent);
265+
sinon.assert.calledOnce(this.copySpy);
266+
sinon.assert.calledOnce(this.hideChaffSpy);
267+
});
268+
});
269+
});
244270
});
245271

246272
suite('Cut', function () {
@@ -353,6 +379,24 @@ suite('Keyboard Shortcut Items', function () {
353379
sinon.assert.notCalled(this.disposeSpy);
354380
sinon.assert.notCalled(this.hideChaffSpy);
355381
});
382+
383+
// Cut a comment.
384+
suite('Workspace comment', function () {
385+
testCases.forEach(function (testCase) {
386+
const testCaseName = testCase[0];
387+
const keyEvent = testCase[1];
388+
test(testCaseName, function () {
389+
Blockly.getFocusManager().getFocusedNode.restore();
390+
this.comment = setSelectedComment(this.workspace);
391+
this.copySpy = sinon.spy(this.comment, 'toCopyData');
392+
this.disposeSpy = sinon.spy(this.comment, 'dispose');
393+
394+
this.injectionDiv.dispatchEvent(keyEvent);
395+
sinon.assert.calledOnce(this.copySpy);
396+
sinon.assert.calledOnce(this.disposeSpy);
397+
});
398+
});
399+
});
356400
});
357401

358402
suite('Undo', function () {

0 commit comments

Comments
 (0)