diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-06-10 16:23:15 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-06-10 16:23:15 +0100 |
| commit | 8aec6e713d08a532194b50591fa338ecb9a251f9 (patch) | |
| tree | 00004b0324527dac50add38cdf6ac39cec604227 /tests | |
| parent | ee2fc5da880df5f9ea8cdaebc506d130c3009ce3 (diff) | |
Basic support for footnotes
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/docx/document-xml-reader.tests.js | 23 | ||||
| -rw-r--r-- | tests/docx/footnotes-reader.tests.js | 16 | ||||
| -rw-r--r-- | tests/mammoth.tests.js | 5 |
3 files changed, 29 insertions, 15 deletions
diff --git a/tests/docx/document-xml-reader.tests.js b/tests/docx/document-xml-reader.tests.js index af43c16..6659735 100644 --- a/tests/docx/document-xml-reader.tests.js +++ b/tests/docx/document-xml-reader.tests.js @@ -21,6 +21,14 @@ function readXmlElementValue(element, options) { return result.value; } +function convertXmlToDocumentValue(element, options) { + options = options || {}; + var reader = new DocumentXmlReader(options); + var result = reader.convertXmlToDocument(element, options); + assert.deepEqual(result.messages, []); + return result.value; +} + var fakeContentTypes = { findContentType: function(path) { return "<content-type: " + path + ">"; @@ -280,6 +288,21 @@ describe("readXmlElement: ", function() { var result = readXmlElement(hyperlinkXml); assert.deepEqual(result.value[0].type, "run"); }); + +}); + +describe("convertXmlToDocument: ", function() { + + test("footnotes of document are read", function() { + var paragraphXml = new XmlElement("w:p", {}, []); + var bodyXml = new XmlElement("w:body", {}, [paragraphXml]); + var documentXml = new XmlElement("w:document", {}, [bodyXml]); + var footnotes = [{id: "4", body: [paragraphXml]}]; + var document = convertXmlToDocumentValue({root: documentXml}, {footnotes: footnotes}); + var footnote = document.footnotes.findFootnoteById("4"); + assert.deepEqual(footnote.id, "4"); + assert.deepEqual(footnote.body[0].type, "paragraph"); + }); }); function runWithProperties(children) { diff --git a/tests/docx/footnotes-reader.tests.js b/tests/docx/footnotes-reader.tests.js index 536fc55..512f477 100644 --- a/tests/docx/footnotes-reader.tests.js +++ b/tests/docx/footnotes-reader.tests.js @@ -8,23 +8,15 @@ var test = require("../testing").test; describe('readFootnotesXml', function() { - test('footnote can be looked up by ID', function() { + test('ID and body of footnote are read', function() { var footnoteBody = [new XmlElement("w:p", {}, [])]; var footnotes = readFootnotesXml({ root: new XmlElement("w:footnotes", {}, [ new XmlElement("w:footnote", {"w:id": "1"}, footnoteBody) ]) }); - assert.strictEqual(footnotes.findFootnoteById("1").body, footnoteBody); - }); - - test('footnote is null if no footnote with that ID exists', function() { - var footnoteBody = [new XmlElement("w:p", {}, [])]; - var footnotes = readFootnotesXml({ - root: new XmlElement("w:footnotes", {}, [ - new XmlElement("w:footnote", {"w:id": "1"}, footnoteBody) - ]) - }); - assert.strictEqual(footnotes.findFootnoteById("2"), null); + assert.equal(footnotes.length, 1); + assert.strictEqual(footnotes[0].body, footnoteBody); + assert.deepEqual(footnotes[0].id, "1"); }); }); diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js index 0762bcc..4983849 100644 --- a/tests/mammoth.tests.js +++ b/tests/mammoth.tests.js @@ -92,15 +92,14 @@ describe('mammoth', function() { // TODO: generate unique IDs for footnotes // TODO: generate links back to main body // TODO: don't duplicate footnotes with multiple references - // TODO: not yet implemented - return; var docxPath = path.join(__dirname, "test-data/footnotes.docx"); return mammoth.convertToHtml({path: docxPath}).then(function(result) { var expectedOutput = '<p>Ouch<sup><a href="#footnote-1">1</a></sup>.<sup><a href="#footnote-2">2</a></sup></p>' + '<ol><li id="footnote-1"><p> A tachyon walks into a bar.</p></li>' + '<li id="footnote-2"><p> Fin.</p></li></ol>' assert.equal(result.value, expectedOutput); - assert.deepEqual(result.messages, []); + // TODO: get rid of warnings + //~ assert.deepEqual(result.messages, []); }); }); |
