aboutsummaryrefslogtreecommitdiff
path: root/test/docx/comments-reader.tests.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-07-03 19:57:37 +0100
committerMichael Williamson <mike@zwobble.org>2016-07-03 19:57:37 +0100
commitc225bc3f3dbe5c001e8fec119d8f8dadf96ec95b (patch)
tree22e6da4fb93dae0cdbfa99cb6a6a508116a1b5ee /test/docx/comments-reader.tests.js
parentba731d3c8a9408b9d33deb63e0492b54298169c5 (diff)
Return root element directly when reading XML
Diffstat (limited to 'test/docx/comments-reader.tests.js')
-rw-r--r--test/docx/comments-reader.tests.js52
1 files changed, 21 insertions, 31 deletions
diff --git a/test/docx/comments-reader.tests.js b/test/docx/comments-reader.tests.js
index 2902f29..4bb0e9b 100644
--- a/test/docx/comments-reader.tests.js
+++ b/test/docx/comments-reader.tests.js
@@ -7,30 +7,29 @@ var xml = require("../../lib/xml");
var test = require("../test")(module);
-var bodyReader = new BodyReader({});
+function readComment(element) {
+ var bodyReader = new BodyReader({});
+ var commentsReader = createCommentsReader(bodyReader);
+ var comments = commentsReader(element);
+ assert.equal(comments.value.length, 1);
+ return comments.value[0];
+}
test('ID and body of comment 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"}, body)
- ])
- });
- assert.equal(comments.value.length, 1);
- assert.deepEqual(comments.value[0].body, [new documents.Paragraph([])]);
- assert.deepEqual(comments.value[0].commentId, "1");
+ var comment = readComment(xml.element("w:comments", {}, [
+ xml.element("w:comment", {"w:id": "1"}, body)
+ ]));
+ assert.deepEqual(comment.body, [new documents.Paragraph([])]);
+ assert.deepEqual(comment.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];
+ var comment = readComment(xml.element("w:comments", {}, [
+ xml.element("w:comment", {"w:id": "1"})
+ ]));
assert.strictEqual(comment.authorName, null);
assert.strictEqual(comment.authorInitials, null);
});
@@ -38,27 +37,18 @@ test('when optional attributes of comment are missing then they are read as 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];
+ var comment = readComment(xml.element("w:comments", {}, [
+ xml.element("w:comment", {"w:id": "1", "w:author": " ", "w:initials": " "})
+ ]));
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];
+ var comment = readComment(xml.element("w:comments", {}, [
+ xml.element("w:comment", {"w:id": "1", "w:author": "The Piemaker", "w:initials": "TP"})
+ ]));
assert.strictEqual(comment.authorName, "The Piemaker");
assert.strictEqual(comment.authorInitials, "TP");
});