-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathtests.js
117 lines (97 loc) · 5.45 KB
/
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
define(["pat-markdown"], function(Pattern) {
describe("pat-markdown", function() {
beforeEach(function() {
$("<div/>", {id: "lab"}).appendTo(document.body);
});
afterEach(function() {
$("#lab").remove();
});
describe("when initialized", function(){
it("replaces the DOM element with the rendered Markdown content.", function() {
var $el = $('<p class="pat-markdown"></p>');
$el.appendTo("#lab");
spyOn(Pattern.prototype, "render").and.returnValue($("<p>Rendering</p>"));
Pattern.init($el);
expect($("#lab").html()).toBe("<p>Rendering</p>");
});
it("does not replace the DOM element if it doesn't have the pattern trigger", function() {
var $el = $('<p></p>');
$el.appendTo("#lab");
spyOn(Pattern.prototype, "render").and.returnValue($("<p>Rendering</p>"));
Pattern.init($el);
expect($("#lab").html()).toBe("<p></p>");
});
it("uses content for non-input elements", function() {
var $el = $('<p class="pat-markdown"/>').text("This is markdown");
$el.appendTo("#lab");
var spy_render = spyOn(Pattern.prototype, "render").and.returnValue($("<p/>"));
Pattern.init($el);
expect(spy_render).toHaveBeenCalledWith("This is markdown");
});
it("uses value for input elements", function() {
var $el = $('<textarea class="pat-markdown"/>').val("This is markdown");
$el.appendTo("#lab");
var spy_render = spyOn(Pattern.prototype, "render").and.returnValue($("<p/>"));
Pattern.init($el);
expect(spy_render).toHaveBeenCalledWith("This is markdown");
});
});
describe("when rendering", function(){
it("wraps rendering in a div", function() {
var $rendering = Pattern.prototype.render("*This is markdown*");
expect($rendering[0].tagName).toBe("DIV");
});
it("converts markdown into HTML", function() {
var $rendering = Pattern.prototype.render("*This is markdown*");
expect($rendering.html()).toBe("<p><em>This is markdown</em></p>");
});
it("removes whitespace from start and end of text", function() {
// If text is not removed, the rendering breaks and ouputs this instead:
// '<pre class="pat-syntax-highlight" tabindex="0"><code data-inner="1"> *This is markdown* </code></pre>'
var $rendering = Pattern.prototype.render(" *This is markdown* ");
expect($rendering.html()).toBe("<p><em>This is markdown</em></p>");
});
});
describe("Session extraction", function() {
it("Unknown section", function() {
expect(Pattern.prototype.extractSection("## My title\n\nContent", "Other title")).toBe(null);
});
it("Last hash-section", function() {
expect(Pattern.prototype.extractSection("## My title\n\nContent", "My title"))
.toBe("## My title\n\nContent");
});
it("Hash-section with following section at same level ", function() {
expect(Pattern.prototype.extractSection("## My title\n\nContent\n## Next section\n", "My title"))
.toBe("## My title\n\nContent\n");
});
it("Hash-section with following section at lower level ", function() {
expect(Pattern.prototype.extractSection("## My title\n\nContent\n### Next section\n", "My title"))
.toBe("## My title\n\nContent\n### Next section\n");
});
it("Double underscore section", function() {
expect(Pattern.prototype.extractSection("My title\n=======\nContent", "My title"))
.toBe("My title\n=======\nContent");
});
it("Double underscore section with following section at same level", function() {
expect(Pattern.prototype.extractSection("My title\n=======\nContent\n\nNext\n====\n", "My title"))
.toBe("My title\n=======\nContent\n\n");
});
it("Double underscore section with following section at lower level", function() {
expect(Pattern.prototype.extractSection("My title\n=======\nContent\n\nNext\n----\n", "My title"))
.toBe("My title\n=======\nContent\n\nNext\n----\n");
});
it("Single underscore section", function() {
expect(Pattern.prototype.extractSection("My title\n-------\nContent", "My title"))
.toBe("My title\n-------\nContent");
});
it("Single underscore section with following section at same level", function() {
expect(Pattern.prototype.extractSection("My title\n-------\nContent\n\nNext\n----\n", "My title"))
.toBe("My title\n-------\nContent\n\n");
});
it("Single underscore section with following section at higher level", function() {
expect(Pattern.prototype.extractSection("My title\n-------\nContent\n\nNext\n====\n", "My title"))
.toBe("My title\n-------\nContent\n\n");
});
});
});
});