honkit
Version:
HonKit is building beautiful books using Markdown.
72 lines (71 loc) • 3.83 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const immutable_1 = __importDefault(require("immutable"));
const html_1 = require("@honkit/html");
const glossaryEntry_1 = __importDefault(require("../../../models/glossaryEntry"));
const annotateText_1 = __importDefault(require("../annotateText"));
describe("annotateText", () => {
const entries = immutable_1.default.List([
new glossaryEntry_1.default({ name: "Word" }),
new glossaryEntry_1.default({ name: "Multiple Words" }),
new glossaryEntry_1.default({ name: ".MD files" }),
new glossaryEntry_1.default({ name: "Brancaleone von Andalò" }),
new glossaryEntry_1.default({ name: "Henry (VII)" }),
]);
test("should annotate text", () => {
const $ = (0, html_1.loadHtml)("<p>This is a word, and multiple words</p>");
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
const links = $("a");
expect(links.length).toBe(2);
const word = $(links.get(0));
expect(word.attr("href")).toBe("/GLOSSARY.md#word");
expect(word.text()).toBe("word");
expect(word.hasClass("glossary-term")).toBeTruthy();
const words = $(links.get(1));
expect(words.attr("href")).toBe("/GLOSSARY.md#multiple-words");
expect(words.text()).toBe("multiple words");
expect(words.hasClass("glossary-term")).toBeTruthy();
});
test("should annotate text with regardless of glossary order", () => {
const $ = (0, html_1.loadHtml)("<p>This is multiple words, and another word.</p>");
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
const links = $("a");
expect(links.length).toBe(2);
const word = $(links.get(0));
expect(word.attr("href")).toBe("/GLOSSARY.md#multiple-words");
expect(word.text()).toBe("multiple words");
expect(word.hasClass("glossary-term")).toBeTruthy();
const words = $(links.get(1));
expect(words.attr("href")).toBe("/GLOSSARY.md#word");
expect(words.text()).toBe("word");
expect(words.hasClass("glossary-term")).toBeTruthy();
});
test("should not annotate scripts", () => {
const $ = (0, html_1.loadHtml)("<script>This is a word, and multiple words</script>");
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
expect($("a").length).toBe(0);
});
test('should not annotate when has class "no-glossary"', () => {
const $ = (0, html_1.loadHtml)('<p class="no-glossary">This is a word, and multiple words</p>');
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
expect($("a").length).toBe(0);
});
test('should annotate terms with starting dots', () => {
const $ = (0, html_1.loadHtml)('<p>I write in .MD files when documenting.</p>');
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
expect($("a").length).toBe(1);
});
test('should annotate terms with starting non-English chars', () => {
const $ = (0, html_1.loadHtml)('<p>Der Papst gehört nicht nach Anagni oder Lyon, nicht nach Perugia oder Assisi, sondern nach Rom.« Ein kraftvoller Mann gab den Römern diese Sprache ein, Brancaleone von Andalò, ihr damaliger Senator.</p>');
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
expect($("a").length).toBe(1);
});
test('should annotate terms with parens at start or end', () => {
const $ = (0, html_1.loadHtml)('<p>Tell me everything you know about Henry (VII) and his reign.</p>');
(0, annotateText_1.default)(entries, "GLOSSARY.md", $);
expect($("a").length).toBe(1);
});
});