|
1 | 1 | 'use strict' |
2 | | - |
3 | 2 | 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' |
| 47 | + |
| 48 | + describe '.time', -> |
| 49 | + comment = null |
| 50 | + |
| 51 | + beforeEach -> |
| 52 | + config = |
| 53 | + dur: 1000 |
| 54 | + comment = new CoreComment(manager, config) |
| 55 | + |
| 56 | + it 'ages comment', -> |
| 57 | + comment.time 100 |
| 58 | + expect(comment.ttl).toBe (comment.dur - 100) |
| 59 | + |
| 60 | + it 'calls update when movable', -> |
| 61 | + spy = sinon.spy comment, 'update' |
| 62 | + comment.time 100 |
| 63 | + expect(spy).toHaveBeenCalled true |
| 64 | + |
| 65 | + it 'calls finish if expired', -> |
| 66 | + spy = sinon.spy comment, 'finish' |
| 67 | + |
| 68 | + # Create the DOM and add it to the manager |
| 69 | + comment.init() |
| 70 | + comment.parent.stage.appendChild comment.dom |
| 71 | + |
| 72 | + comment.time 2000 |
| 73 | + expect(spy).toHaveBeenCalled true |
| 74 | + |
| 75 | + describe '.invalidate', -> |
| 76 | + comment = null |
| 77 | + |
| 78 | + beforeEach -> |
| 79 | + config = |
| 80 | + dur: 1000 |
| 81 | + comment = new CoreComment(manager, config) |
| 82 | + |
| 83 | + it 'invalidates comment cache data', -> |
| 84 | + comment.invalidate() |
| 85 | + expect(comment._x).toBe null |
| 86 | + expect(comment._y).toBe null |
| 87 | + expect(comment._width).toBe null |
| 88 | + expect(comment._height).toBe null |
| 89 | + |
| 90 | + describe '.update', -> |
| 91 | + it 'calls animate', -> |
| 92 | + comment = new CoreComment(manager) |
| 93 | + spy = sinon.spy comment, 'animate' |
| 94 | + comment.update() |
| 95 | + expect(spy).toHaveBeenCalled true |
| 96 | + |
| 97 | + describe '.LINEAR', -> |
| 98 | + it 'does linear interpolation', -> |
| 99 | + v = CoreComment.LINEAR(400, 1, 1, 4000) |
| 100 | + expect(v).toBe 1.1 |
5 | 101 |
|
6 | 102 | describe 'ScrollComment', -> |
7 | | - xit('TODO: add some examples to (or delete) it') |
| 103 | + manager = null |
| 104 | + |
| 105 | + beforeEach -> |
| 106 | + manager = new CommentManager(document.createElement 'div') |
| 107 | + |
| 108 | + it 'cannot initialize without parent', -> |
| 109 | + expect(ScrollComment).toThrow() |
| 110 | + |
| 111 | + it 'applies scaling for scroll comments', -> |
| 112 | + manager.options.scroll.scale = 10 |
| 113 | + config = |
| 114 | + dur: 4000 |
| 115 | + comment = new ScrollComment(manager, config) |
| 116 | + expect(comment.dur).toBe 40000 |
| 117 | + |
0 commit comments