Skip to content

Commit dac71d7

Browse files
committed
test: add test for setting-theme component
1 parent 8d16a53 commit dac71d7

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
'use strict'
2+
3+
const test = require('tap').test
4+
const View = require('../../../lib/views/components/setting-theme')
5+
const Theme = require('../../../lib/themes/theme')
6+
const common = require('../../common')
7+
const IRC = require('eyearesee-client')
8+
const Settings = IRC.Settings
9+
10+
test('SettingThemeSelect', (t) => {
11+
t.plan(29)
12+
const themes = new Map()
13+
themes.set('dusk.css', new Theme(null, '/dusk.css', 'dusk.css', true))
14+
themes.set('user.css', new Theme(null, '/user.css', 'user.css', false))
15+
16+
const defs = new Map([[ 'color', '#fff' ]])
17+
const target = {
18+
needsLayout: () => {
19+
t.pass('called target.needsLayout')
20+
}
21+
, settings: new Settings(defs)
22+
, themes: {
23+
themes: themes
24+
, load: (a, cb) => {
25+
t.pass('called themes.load()')
26+
cb()
27+
}
28+
, activate: (name) => {
29+
t.pass('called themes.activate()')
30+
}
31+
}
32+
}
33+
34+
const verify = common.VerifyNode(t)
35+
36+
const view = View(target)
37+
38+
target.settings.once('settingChanged', (key, orig, val) => {
39+
t.equal(key, 'theme.active', 'key')
40+
t.equal(orig, undefined, 'old value')
41+
t.equal(val, 'user.css', 'new value')
42+
})
43+
44+
const out = view.render({
45+
id: 'theme.active'
46+
, title: 'Theme'
47+
, note: 'Click reload to reload your themes.'
48+
})
49+
50+
verify(out, 'DIV', {
51+
className: 'form-group'
52+
}, 3, 'wrapper')
53+
54+
let kids = out.children
55+
const label = kids[0]
56+
verify(label, 'LABEL', {
57+
className: 'control-label'
58+
, attributes: {
59+
for: 'theme.active'
60+
}
61+
}, 1, 'label')
62+
63+
const select = kids[1]
64+
verify(select, 'SELECT', {
65+
className: 'form-control'
66+
}, 2, 'select')
67+
68+
const options = select.children
69+
const o1 = options[0]
70+
verify(o1, 'OPTION', {
71+
selected: true
72+
}, 1, 'option 1')
73+
74+
t.equal(o1.children[0].text, 'dusk.css', 'option 1 text')
75+
76+
const o2 = options[1]
77+
verify(o2, 'OPTION', {
78+
selected: false
79+
}, 1, 'option 2')
80+
81+
t.equal(o2.children[0].text, 'user.css', 'option 2 text')
82+
83+
select.properties.onchange({
84+
target: {
85+
value: 'user.css'
86+
}
87+
})
88+
89+
const p = kids[2]
90+
verify(p, 'P', {
91+
className: 'form-control-static'
92+
}, 2, 'p')
93+
94+
const txt = p.children[0]
95+
t.equal(txt.text, 'Click reload to reload your themes.', 'note text')
96+
97+
const reload = p.children[1]
98+
verify(reload, 'BUTTON', {
99+
tabindex: '-1'
100+
, attributes: {
101+
tabindex: '-1'
102+
}
103+
, className: 'btn btn-link'
104+
}, 1, 'reload button')
105+
106+
t.equal(reload.children[0].text, 'Reload', 'reload button text')
107+
108+
reload.properties.onclick({
109+
target: {
110+
blur: () => {
111+
t.pass('called blur on reload button')
112+
}
113+
}
114+
})
115+
})

0 commit comments

Comments
 (0)