forked from lookback/meteor-bodyclass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
body-class-test.coffee
75 lines (52 loc) · 1.8 KB
/
body-class-test.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
Should = should()
describe 'BodyClass', ->
beforeAll ->
# Simple stubs
window.Router = {}
Router.current = ->
lookupTemplate: ->
'template'
lookupOption: ->
'layout'
_layout:
_template: 'layout'
afterEach ->
$('body, html').removeClass()
it 'should be available', ->
BodyClass.should.be.defined
describe 'config', ->
it 'should be able to use an arbitrary element', ->
BodyClass.config(element: 'html').add 'foo'
$('html').hasClass('foo').should.be.true
# Restore
BodyClass.settings.element = 'body'
describe 'run', ->
it 'should add a classes of the current template and layout', ->
BodyClass.run()
$('body').hasClass('layout template').should.be.true
it 'should take additional classes as an array', ->
BodyClass.run(classes: ['foo', 'bar'])
$('body').hasClass('layout template foo bar').should.be.true
describe 'cleanup', ->
it 'should clean up router classes', ->
BodyClass.cleanup()
$('body').hasClass('layout template').should.be.false
describe 'add', ->
it 'should be able to add a class', ->
BodyClass.add 'foo'
$('body').hasClass('foo').should.be.true
it 'should be able to add an array of classes', ->
BodyClass.add ['foo', 'bar']
$('body').hasClass('foo bar').should.be.true
it 'should be able to add a function', ->
BodyClass.add -> 'foo'
$('body').hasClass('foo').should.be.true
it 'should be able run function reactively', ->
Session.set 'foo', 'bar'
BodyClass.add ->
Session.get 'foo'
$('body').hasClass('bar').should.be.true
Session.set 'foo', 'baz'
Tracker.flush()
$('body').hasClass('baz').should.be.true
$('body').hasClass('bar').should.be.false