-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
130 lines (92 loc) · 2.95 KB
/
test.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import 'utilise'
import 'browserenv'
import test from 'tape'
import scope from 'cssscope'
import input from './ux-input'
const style = window.getComputedStyle
, o = once(document.body)('.container', 1)
once(document.head)
('style', 1)
.html(scope(file('dist/ux-input.css'), 'ux-input'))
test('unit test - label', t => {
t.plan(1)
const host = o('ux-input', 1).node()
input.call(host, { label: 'foo' })
t.equal(host.outerHTML, stripws`
<ux-input>
<input placeholder="foo">
<label>foo</label>
</ux-input>
`, 'basic structure')
o.html('')
})
test('unit test - value', t => {
t.plan(2)
const host = o('ux-input', 1).node()
input.call(host, { value: 'foo' })
t.equal(host.outerHTML, stripws`
<ux-input class="is-active">
<input>
<label></label>
</ux-input>
`, 'basic structure')
t.equal(raw('input', host).value, 'foo', 'input value')
o.html('')
})
test('unit test - value', t => {
t.plan(2)
const host = o('ux-input', 1).node()
input.call(host, { value: 'foo' })
t.equal(host.outerHTML, stripws`
<ux-input class="is-active">
<input>
<label></label>
</ux-input>
`, 'basic structure')
t.equal(raw('input', host).value, 'foo', 'input value')
o.html('')
})
test('unit test - name', t => {
t.plan(1)
const host = o('ux-input', 1).node()
input.call(host, { name: 'foo' })
t.ok(includes('<ux-input name="foo">')(host.outerHTML), 'name attr')
o.html('')
})
test('unit test - optional', t => {
t.plan(1)
const host = o('ux-input', 1).node()
input.call(host, { optional: true })
t.ok(includes('<ux-input class="is-optional">')(host.outerHTML), 'optional attr')
o.html('')
})
test('unit test - focused', t => {
const host = o('ux-input', 1).node()
time( 0, d => input.call(host, { focused: false }))
time( 50, d => t.equal(host.className, '', 'blur class'))
time(100, d => t.equal(style(raw('label', host)).color, 'rgb(187, 187, 187)', 'blur style'))
time(150, d => input.call(host, { focused: true }))
time(200, d => t.equal(host.className, 'is-focused', 'focus class'))
time(400, d => t.equal(style(raw('label', host)).color, 'rgb(41, 142, 234)', 'focus style'))
time(450, d => { o.html(''), t.end() })
})
test('event test - focus/blur event', t => {
const host = tdraw(o('ux-input', 1), input)
, el = host('input')
time( 0, d => el.emit('focus'))
time( 50, d => t.equal(host.node().className, 'is-focused', 'focus event'))
time(100, d => el.emit('blur'))
time(150, d => t.equal(host.node().className, '', 'blur event'))
time(200, d => { o.html(''), t.end() })
})
test('event test - keyup event', t => {
t.plan(3)
const host = tdraw(o('ux-input', 1), input)
, el = host('input')
host.on('change', value => t.equal(value, 'foo', 'change event'))
el.property('value', 'foo')
.emit('keyup')
t.equal(host.node().value, 'foo', 'host value')
t.equal(el.node().value, 'foo', 'input value')
o.html('')
})