Skip to content

Commit f4b31e7

Browse files
committed
Add more test
1 parent 112fc8b commit f4b31e7

1 file changed

Lines changed: 75 additions & 3 deletions

File tree

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,84 @@
11
'use strict'
22
describe 'CommentManager', ->
3-
manager = null
3+
manager = stage = cmt = c1 = c2 = c3 = c4 = c5 = null
44

55
describe 'instance API', ->
66
beforeEach ->
7-
manager = new CommentManager(window)
7+
c1 = stime: 1
8+
c2 = stime: 2, date: '2014-07-12T04:35:55.624Z'
9+
c3 =
10+
stime: 2
11+
date: '2014-07-12T04:35:55.626Z'
12+
dbid: '53c0bb2b6465625061b40698'
13+
c4 =
14+
stime: 2
15+
date: '2014-07-12T04:35:55.626Z'
16+
dbid: '53c0bb2b6465625061b40700'
17+
c5 =
18+
stime: 2
19+
date: '2014-07-12T04:35:55.626Z'
20+
dbid: '53c0bb2b6465625061b40700'
21+
cmt =
22+
stime: 124900
23+
color: '#fff'
24+
mode: 1
25+
size: 25
26+
hash: '53c0bb2b6465625061b40700'
27+
date: '2014-07-12T04:35:55.624Z'
28+
position: 13600
29+
stage = document.createElement 'DIV'
30+
manager = new CommentManager(stage)
31+
manager.init()
32+
33+
'addEventListener clear dispatchEvent finish init
34+
insert load onTimerEvent rescale seek send sendComment
35+
setBounds start stop time validate'.split(/\s/).forEach (method)->
836

9-
'load start stop insert send clear time'.split(' ').forEach (method)->
1037
it "has method: '#{method}'", ->
1138
expect(typeof manager[method]).toBe 'function'
1239

40+
it 'sets the stage', ->
41+
expect(manager.stage).toBe stage
42+
43+
describe '.load', ->
44+
it 'loads specific comment' , ->
45+
expect(manager.timeline).toEqual []
46+
manager.load [cmt]
47+
expect(manager.timeline).toEqual [cmt]
48+
49+
it 'sorts the comments', ->
50+
manager.load [ c5, c2, c4, c1, c3 ]
51+
expect(manager.timeline).toEqual [c1, c2, c3, c4, c5]
52+
53+
describe '.send', ->
54+
it 'sends to runline' , ->
55+
expect(manager.runline.length).toBe 0
56+
manager.send cmt
57+
expect(manager.runline.length).toBe 1
58+
59+
describe '.start', ->
60+
it 'starts the timer', ->
61+
manager.start()
62+
manager.start()
63+
# TODO: figure out how to test the timer
64+
# maybe just add spy on window.setInterval
65+
66+
describe '.stop', ->
67+
it 'stops the timer', ->
68+
manager.stop()
69+
# TODO: figure out how to test the timer
70+
# maybe just add spy on window.clearInterval
71+
72+
describe '.clear', ->
73+
it 'clears', ->
74+
manager.send cmt
75+
expect(manager.runline.length).toBe 1
76+
manager.clear()
77+
expect(manager.runline.length).toBe 0
78+
79+
describe '.insert', ->
80+
it 'inserts to right position', ->
81+
manager.load [c3, c5]
82+
expect(manager.timeline).toEqual [c3, c5]
83+
manager.insert c4
84+
expect(manager.timeline).toEqual [c3, c4 , c5]

0 commit comments

Comments
 (0)