-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-interaction.test.html
145 lines (118 loc) · 3.68 KB
/
user-interaction.test.html
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<script src="../bower_components/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../bower_components/web-component-tester/browser.js"></script>
<script src="../mocha-extensions.js"></script>
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="../oo-test-helpers.html">
<test-fixture id="button-fixture">
<template>
<paper-button raised>click me</paper-button>
</template>
</test-fixture>
<test-fixture id="items-fixture">
<template>
<paper-listbox>
<paper-item class="item-1">
<span>first option</span>
<paper-icon-button icon="close"></paper-icon-button>
</paper-item>
<paper-item class="item-2">
<span>second option</span>
<paper-icon-button icon="close"></paper-icon-button>
</paper-item>
</paper-listbox>
</template>
</test-fixture>
<style>
paper-item paper-icon-button {
opacity: 0.0;
transition: 0.2s ease-out;
}
paper-item:hover paper-icon-button {
opacity: 0.5;
}
paper-item:hover paper-icon-button:hover {
opacity: 1.0;
}
</style>
<script>
suite("user-interaction", () => {
suite("button", () => {
let button
setup(() => {
button = fixture("button-fixture")
})
test("can be clicked", done => {
button.addEventListener("click", () => {
done()
})
MockInteractions.tap(button)
})
test("can be pushed with key", done => {
button.addEventListener("keydown", () => {
done()
})
MockInteractions.pressEnter(button)
})
test("can be hovered", () => {
const eventSpy = sinon.spy()
button.addEventListener("mouseover", eventSpy)
// when:
MockInteractions.mouseover(button)
// then:
expect(eventSpy.callCount).to.eql(1)
expect(eventSpy.args).to.have.length(1)
})
// test.skip("can be ...", () => {
// MockInteractions.focus(button)
// MockInteractions.blur(button)
// MockInteractions.move(
// button,
// { x: 0, y: 0 },
// MockInteractions.middleOfNode(button)
// )
// })
})
suite("items", () => {
let items
setup(() => {
// given:
items = fixture("items-fixture")
})
test("first option can be selected", done => {
const item1 = items.querySelector(".item-1")
const item2 = items.querySelector(".item-2")
// when:
Polymer.Base.async(() => {
MockInteractions.click(item1)
MockInteractions.focus(item1)
})
// then:
flush(() => {
expect(items.selected).to.eql(0)
expect(item1.focused).to.be.true
expect(item2.focused).to.be.false
done()
})
})
test("second option can be selected", done => {
const item1 = items.querySelector(".item-1")
const item2 = items.querySelector(".item-2")
// when:
MockInteractions.downAndUp(item2)
MockInteractions.focus(item2)
// then:
flush(() => {
expect(items.selected).to.eql(1)
expect(item1.focused).to.be.false
expect(item2.focused).to.be.true
done()
})
})
})
})
</script>