Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/events/events_block_change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class BlockChange extends BlockBase {
break;
}
case 'comment':
block.setCommentText((value as string) || null);
block.setCommentText((value as string) ?? null);
break;
case 'collapsed':
block.setCollapsed(!!value);
Expand Down
45 changes: 45 additions & 0 deletions tests/mocha/comment_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,49 @@ suite('Comments', function () {
assertBubbleLocation(this.comment, 100, 100);
});
});
suite('Undo/Redo', function () {
test('Adding an empty comment can be undone', function () {
const block = this.workspace.newBlock('empty_block');
block.setCommentText('');
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.equal(block.getCommentText(), '');

this.workspace.undo(false);

assert.isUndefined(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.isNull(block.getCommentText());
});

test('Adding an empty comment can be redone', function () {
const block = this.workspace.newBlock('empty_block');
block.setCommentText('');
this.workspace.undo(false);
this.workspace.undo(true);

assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.equal(block.getCommentText(), '');
});

test('Adding a non-empty comment can be undone', function () {
const block = this.workspace.newBlock('empty_block');
block.setCommentText('hey there');
assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.equal(block.getCommentText(), 'hey there');

this.workspace.undo(false);

assert.isUndefined(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.isNull(block.getCommentText());
});

test('Adding a non-empty comment can be redone', function () {
const block = this.workspace.newBlock('empty_block');
block.setCommentText('hey there');
this.workspace.undo(false);
this.workspace.undo(true);

assert.isNotNull(block.getIcon(Blockly.icons.IconType.COMMENT));
assert.equal(block.getCommentText(), 'hey there');
});
});
});
Loading