-
Notifications
You must be signed in to change notification settings - Fork 304
/
Comment_spec.coffee
117 lines (93 loc) · 3.03 KB
/
Comment_spec.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'use strict'
describe 'CoreComment', ->
manager = null
beforeEach ->
manager = new CommentManager(document.createElement 'div')
it 'cannot initialize without parent', ->
expect(CoreComment).toThrow()
it 'initializes defaults from empty IComment', ->
comment = new CoreComment(manager)
expect(comment.mode).toBe 1
expect(comment.text).toBe ''
expect(comment.ttl).toBe 4000
expect(comment.dur).toBe 4000
expect(comment.movable).toBe true
expect(comment.color).toBe 0xffffff
expect(comment.size).toBe 25
expect(comment.alpha).toBe 1
expect(comment.border).toBe false
expect(comment.align).toBe 0
expect(comment.parent).toBe manager
it 'initializes from parameterized IComment', ->
config =
stime: 100
mode: 2
dur: 5000
text: 'FooBar'
color: 0xf0f0f0
size: 24
border: true
opacity: 0.5
font: 'SimSun'
comment = new CoreComment(manager, config)
'stime mode dur text color size border'.split(' ').forEach (property) ->
expect(comment[property]).toBe config[property]
expect(comment.alpha).toBe config.opacity
'time update finish'.split(' ').forEach (method) ->
it "has #{method}", ->
comment = new CoreComment(manager)
expect(typeof comment[method]).toBe 'function'
describe '.time', ->
comment = null
beforeEach ->
config =
dur: 1000
comment = new CoreComment(manager, config)
it 'ages comment', ->
comment.time 100
expect(comment.ttl).toBe (comment.dur - 100)
it 'calls update when movable', ->
spy = sinon.spy comment, 'update'
comment.time 100
expect(spy).toHaveBeenCalled true
it 'calls finish if expired', ->
spy = sinon.spy comment, 'finish'
# Create the DOM and add it to the manager
comment.init()
comment.parent.stage.appendChild comment.dom
comment.time 2000
expect(spy).toHaveBeenCalled true
describe '.invalidate', ->
comment = null
beforeEach ->
config =
dur: 1000
comment = new CoreComment(manager, config)
it 'invalidates comment cache data', ->
comment.invalidate()
expect(comment._x).toBe null
expect(comment._y).toBe null
expect(comment._width).toBe null
expect(comment._height).toBe null
describe '.update', ->
it 'calls animate', ->
comment = new CoreComment(manager)
spy = sinon.spy comment, 'animate'
comment.update()
expect(spy).toHaveBeenCalled true
describe '.LINEAR', ->
it 'does linear interpolation', ->
v = CoreComment.LINEAR(400, 1, 1, 4000)
expect(v).toBe 1.1
describe 'ScrollComment', ->
manager = null
beforeEach ->
manager = new CommentManager(document.createElement 'div')
it 'cannot initialize without parent', ->
expect(ScrollComment).toThrow()
it 'applies scaling for scroll comments', ->
manager.options.scroll.scale = 10
config =
dur: 4000
comment = new ScrollComment(manager, config)
expect(comment.dur).toBe 40000