Skip to content

Commit adf7525

Browse files
committed
many tests. wow.
1 parent f8b1651 commit adf7525

File tree

2 files changed

+93
-8
lines changed

2 files changed

+93
-8
lines changed

spec/CommentCoreLibrary_spec.coffee

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,37 @@ describe 'CommentManager', ->
9090
expect(manager.timeline).toEqual [c3, c5]
9191
manager.insert c4
9292
expect(manager.timeline).toEqual [c3, c4 , c5]
93-
93+
94+
describe '.setBounds', ->
95+
beforeEach ->
96+
manager.stage.style.width = '640px'
97+
manager.stage.style.width = '480px'
98+
99+
it 'updates width and height', ->
100+
manager.setBounds()
101+
expect(manager.width).toEqual stage.offsetWidth
102+
expect(manager.height).toEqual stage.offsetHeight
103+
104+
it 'dispatches resize event', ->
105+
callback = sinon.spy()
106+
manager.addEventListener 'resize', callback
107+
manager.setBounds()
108+
expect(callback).toHaveBeenCalled true
109+
110+
it 'sets bounds on comment space allocators', ->
111+
spies = {}
112+
for allocatorName, allocator of manager.csa
113+
spies[allocatorName] = sinon.spy allocator, 'setBounds'
114+
manager.setBounds()
115+
for allocatorName, spy of spies
116+
expect(spy).toHaveBeenCalledWith stage.offsetWidth, stage.offsetHeight
117+
94118
describe '.addEventListener .dispatchEvent', ->
95119
it 'add one event listener', ->
96-
hasDispatchedEvent = false
97-
manager.addEventListener 'myCustomEvent', ->
98-
hasDispatchedEvent = true
120+
callback = sinon.spy()
121+
manager.addEventListener 'myCustomEvent', callback
99122
manager.dispatchEvent 'myCustomEvent'
100-
expect(hasDispatchedEvent).toBe true
123+
expect(callback).toHaveBeenCalled true
101124

102125
it 'add multiple event listeners', ->
103126
dispatchedEventId = 0
@@ -107,3 +130,9 @@ describe 'CommentManager', ->
107130
dispatchedEventId = 2
108131
manager.dispatchEvent 'myCustomEvent'
109132
expect(dispatchedEventId).toBe 2
133+
134+
it 'dispatch event works with data', ->
135+
callback = sinon.spy()
136+
manager.addEventListener 'myCustomEvent', callback
137+
manager.dispatchEvent 'myCustomEvent', 'foo'
138+
expect(callback).toHaveBeenCalledWith 'foo'

spec/core/Comment_spec.coffee

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,63 @@
11
'use strict'
2-
32
describe 'CoreComment', ->
4-
xit('TODO: add some examples to (or delete) it')
3+
manager = null
4+
5+
beforeEach ->
6+
manager = new CommentManager(document.createElement 'div')
7+
8+
it 'cannot initialize without parent', ->
9+
expect(CoreComment).toThrow()
10+
11+
it 'initializes defaults from empty IComment', ->
12+
comment = new CoreComment(manager)
13+
expect(comment.mode).toBe 1
14+
expect(comment.text).toBe ''
15+
expect(comment.ttl).toBe 4000
16+
expect(comment.dur).toBe 4000
17+
expect(comment.movable).toBe true
18+
expect(comment.color).toBe 0xffffff
19+
expect(comment.size).toBe 25
20+
expect(comment.alpha).toBe 1
21+
expect(comment.border).toBe false
22+
expect(comment.align).toBe 0
23+
expect(comment.parent).toBe manager
24+
25+
it 'initializes from parameterized IComment', ->
26+
config =
27+
stime: 100
28+
mode: 2
29+
dur: 5000
30+
text: 'FooBar'
31+
color: 0xf0f0f0
32+
size: 24
33+
border: true
34+
opacity: 0.5
35+
font: 'SimSun'
36+
comment = new CoreComment(manager, config)
37+
38+
'stime mode dur text color size border'.split(' ').forEach (property) ->
39+
expect(comment[property]).toBe config[property]
40+
41+
expect(comment.alpha).toBe config.opacity
42+
43+
'time update finish'.split(' ').forEach (method) ->
44+
it "has #{method}", ->
45+
comment = new CoreComment(manager)
46+
expect(typeof comment[method]).toBe 'function'
547

648
describe 'ScrollComment', ->
7-
xit('TODO: add some examples to (or delete) it')
49+
manager = null
50+
51+
beforeEach ->
52+
manager = new CommentManager(document.createElement 'div')
53+
54+
it 'cannot initialize without parent', ->
55+
expect(ScrollComment).toThrow()
56+
57+
it 'applies scaling for scroll comments', ->
58+
manager.options.scroll.scale = 10
59+
config =
60+
dur: 4000
61+
comment = new ScrollComment(manager, config)
62+
expect(comment.dur).toBe 40000
63+

0 commit comments

Comments
 (0)