From 76b423e481c1d64949e22f4062d1078d16ebca11 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Fri, 15 Jun 2018 13:58:03 -0400 Subject: [PATCH] Make sure to set comment property of block when creating a new block via XML using the adapter. Update unit tests. --- src/engine/adapter.js | 5 +++++ test/fixtures/events.json | 13 +++++++++++++ test/unit/engine_adapter.js | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/engine/adapter.js b/src/engine/adapter.js index 9d17f92b8..873974f8c 100644 --- a/src/engine/adapter.js +++ b/src/engine/adapter.js @@ -86,6 +86,11 @@ const domToBlock = function (blockDOM, blocks, isTopBlock, parent) { } break; } + case 'comment': + { + block.comment = xmlChild.attribs.id; + break; + } case 'value': case 'statement': { diff --git a/test/fixtures/events.json b/test/fixtures/events.json index 4820c58cf..a5a126f07 100644 --- a/test/fixtures/events.json +++ b/test/fixtures/events.json @@ -12,6 +12,19 @@ "!6Ahqg4f}Ljl}X5Hws?Z" ] }, + "createComment": { + "workspaceId": "7Luws3lyb*Z98~Kk+IG|", + "group": ";OswyM#@%`%,xOrhOXC=", + "recordUndo": true, + "name": "block", + "xml": { + "outerHTML": "Some comment text10" + }, + "ids": [ + "z!+#Nqr,_(V=xz0y7a@d", + "!6Ahqg4f}Ljl}X5Hws?Z" + ] + }, "createbranch": { "name": "block", "xml": { diff --git a/test/unit/engine_adapter.js b/test/unit/engine_adapter.js index 4255fb8fe..814ff9ffc 100644 --- a/test/unit/engine_adapter.js +++ b/test/unit/engine_adapter.js @@ -24,6 +24,7 @@ test('create event', t => { // Outer block t.type(result[0].id, 'string'); t.type(result[0].opcode, 'string'); + t.type(result[0].comment, 'undefined'); t.type(result[0].fields, 'object'); t.type(result[0].inputs, 'object'); t.type(result[0].inputs.DURATION, 'object'); @@ -43,6 +44,20 @@ test('create event', t => { t.end(); }); +test('create with comment', t => { + const result = adapter(events.createComment); + + // This test should be the same as above except that it also has a comment. + + t.ok(Array.isArray(result)); + t.equal(result.length, 2); + + t.type(result[0].comment, 'string'); + t.equal(result[0].comment, 'aCommentId'); + + t.end(); +}); + test('create with branch', t => { const result = adapter(events.createbranch); // Outer block