diff options
Diffstat (limited to 'test/docx/comments-reader.tests.js')
| -rw-r--r-- | test/docx/comments-reader.tests.js | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/test/docx/comments-reader.tests.js b/test/docx/comments-reader.tests.js index 55cffeb..2902f29 100644 --- a/test/docx/comments-reader.tests.js +++ b/test/docx/comments-reader.tests.js @@ -7,8 +7,9 @@ var xml = require("../../lib/xml"); var test = require("../test")(module); +var bodyReader = new BodyReader({}); + test('ID and body of comment are read', function() { - var bodyReader = new BodyReader({}); var body = [xml.element("w:p")]; var comments = createCommentsReader(bodyReader)({ root: xml.element("w:comments", {}, [ @@ -19,3 +20,45 @@ test('ID and body of comment are read', function() { assert.deepEqual(comments.value[0].body, [new documents.Paragraph([])]); assert.deepEqual(comments.value[0].commentId, "1"); }); + + +test('when optional attributes of comment are missing then they are read as null', function() { + var body = [xml.element("w:p")]; + var comments = createCommentsReader(bodyReader)({ + root: xml.element("w:comments", {}, [ + xml.element("w:comment", {"w:id": "1"}, body) + ]) + }); + assert.equal(comments.value.length, 1); + var comment = comments.value[0]; + assert.strictEqual(comment.authorName, null); + assert.strictEqual(comment.authorInitials, null); +}); + + +test('when optional attributes of comment are blank then they are read as null', function() { + var body = [xml.element("w:p")]; + var comments = createCommentsReader(bodyReader)({ + root: xml.element("w:comments", {}, [ + xml.element("w:comment", {"w:id": "1", "w:author": " ", "w:initials": " "}, body) + ]) + }); + assert.equal(comments.value.length, 1); + var comment = comments.value[0]; + assert.strictEqual(comment.authorName, null); + assert.strictEqual(comment.authorInitials, null); +}); + + +test('when optional attributes of comment are not blank then they are read', function() { + var body = [xml.element("w:p")]; + var comments = createCommentsReader(bodyReader)({ + root: xml.element("w:comments", {}, [ + xml.element("w:comment", {"w:id": "1", "w:author": "The Piemaker", "w:initials": "TP"}, body) + ]) + }); + assert.equal(comments.value.length, 1); + var comment = comments.value[0]; + assert.strictEqual(comment.authorName, "The Piemaker"); + assert.strictEqual(comment.authorInitials, "TP"); +}); |
