diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-11-30 11:20:20 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-11-30 11:20:20 +0000 |
| commit | 3751195339954f49f525446de0795d2acad2c234 (patch) | |
| tree | fb177eed0d2ad356f438cbfb35ff045760c87f0e /test | |
| parent | f79db6f1dd40c5ff0325e2a5ea4d99485ce18bf4 (diff) | |
Read complex field checkboxes, always unchecked
Diffstat (limited to 'test')
| -rw-r--r-- | test/docx/body-reader.tests.js | 37 | ||||
| -rw-r--r-- | test/docx/document-matchers.js | 5 |
2 files changed, 42 insertions, 0 deletions
diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index 292e1a2..a431866 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -7,12 +7,14 @@ var assertThat = hamjest.assertThat; var promiseThat = hamjest.promiseThat; var allOf = hamjest.allOf; var contains = hamjest.contains; +var equalTo = hamjest.equalTo; var hasProperties = hamjest.hasProperties; var willBe = hamjest.willBe; var FeatureMatcher = hamjest.FeatureMatcher; var documentMatchers = require("./document-matchers"); var isEmptyRun = documentMatchers.isEmptyRun; +var isCheckbox = documentMatchers.isCheckbox; var isHyperlink = documentMatchers.isHyperlink; var isRun = documentMatchers.isRun; var isText = documentMatchers.isText; @@ -529,6 +531,41 @@ test("complex fields", (function() { }; })()); +test("checkboxes", { + "complex field checkbox without default or checked elements is unchecked": function() { + var paragraphXml = xml.element("w:p", {}, [ + xml.element("w:r", {}, [ + xml.element("w:fldChar", {"w:fldCharType": "begin"}, [ + xml.element("w:ffData", {}, [ + xml.element("w:checkBox") + ]) + ]) + ]), + xml.element("w:instrText", {}, [ + xml.text(' FORMCHECKBOX ') + ]), + xml.element("w:r", {}, [ + xml.element("w:fldChar", {"w:fldCharType": "separate"}) + ]), + xml.element("w:r", {}, [ + xml.element("w:fldChar", {"w:fldCharType": "end"}) + ]) + ]); + + var paragraph = readXmlElementValue(paragraphXml); + + assertThat(paragraph.children, contains( + isEmptyRun, + isEmptyRun, + isRun({ + children: contains( + isCheckbox({checked: equalTo(false)}) + ) + }) + )); + } +}); + test("run has no style if it has no properties", function() { var runXml = runWithProperties([]); var run = readXmlElementValue(runXml); diff --git a/test/docx/document-matchers.js b/test/docx/document-matchers.js index 83c4486..11b5aa9 100644 --- a/test/docx/document-matchers.js +++ b/test/docx/document-matchers.js @@ -7,6 +7,7 @@ var documents = require("../../lib/documents"); exports.isEmptyRun = isRun({children: []}); exports.isRun = isRun; exports.isText = isText; +exports.isCheckbox = isCheckbox; exports.isHyperlink = isHyperlink; exports.isTable = isTable; exports.isRow = isRow; @@ -20,6 +21,10 @@ function isText(text) { return isDocumentElement(documents.types.text, {value: text}); } +function isCheckbox(properties) { + return isDocumentElement(documents.types.checkbox, properties); +} + function isHyperlink(properties) { return isDocumentElement(documents.types.hyperlink, properties); } |
