forked from yakyak/yakyak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-userinput.coffee
92 lines (77 loc) · 3.23 KB
/
test-userinput.coffee
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
{ MessageActionType } = require 'hangupsjs'
viewstate = require '../src/ui/models/viewstate'
userinput = require '../src/ui/models/userinput'
describe 'userinput', ->
describe 'buildChatMessage', ->
it 'takes a text and does good', ->
sender = { firstName: 'John' }
viewstate.selectedConv = 'c123'
msg = userinput.buildChatMessage sender, 'foo'
eql msg.conv_id, 'c123'
eql msg.image_id, undefined
eql msg.message_action_type, [[MessageActionType.NONE, '']]
eql msg.segs, [[0,'foo']]
eql msg.segsj, [{text:'foo', type:'TEXT'}]
assert.isNotNull msg.client_generated_id
assert.isNotNull msg.ts
eql msg.otr, 2
it 'recognizes /me messages', ->
sender = { first_name: 'John' }
msg = userinput.buildChatMessage sender, '/me says hello'
eql msg.message_action_type, [[MessageActionType.ME_ACTION, '']]
eql msg.segs, [[0,'John says hello']]
eql msg.segsj, [{text:'John says hello', type:'TEXT'}]
describe 'parse', ->
mb = null
coll = ""
beforeEach ->
coll = ""
mb = {
text: spy -> coll += "t"
link: spy -> coll += "l"
linebreak: spy -> coll += "n"
}
it 'does text', ->
userinput.parse mb, 'foo'
eql mb.text.args, [['foo']]
eql coll, 't'
it 'does text with whitespace', ->
userinput.parse mb, ' \n \n foo'
eql mb.text.args, [[' '],[' '],[' foo']]
eql mb.linebreak.args, [[],[]]
eql coll, 'tntnt'
it 'does \\n linebreaks', ->
userinput.parse mb, 'foo\nbar'
eql mb.linebreak.args, [[]]
eql mb.text.args, [['foo'],['bar']]
eql coll, 'tnt'
it 'does \\r\\n linebreaks', ->
userinput.parse mb, 'foo\r\nbar'
eql mb.linebreak.args, [[]]
eql mb.text.args, [['foo'],['bar']]
eql coll, 'tnt'
it 'does not ignore last linebreak', ->
userinput.parse mb, 'foo\n'
eql mb.text.args, [['foo']]
eql mb.linebreak.args, [[]]
eql coll, 'tn'
it 'does not ignore many last linebreak', ->
userinput.parse mb, 'foo \n\n\n'
eql mb.text.args, [['foo ']]
eql mb.linebreak.args, [[],[],[]]
eql coll, 'tnnn'
it 'identifies links only', ->
userinput.parse mb, 'http://www.abc.com'
eql mb.link.args, [['http://www.abc.com','http://www.abc.com']]
eql coll, 'l'
it 'finds links in text', ->
userinput.parse mb, 'a http://www.abc.com b'
eql mb.text.args, [['a '],[' b']]
eql mb.link.args, [['http://www.abc.com','http://www.abc.com']]
eql coll, 'tlt'
it 'finds multiple links in text', ->
userinput.parse mb, 'a http://www.abc.com b https://foo.bar c'
eql mb.text.args, [['a '],[' b '],[' c']]
eql mb.link.args, [['http://www.abc.com','http://www.abc.com'],
['https://foo.bar','https://foo.bar']]
eql coll, 'tltlt'