diff options
| author | Jonathan Lehman <jonathan.lehman91@gmail.com> | 2017-02-17 11:59:38 -0500 |
|---|---|---|
| committer | Jonathan Lehman <jonathan.lehman91@gmail.com> | 2017-02-17 11:59:38 -0500 |
| commit | 75e327ddfff69d7bdbaff994e4662f7c37cc2b85 (patch) | |
| tree | 318fe55904110bdec9131af14e6d2ade3100acf9 /test | |
| parent | c626ef8e1047fb9f27fc4db8c17783a711bd566a (diff) | |
Handle split instrText elements
Diffstat (limited to 'test')
| -rw-r--r-- | test/docx/body-reader.tests.js | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index ab4995c..4cb7bb3 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -148,6 +148,9 @@ test("complex fields", (function() { var endXml = new XmlElement("w:r", {}, [ new XmlElement("w:fldChar", {"w:fldCharType": "end"}) ]); + var separateXml = new XmlElement("w:r", {}, [ + new XmlElement("w:fldChar", {"w:fldCharType": "separate"}) + ]); var hyperlinkInstrText = new XmlElement("w:instrText", {}, [ xml.text(' HYPERLINK "' + uri + '"') ]); @@ -160,10 +163,10 @@ test("complex fields", (function() { "runs in a complex field for hyperlinks are read as hyperlinks": function() { var hyperlinkRunXml = runOfText("this is a hyperlink"); - var afterEndXml = runOfText("this will not be a hyperlink"); var paragraphXml = new XmlElement("w:p", {}, [ beginXml, hyperlinkInstrText, + separateXml, hyperlinkRunXml, endXml ]); @@ -175,6 +178,14 @@ test("complex fields", (function() { children: contains( isHyperlink({ href: uri, + children: [] + }) + ) + }), + isRun({ + children: contains( + isHyperlink({ + href: uri, children: contains( isText("this is a hyperlink") ) @@ -190,6 +201,7 @@ test("complex fields", (function() { var paragraphXml = new XmlElement("w:p", {}, [ beginXml, hyperlinkInstrText, + separateXml, endXml, afterEndXml ]); @@ -197,6 +209,14 @@ test("complex fields", (function() { assertThat(paragraph.children, contains( isEmptyRun, + isRun({ + children: contains( + isHyperlink({ + href: uri, + children: [] + }) + ) + }), isEmptyRun, isRun({ children: contains( @@ -204,6 +224,48 @@ test("complex fields", (function() { ) }) )); + }, + + "can handle split instrText elements": function() { + var hyperlinkRunXml = runOfText("this is a hyperlink"); + var hyperlinkInstrTextPart1 = new XmlElement("w:instrText", {}, [ + xml.text(" HYPE") + ]); + var hyperlinkInstrTextPart2 = new XmlElement("w:instrText", {}, [ + xml.text('RLINK "' + uri + '"') + ]); + var paragraphXml = new XmlElement("w:p", {}, [ + beginXml, + hyperlinkInstrTextPart1, + hyperlinkInstrTextPart2, + separateXml, + hyperlinkRunXml, + endXml + ]); + var paragraph = readXmlElementValue(paragraphXml); + + assertThat(paragraph.children, contains( + isEmptyRun, + isRun({ + children: contains( + isHyperlink({ + href: uri, + children: [] + }) + ) + }), + isRun({ + children: contains( + isHyperlink({ + href: uri, + children: contains( + isText("this is a hyperlink") + ) + }) + ) + }), + isEmptyRun + )); } }; })()); |
