Skip to content
This repository was archived by the owner on Jul 11, 2019. It is now read-only.

Commit 5c7adfd

Browse files
author
ekmartin
committed
Add ghlinks, paragraph, highlight, timeago, markdown and merge tests
1 parent 0e4a7d9 commit 5c7adfd

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

test/index.js

+99
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var test = require('tape')
22
var richMessage = require('../')
3+
var mergeMessages = richMessage.mergeMessages
34

45
test('link replacement', function (t) {
56
var message = {
@@ -41,3 +42,101 @@ test('anon avatars', function (t) {
4142
t.equal(output.avatar, 'static/cat.png')
4243
t.end()
4344
})
45+
46+
test('github links', function (t) {
47+
var message = {
48+
text: 'cats isaacs/npm#1234',
49+
username: 'cat',
50+
timestamp: Date.now()
51+
}
52+
53+
var output = richMessage(message, 'other_cat')
54+
var expected = '<div><p>' +
55+
'cats <a href="https://github.com/isaacs/npm/issues/1234">' +
56+
'isaacs/npm#1234</a>' +
57+
'</p><p></p></div>'
58+
59+
t.equal(output.html, expected)
60+
t.end()
61+
})
62+
63+
test('newlines -> paragraphs', function (t) {
64+
var message = {
65+
text: 'cat\ncat',
66+
username: 'cat',
67+
timestamp: Date.now()
68+
}
69+
70+
var output = richMessage(message, 'other_cat')
71+
var expected = '<div><p>' +
72+
'cat<p></p>cat' +
73+
'</p><p></p></div>'
74+
75+
t.equal(output.html, expected)
76+
t.end()
77+
})
78+
79+
test('username highlight', function (t) {
80+
var message = {
81+
text: 'cat',
82+
username: 'cat',
83+
timestamp: Date.now()
84+
}
85+
86+
var output = richMessage(message, 'cat')
87+
var expected = '<div class="highlight"><p>' +
88+
'cat' +
89+
'</p><p></p></div>'
90+
91+
t.equal(output.html, expected)
92+
t.end()
93+
})
94+
95+
test('timeago', function (t) {
96+
var message = {
97+
text: 'cat',
98+
username: 'cat',
99+
timestamp: 0
100+
}
101+
102+
var output = richMessage(message, 'cat')
103+
t.equal(output.timeago, '01/01/1970')
104+
t.end()
105+
})
106+
107+
test('markdown render', function (t) {
108+
var message = {
109+
text: '`cat` **cat**',
110+
username: 'cat',
111+
timestamp: Date.now()
112+
}
113+
114+
var output = richMessage(message, 'other_cat')
115+
var expected = '<div><p>' +
116+
'<code>cat</code> <strong>cat</strong>' +
117+
'</p><p></p></div>'
118+
119+
t.equal(output.html, expected)
120+
t.end()
121+
})
122+
123+
test('merge messages', function (t) {
124+
var message1 = {
125+
text: 'cat1',
126+
html: '<p>cat1</p>'
127+
}
128+
129+
var message2 = {
130+
text: 'cat2',
131+
html: '<p>cat2</p>'
132+
}
133+
134+
var output = mergeMessages(message1, message2)
135+
var expected = {
136+
text: 'cat1\ncat2',
137+
html: '<p>cat1</p><p></p><p>cat2</p>'
138+
}
139+
140+
t.deepEqual(output, expected)
141+
t.end()
142+
})

0 commit comments

Comments
 (0)