summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-02-16 11:20:25 +0000
committerMichael Williamson <mike@zwobble.org>2017-02-16 11:20:25 +0000
commit7a738f5b619de07eca4bd5e49259912a839b15d2 (patch)
tree776c507cc877c78a367d1d613ffe66d0754f85ac
parentfdd4a4d329a647912fd48991472ff61996684862 (diff)
Remove explicit indices in test
-rw-r--r--test/docx/body-reader.tests.js42
-rw-r--r--test/docx/document-matchers.js27
2 files changed, 55 insertions, 14 deletions
diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js
index 147684f..9bd2e34 100644
--- a/test/docx/body-reader.tests.js
+++ b/test/docx/body-reader.tests.js
@@ -3,6 +3,7 @@ var path = require("path");
var _ = require("underscore");
var hamjest = require("hamjest");
+var assertThat = hamjest.assertThat;
var promiseThat = hamjest.promiseThat;
var allOf = hamjest.allOf;
var contains = hamjest.contains;
@@ -10,6 +11,12 @@ var hasProperties = hamjest.hasProperties;
var willBe = hamjest.willBe;
var FeatureMatcher = hamjest.FeatureMatcher;
+var documentMatchers = require("./document-matchers");
+var isEmptyRun = documentMatchers.isEmptyRun;
+var isHyperlink = documentMatchers.isHyperlink;
+var isRun = documentMatchers.isRun;
+var isText = documentMatchers.isText;
+
var BodyReader = require("../../lib/docx/body-reader").BodyReader;
var documents = require("../../lib/documents");
var xml = require("../../lib/xml");
@@ -166,20 +173,27 @@ test("runs in a complex field for hyperlinks are read as hyperlinks", function()
afterEndXml
]);
var paragraph = readXmlElementValue(parXml);
-
- var hyperlinkRun = paragraph.children[1];
- var hyperlink = hyperlinkRun.children[0];
- assert.equal(hyperlink.type, 'hyperlink');
- assert.equal(hyperlink.href, uri);
- var hyperlinkText = hyperlink.children[0];
- assert.equal(hyperlinkText.type, 'text');
- assert.equal(hyperlinkText.value, 'this is a hyperlink');
-
- // runs after fldCharType "end" do not become hyperlinks
- var run = paragraph.children[3];
- var text = run.children[0];
- assert.equal(text.type, 'text');
- assert.equal(text.value, 'this will not be a hyperlink');
+
+ assertThat(paragraph.children, contains(
+ isEmptyRun,
+ isRun({
+ children: contains(
+ isHyperlink({
+ href: uri,
+ children: contains(
+ isText("this is a hyperlink")
+ )
+ })
+ )
+ }),
+ isEmptyRun,
+ isRun({
+ // runs after fldCharType "end" do not become hyperlinks
+ children: contains(
+ isText("this will not be a hyperlink")
+ )
+ })
+ ));
});
test("run has no style if it has no properties", function() {
diff --git a/test/docx/document-matchers.js b/test/docx/document-matchers.js
new file mode 100644
index 0000000..b750bed
--- /dev/null
+++ b/test/docx/document-matchers.js
@@ -0,0 +1,27 @@
+var hamjest = require("hamjest");
+var _ = require("underscore");
+
+var documents = require("../../lib/documents");
+
+
+exports.isEmptyRun = isRun({children: []});
+exports.isRun = isRun;
+exports.isText = isText;
+exports.isHyperlink = isHyperlink;
+
+
+function isRun(properties) {
+ return isDocumentElement(documents.types.run, properties);
+}
+
+function isText(text) {
+ return isDocumentElement(documents.types.text, {value: text});
+}
+
+function isHyperlink(properties) {
+ return isDocumentElement(documents.types.hyperlink, properties);
+}
+
+function isDocumentElement(type, properties) {
+ return hamjest.hasProperties(_.extend({type: hamjest.equalTo(type)}, properties));
+}