aboutsummaryrefslogtreecommitdiff
path: root/test/styles
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-11-19 11:54:43 +0000
committerMichael Williamson <mike@zwobble.org>2016-11-19 11:54:43 +0000
commit68d8c8140fb6ef1118fa2815243817f8e4f55b59 (patch)
treed4e4be8d3b124d98f2d204ed5f97585a8729ca94 /test/styles
parent5f84e7887b262b96fd6fd47ce6bb1cd96c196f69 (diff)
Move html-paths and document-matchers to styles module
Diffstat (limited to 'test/styles')
-rw-r--r--test/styles/document-matchers.tests.js50
-rw-r--r--test/styles/html-paths.tests.js20
2 files changed, 70 insertions, 0 deletions
diff --git a/test/styles/document-matchers.tests.js b/test/styles/document-matchers.tests.js
new file mode 100644
index 0000000..e36298c
--- /dev/null
+++ b/test/styles/document-matchers.tests.js
@@ -0,0 +1,50 @@
+var assert = require("assert");
+
+var test = require("../test")(module);
+var documentMatchers = require("../../lib/styles/document-matchers");
+var documents = require("../../lib/documents");
+var Paragraph = documents.Paragraph;
+
+test("paragraph with no options matches any paragraph", function() {
+ var matcher = documentMatchers.paragraph();
+ assert.ok(matcher.matches(new Paragraph()));
+ assert.ok(matcher.matches(paragraphWithStyle("Heading1", "Heading 1")));
+});
+
+test("paragraph style ID only matches paragraphs with that style ID", function() {
+ var matcher = documentMatchers.paragraph({styleId: "Heading1"});
+ assert.ok(!matcher.matches(new Paragraph()));
+ assert.ok(matcher.matches(paragraphWithStyle("Heading1", "Heading 1")));
+ assert.ok(!matcher.matches(paragraphWithStyle("Heading2", "Heading 2")));
+});
+
+test("paragraph style name only matches paragraphs with that style name", function() {
+ var matcher = documentMatchers.paragraph({styleName: "Heading 1"});
+ assert.ok(!matcher.matches(new Paragraph()));
+ assert.ok(matcher.matches(paragraphWithStyle("Heading1", "Heading 1")));
+ assert.ok(!matcher.matches(paragraphWithStyle("Heading2", "Heading 2")));
+});
+
+test("ordered-list(index) matches an ordered list with specified level index", function() {
+ var matcher = documentMatchers.paragraph({list: {isOrdered: true, levelIndex: 1}});
+ assert.ok(!matcher.matches(new Paragraph()));
+ assert.ok(matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: true}})));
+ assert.ok(!matcher.matches(new Paragraph([], {numbering: {level: 0, isOrdered: true}})));
+ assert.ok(!matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: false}})));
+});
+
+test("unordered-list(index) matches an unordered list with specified level index", function() {
+ var matcher = documentMatchers.paragraph({list: {isOrdered: false, levelIndex: 1}});
+ assert.ok(!matcher.matches(new Paragraph()));
+ assert.ok(matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: false}})));
+ assert.ok(!matcher.matches(new Paragraph([], {numbering: {level: 1, isOrdered: true}})));
+});
+
+test("matchers for lists with index 0 do not match elements that are not lists", function() {
+ var matcher = documentMatchers.paragraph({list: {isOrdered: true, levelIndex: 0}});
+ assert.ok(!matcher.matches(new Paragraph()));
+});
+
+function paragraphWithStyle(styleId, styleName) {
+ return new Paragraph([], {styleId: styleId, styleName: styleName});
+}
diff --git a/test/styles/html-paths.tests.js b/test/styles/html-paths.tests.js
new file mode 100644
index 0000000..ab24cec
--- /dev/null
+++ b/test/styles/html-paths.tests.js
@@ -0,0 +1,20 @@
+var assert = require("assert");
+
+var test = require("../test")(module);
+var htmlPaths = require("../../lib/styles/html-paths");
+
+
+test("element can match multiple tag names", function() {
+ var pathPart = htmlPaths.element(["ul", "ol"]);
+ assert.ok(pathPart.matchesElement({tagName: "ul"}));
+ assert.ok(pathPart.matchesElement({tagName: "ol"}));
+ assert.ok(!pathPart.matchesElement({tagName: "p"}));
+});
+
+test("element matches if attributes are the same", function() {
+ var pathPart = htmlPaths.element(["p"], {"class": "tip"});
+ assert.ok(!pathPart.matchesElement({tagName: "p"}));
+ assert.ok(!pathPart.matchesElement({tagName: "p", attributes: {"class": "tip help"}}));
+ assert.ok(pathPart.matchesElement({tagName: "p", attributes: {"class": "tip"}}));
+});
+