diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-10-13 23:29:41 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-10-13 23:49:31 +0100 |
| commit | 7b7ce0d563ddc07172b0f241a5c3baf344f256e8 (patch) | |
| tree | 43f5fddf920d47e281a30139bde99da5a689d667 /tests | |
| parent | e04d054a1b414e843fa6d6f5ee1ae75c0df533b1 (diff) | |
Collapse similar HTML elements
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/document-to-html.tests.js | 27 | ||||
| -rw-r--r-- | tests/html/simplify.tests.js | 16 | ||||
| -rw-r--r-- | tests/mammoth.tests.js | 6 |
3 files changed, 31 insertions, 18 deletions
diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index 323efb6..7180191 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -9,6 +9,7 @@ var htmlPaths = require("../lib/html-paths"); var xml = require("../lib/xml"); var results = require("../lib/results"); var documentMatchers = require("../lib/document-matchers"); +var Html = require("../lib/html"); describe('DocumentConverter', function() { @@ -157,17 +158,16 @@ describe('DocumentConverter', function() { }); }); - // TODO - //~ test('consecutive bold runs are wrapped in a single <strong> element', function() { - //~ var paragraph = new documents.Paragraph([ - //~ runOfText("Hello", {isBold: true}), - //~ runOfText(".", {isBold: true}) - //~ ]); - //~ var converter = new DocumentConverter(); - //~ return converter.convertToHtml(paragraph).then(function(result) { - //~ assert.equal(result.value, "<p><strong>Hello.</strong></p>"); - //~ }); - //~ }); + test('consecutive bold runs are wrapped in a single <strong> element', function() { + var paragraph = new documents.Paragraph([ + runOfText("Hello", {isBold: true}), + runOfText(".", {isBold: true}) + ]); + var converter = new DocumentConverter(); + return converter.convertToHtml(paragraph).then(function(result) { + assert.equal(result.value, "<p><strong>Hello.</strong></p>"); + }); + }); test('underline runs are ignored by default', function() { var run = runOfText("Hello.", {isUnderline: true}); @@ -476,10 +476,9 @@ describe('DocumentConverter', function() { contentType: "image/png" }); var converter = new DocumentConverter({ - convertImage: function(element, html, messages, callback) { + convertImage: function(element, messages, callback) { element.read("utf8").then(function(altText) { - html.selfClosing(htmlPaths.element("img", {alt: altText})); - callback(); + callback(null, Html.selfClosingElement("img", {alt: altText})); }); } }); diff --git a/tests/html/simplify.tests.js b/tests/html/simplify.tests.js index 7e17903..e23c379 100644 --- a/tests/html/simplify.tests.js +++ b/tests/html/simplify.tests.js @@ -6,11 +6,25 @@ var htmlPaths = require("../../lib/html-paths"); var fragment = html.fragment; -var element = html.element; var text = html.text; var pathToNode = html.pathToNode; describe("simplify", function() { + test("empty text nodes are removed", function() { + assert.deepEqual( + html.simplify(fragment([text("")])), + fragment([])); + }); + + test("empty elements are removed", function() { + var path = htmlPaths.elements([ + htmlPaths.element("p", {}, {fresh: false})]); + assert.deepEqual( + html.simplify(fragment([ + pathToNode(path, [text("")])])), + fragment([])); + }); + test("successive fresh elements are not collapsed", function() { var path = htmlPaths.elements([ htmlPaths.element("p", {}, {fresh: true})]); diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js index 10b95ef..34adb09 100644 --- a/tests/mammoth.tests.js +++ b/tests/mammoth.tests.js @@ -280,21 +280,21 @@ describe('mammoth', function() { test('underline is ignored by default', function() { var docxPath = path.join(__dirname, "test-data/underline.docx"); return mammoth.convertToHtml({path: docxPath}).then(function(result) { - assert.equal(result.value, '<p><strong>The </strong><strong>Sunset</strong><strong> Tree</strong></p>'); + assert.equal(result.value, '<p><strong>The Sunset Tree</strong></p>'); }); }); test('underline can be configured with convertUnderline option', function() { var docxPath = path.join(__dirname, "test-data/underline.docx"); return mammoth.convertToHtml({path: docxPath}, {convertUnderline: mammoth.underline.element("em")}).then(function(result) { - assert.equal(result.value, '<p><strong>The </strong><strong><em>Sunset</em></strong><strong> Tree</strong></p>'); + assert.equal(result.value, '<p><strong>The <em>Sunset</em> Tree</strong></p>'); }); }); test('underline can be configured with style mapping', function() { var docxPath = path.join(__dirname, "test-data/underline.docx"); return mammoth.convertToHtml({path: docxPath}, {styleMap: "u => em"}).then(function(result) { - assert.equal(result.value, '<p><strong>The </strong><strong><em>Sunset</em></strong><strong> Tree</strong></p>'); + assert.equal(result.value, '<p><strong>The <em>Sunset</em> Tree</strong></p>'); }); }); |
