Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apple502j committed Jul 1, 2020
1 parent 5d5196f commit e8e0821
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/engine/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ class Blocks {
// Delete comments attached to the block.
if (block.comment) {
const editingTarget = this.runtime.getEditingTarget();
if (editingTarget.comments.hasOwnProperty(block.comment)) {
if (editingTarget && editingTarget.comments.hasOwnProperty(block.comment)) {
delete editingTarget.comments[block.comment];
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/unit/engine_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,25 @@ test('delete inputs', t => {
t.end();
});

test('delete block with comment', t => {
const b = new Blocks(new Runtime());
const fakeTarget = {
comments: {
bar: {
blockId: 'foo'
}
}
};
b.runtime.getEditingTarget = () => fakeTarget;
b.createBlock({
id: 'foo',
comment: 'bar'
});
b.deleteBlock('foo');
t.notOk(fakeTarget.comments.hasOwnProperty('bar'));
t.end();
});

test('updateAssetName function updates name in sound field', t => {
const b = new Blocks(new Runtime());
b.createBlock({
Expand Down
15 changes: 15 additions & 0 deletions test/unit/sprites_rendered-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ test('blocks get new id on duplicate', t => {
});
});

test('comments are duplicated when duplicating target', t => {
const r = new Runtime();
const s = new Sprite(null, r);
const rt = new RenderedTarget(s, r);
rt.createComment('commentid', null, 'testcomment', 0, 0, 100, 100, false);
t.ok(s.comments.hasOwnProperty('commentid'));
return rt.duplicate().then(duplicate => {
// Not ok because comment id should be re-generated
t.notOk(duplicate.comments.hasOwnProperty('commentid'));
t.ok(Object.keys(duplicate.comments).length === 1);
t.end();
});
});


test('direction', t => {
const r = new Runtime();
const s = new Sprite(null, r);
Expand Down

0 comments on commit e8e0821

Please sign in to comment.