forked from mwilliamson/mammoth.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml-generator.tests.js
81 lines (70 loc) · 3.05 KB
/
html-generator.tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var assert = require("assert");
var test = require("./testing").test;
var HtmlGenerator = require("../lib/html-generator").HtmlGenerator;
var htmlPaths = require("../lib/html-paths");
describe('HtmlGenerator', function() {
test('generates empty string when newly created', function() {
var generator = new HtmlGenerator();
return assert.equal("", generator.asString());
});
test('HTML-escapes text', function() {
var generator = new HtmlGenerator();
generator.text("<");
return assert.equal(generator.asString(), "<");
});
test('asString closes all elements', function() {
var generator = new HtmlGenerator();
generator.satisfyPath(htmlPaths.elements(["p", "span"]));
generator.text("Hello!");
generator.closeAll();
return assert.equal(generator.asString(), "<p><span>Hello!</span></p>");
});
test('elements with no text are not generated', function() {
var generator = new HtmlGenerator();
generator.satisfyPath(htmlPaths.elements(["p", "span"]));
generator.closeAll();
return assert.equal(generator.asString(), "");
});
test('generates empty string if text is empty string', function() {
var generator = new HtmlGenerator();
generator.satisfyPath(htmlPaths.elements(["p", "span"]));
generator.text("");
generator.closeAll();
return assert.equal(generator.asString(), "");
});
test('can leave some HTML elements for next style', function() {
var generator = new HtmlGenerator();
var listPath = htmlPaths.elements([
htmlPaths.element("ul", {}, {fresh: false}),
htmlPaths.element("li", {}, {fresh: true})
]);
generator.satisfyPath(listPath);
generator.text("Apple");
generator.satisfyPath(listPath);
generator.text("Banana");
generator.closeAll();
return assert.equal(generator.asString(), "<ul><li>Apple</li><li>Banana</li></ul>");
});
test('renders class attribute of elements', function() {
var generator = new HtmlGenerator();
generator.satisfyPath(htmlPaths.elements([
htmlPaths.element("p", {"class": "tip"})
]));
generator.text("Hello!");
generator.closeAll();
return assert.equal(generator.asString(), '<p class="tip">Hello!</p>');
});
test('attribute values are escaped', function() {
var generator = new HtmlGenerator();
generator.selfClosing({tagName: "br", attributes: {"data-blah": "<"}});
return assert.equal(generator.asString(), '<br data-blah="<" />');
});
test('appendPath does not close currently-open elements', function() {
var generator = new HtmlGenerator();
generator.satisfyPath(htmlPaths.elements(["strong"]));
generator.appendPath(htmlPaths.elements(["em"]));
generator.text("Hello!");
generator.closeAll();
return assert.equal(generator.asString(), "<strong><em>Hello!</em></strong>");
});
});