diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-07-03 19:57:37 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-07-03 19:57:37 +0100 |
| commit | c225bc3f3dbe5c001e8fec119d8f8dadf96ec95b (patch) | |
| tree | 22e6da4fb93dae0cdbfa99cb6a6a508116a1b5ee /test/docx | |
| parent | ba731d3c8a9408b9d33deb63e0492b54298169c5 (diff) | |
Return root element directly when reading XML
Diffstat (limited to 'test/docx')
| -rw-r--r-- | test/docx/comments-reader.tests.js | 52 | ||||
| -rw-r--r-- | test/docx/content-types-reader.tests.js | 24 | ||||
| -rw-r--r-- | test/docx/notes-reader.tests.js | 12 | ||||
| -rw-r--r-- | test/docx/numbering-xml.tests.js | 6 | ||||
| -rw-r--r-- | test/docx/office-xml-reader.tests.js | 2 | ||||
| -rw-r--r-- | test/docx/styles-reader.tests.js | 42 |
6 files changed, 64 insertions, 74 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"); }); diff --git a/test/docx/content-types-reader.tests.js b/test/docx/content-types-reader.tests.js index a223d09..5ea93ec 100644 --- a/test/docx/content-types-reader.tests.js +++ b/test/docx/content-types-reader.tests.js @@ -7,28 +7,28 @@ var test = require("../testing").test; describe('readContentTypesFromXml', function() { test('reads default-per-extension from XML', function() { - var contentTypes = readContentTypesFromXml({ - root: new XmlElement("content-types:Types", {}, [ + var contentTypes = readContentTypesFromXml( + new XmlElement("content-types:Types", {}, [ new XmlElement("content-types:Default", {Extension: "png", ContentType: "image/png"}) ]) - }); + ); assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/png"); }); test('reads overrides in preference to defaults', function() { - var contentTypes = readContentTypesFromXml({ - root: new XmlElement("content-types:Types", {}, [ + var contentTypes = readContentTypesFromXml( + new XmlElement("content-types:Types", {}, [ new XmlElement("content-types:Default", {Extension: "png", ContentType: "image/png"}), new XmlElement("content-types:Override", {PartName: "/word/media/hat.png", ContentType: "image/hat"}) ]) - }); + ); assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/hat"); }); test('fallback content types have common image types', function() { - var contentTypes = readContentTypesFromXml({ - root: new XmlElement("content-types:Types", {}, []) - }); + var contentTypes = readContentTypesFromXml( + new XmlElement("content-types:Types", {}, []) + ); assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/png"); assert.equal(contentTypes.findContentType("word/media/hat.gif"), "image/gif"); assert.equal(contentTypes.findContentType("word/media/hat.jpg"), "image/jpeg"); @@ -39,9 +39,9 @@ describe('readContentTypesFromXml', function() { }); test('fallback content types are case insensitive on extension', function() { - var contentTypes = readContentTypesFromXml({ - root: new XmlElement("content-types:Types", {}, []) - }); + var contentTypes = readContentTypesFromXml( + new XmlElement("content-types:Types", {}, []) + ); assert.equal(contentTypes.findContentType("word/media/hat.PnG"), "image/png"); }); }); diff --git a/test/docx/notes-reader.tests.js b/test/docx/notes-reader.tests.js index 79ffed3..85a49f5 100644 --- a/test/docx/notes-reader.tests.js +++ b/test/docx/notes-reader.tests.js @@ -11,11 +11,11 @@ describe('readFootnotesXml', function() { test('ID and body of footnote are read', function() { var bodyReader = new BodyReader({}); var footnoteBody = [new XmlElement("w:p", {}, [])]; - var footnotes = createFootnotesReader(bodyReader)({ - root: new XmlElement("w:footnotes", {}, [ + var footnotes = createFootnotesReader(bodyReader)( + new XmlElement("w:footnotes", {}, [ new XmlElement("w:footnote", {"w:id": "1"}, footnoteBody) ]) - }); + ); assert.equal(footnotes.value.length, 1); assert.deepEqual(footnotes.value[0].body, [new documents.Paragraph([])]); assert.deepEqual(footnotes.value[0].noteId, "1"); @@ -28,11 +28,11 @@ footnoteTypeIsIgnored('separator'); function footnoteTypeIsIgnored(type) { describe('footnotes of type ' + type + ' are ignored', function() { test('ID and body of footnote are read', function() { - var footnotes = createFootnotesReader()({ - root: new XmlElement("w:footnotes", {}, [ + var footnotes = createFootnotesReader()( + new XmlElement("w:footnotes", {}, [ new XmlElement("w:footnote", {"w:id": "1", "w:type": type}, []) ]) - }); + ); assert.equal(footnotes.value.length, 0); }); }); diff --git a/test/docx/numbering-xml.tests.js b/test/docx/numbering-xml.tests.js index 2fea5fb..fb28cb8 100644 --- a/test/docx/numbering-xml.tests.js +++ b/test/docx/numbering-xml.tests.js @@ -7,8 +7,8 @@ var test = require("../testing").test; describe('readNumberingXml', function() { test('w:num element inherits levels from w:abstractNum', function() { - var numbering = readNumberingXml({ - root: new XmlElement("w:numbering", {}, [ + var numbering = readNumberingXml( + new XmlElement("w:numbering", {}, [ new XmlElement("w:abstractNum", {"w:abstractNumId": "42"}, [ new XmlElement("w:lvl", {"w:ilvl": "0"}, [ new XmlElement("w:numFmt", {"w:val": "bullet"}) @@ -21,7 +21,7 @@ describe('readNumberingXml', function() { new XmlElement("w:abstractNumId", {"w:val": "42"}) ]) ]) - }); + ); duck.assertThat(numbering.findLevel("47", "0"), duck.hasProperties({ isOrdered: false })); diff --git a/test/docx/office-xml-reader.tests.js b/test/docx/office-xml-reader.tests.js index 9d202ba..f28c4f3 100644 --- a/test/docx/office-xml-reader.tests.js +++ b/test/docx/office-xml-reader.tests.js @@ -20,7 +20,7 @@ describe("office-xml-reader", function() { '</mc:AlternateContent>' + '</numbering>'; return officeXmlReader.read(xmlString).then(function(element) { - assert.deepEqual(element.root.children, [xml.element("fallback")]); + assert.deepEqual(element.children, [xml.element("fallback")]); }); }); }); diff --git a/test/docx/styles-reader.tests.js b/test/docx/styles-reader.tests.js index 4ff19c7..8de53ef 100644 --- a/test/docx/styles-reader.tests.js +++ b/test/docx/styles-reader.tests.js @@ -7,66 +7,66 @@ var test = require("../testing").test; describe('readStylesXml', function() { test('paragraph style is null if no style with that ID exists', function() { - var styles = readStylesXml({ - root: new XmlElement("w:styles", {}, []) - }); + var styles = readStylesXml( + new XmlElement("w:styles", {}, []) + ); assert.equal(styles.findParagraphStyleById("Heading1"), null); }); test('paragraph style can be found by ID', function() { - var styles = readStylesXml({ - root: new XmlElement("w:styles", {}, [ + var styles = readStylesXml( + new XmlElement("w:styles", {}, [ paragraphStyleElement("Heading1", "Heading 1") ]) - }); + ); assert.equal(styles.findParagraphStyleById("Heading1").styleId, "Heading1"); }); test('character style can be found by ID', function() { - var styles = readStylesXml({ - root: new XmlElement("w:styles", {}, [ + var styles = readStylesXml( + new XmlElement("w:styles", {}, [ characterStyleElement("Heading1Char", "Heading 1 Char") ]) - }); + ); assert.equal(styles.findCharacterStyleById("Heading1Char").styleId, "Heading1Char"); }); test('paragraph and character styles are distinct', function() { - var styles = readStylesXml({ - root: new XmlElement("w:styles", {}, [ + var styles = readStylesXml( + new XmlElement("w:styles", {}, [ paragraphStyleElement("Heading1", "Heading 1"), characterStyleElement("Heading1Char", "Heading 1 Char") ]) - }); + ); assert.equal(styles.findCharacterStyleById("Heading1"), null); assert.equal(styles.findParagraphStyleById("Heading1Char"), null); }); test('character and table styles are distinct', function() { - var styles = readStylesXml({ - root: new XmlElement("w:styles", {}, [ + var styles = readStylesXml( + new XmlElement("w:styles", {}, [ styleElement("table", "Heading1", "Heading 1") ]) - }); + ); assert.equal(styles.findCharacterStyleById("Heading1"), null); }); test('styles include names', function() { - var styles = readStylesXml({ - root: new XmlElement("w:styles", {}, [ + var styles = readStylesXml( + new XmlElement("w:styles", {}, [ paragraphStyleElement("Heading1", "Heading 1") ]) - }); + ); assert.equal(styles.findParagraphStyleById("Heading1").name, "Heading 1"); }); test('style name is null if w:name element does not exist', function() { - var styles = readStylesXml({ - root: new XmlElement("w:styles", {}, [ + var styles = readStylesXml( + new XmlElement("w:styles", {}, [ styleWithoutWNameElement("paragraph", "Heading1"), styleWithoutWNameElement("character", "Heading1Char") ]) - }); + ); assert.equal(styles.findParagraphStyleById("Heading1").name, null); assert.equal(styles.findCharacterStyleById("Heading1Char").name, null); }); |
