aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/document-to-html.tests.js46
-rw-r--r--test/style-reader.tests.js14
-rw-r--r--test/styles/document-matchers.tests.js20
3 files changed, 80 insertions, 0 deletions
diff --git a/test/document-to-html.tests.js b/test/document-to-html.tests.js
index 4283e86..4587602 100644
--- a/test/document-to-html.tests.js
+++ b/test/document-to-html.tests.js
@@ -344,6 +344,52 @@ test('small caps runs can be configured with style mapping', function() {
});
+test('highlighted runs are ignored by default', function() {
+ var run = runOfText("Hello.", {highlight: "yellow"});
+ var converter = new DocumentConverter();
+ return converter.convertToHtml(run).then(function(result) {
+ assert.equal(result.value, "Hello.");
+ });
+});
+
+test('highlighted runs can be configured with style mapping for all highlights', function() {
+ var run = runOfText("Hello.", {highlight: "yellow"});
+ var converter = new DocumentConverter({
+ styleMap: [
+ {
+ from: documentMatchers.highlight(null),
+ to: htmlPaths.elements([htmlPaths.element("mark")])
+ }
+ ]
+ });
+ return converter.convertToHtml(run).then(function(result) {
+ assert.equal(result.value, "<mark>Hello.</mark>");
+ });
+});
+
+test('highlighted runs can be configured with style mapping for specific highlight color', function() {
+ var paragraph = new documents.Paragraph([
+ runOfText("Yellow", {highlight: "yellow"}),
+ runOfText("Red", {highlight: "red"})
+ ]);
+ var converter = new DocumentConverter({
+ styleMap: [
+ {
+ from: documentMatchers.highlight({color: "yellow"}),
+ to: htmlPaths.elements([htmlPaths.element("mark", {"class": "yellow"})])
+ },
+ {
+ from: documentMatchers.highlight({color: undefined}),
+ to: htmlPaths.elements([htmlPaths.element("mark")])
+ }
+ ]
+ });
+ return converter.convertToHtml(paragraph).then(function(result) {
+ assert.equal(result.value, '<p><mark class="yellow">Yellow</mark><mark>Red</mark></p>');
+ });
+});
+
+
test('run styles are converted to HTML if mapping exists', function() {
var run = runOfText("Hello.", {styleId: "Heading1Char", styleName: "Heading 1 Char"});
var converter = new DocumentConverter({
diff --git a/test/style-reader.tests.js b/test/style-reader.tests.js
index 93ddc79..79be1dd 100644
--- a/test/style-reader.tests.js
+++ b/test/style-reader.tests.js
@@ -209,6 +209,20 @@ test("styleReader.readDocumentMatcher", {
);
},
+ "reads highlight without color": function() {
+ assertDocumentMatcher(
+ "highlight",
+ documentMatchers.highlight()
+ );
+ },
+
+ "reads highlight with color": function() {
+ assertDocumentMatcher(
+ "highlight[color='yellow']",
+ documentMatchers.highlight({color: "yellow"})
+ );
+ },
+
"reads comment-reference": function() {
assertDocumentMatcher(
"comment-reference",
diff --git a/test/styles/document-matchers.tests.js b/test/styles/document-matchers.tests.js
index 5ce3f72..63a00a8 100644
--- a/test/styles/document-matchers.tests.js
+++ b/test/styles/document-matchers.tests.js
@@ -45,6 +45,26 @@ test("matchers for lists with index 0 do not match elements that are not lists",
assert.ok(!matcher.matches(new Paragraph()));
});
+test("highlight matcher does not match non-highlight elements", function() {
+ var matcher = documentMatchers.highlight();
+ assert.ok(!matcher.matches(new Paragraph()));
+});
+
+test("highlight matcher without color matches all highlight elements", function() {
+ var matcher = documentMatchers.highlight({});
+ assert.ok(matcher.matches({type: "highlight", color: "yellow"}));
+});
+
+test("highlight matcher with color matches highlight with that color", function() {
+ var matcher = documentMatchers.highlight({color: "yellow"});
+ assert.ok(matcher.matches({type: "highlight", color: "yellow"}));
+});
+
+test("highlight matcher with color does not match highlights with other colors", function() {
+ var matcher = documentMatchers.highlight({color: "yellow"});
+ assert.ok(!matcher.matches({type: "highlight", color: "red"}));
+});
+
function paragraphWithStyle(styleId, styleName) {
return new Paragraph([], {styleId: styleId, styleName: styleName});
}