Skip to content

Commit 1cfa85c

Browse files
author
Nipun Paradkar
authored
Refactor Event Options test helpers (#541)
* Remove `elementActionValue` setter ... and modify `actionValue` to accept an element onto which the action should be set. Defaults to `this.element` when the element isn't provided. * Replace `actionValue` setter with `setAction` method ... that has the same method signature as the `triggerEvent` method.
1 parent 30933d6 commit 1cfa85c

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

src/tests/modules/core/event_options_tests.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
99
<div id="outside"></div>
1010
`
1111
async "test different syntaxes for once action"() {
12-
this.actionValue = "click->c#log:once d#log2:once c#log3:once"
12+
this.setAction(this.buttonElement, "click->c#log:once d#log2:once c#log3:once")
1313

1414
await this.nextFrame
1515
await this.triggerEvent(this.buttonElement, "click")
@@ -23,7 +23,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
2323
}
2424

2525
async "test mix once and standard actions"() {
26-
this.actionValue = "c#log:once d#log2 c#log3"
26+
this.setAction(this.buttonElement, "c#log:once d#log2 c#log3")
2727

2828
await this.nextFrame
2929
await this.triggerEvent(this.buttonElement, "click")
@@ -39,7 +39,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
3939
}
4040

4141
async "test stop propagation with once"() {
42-
this.actionValue = "c#stop:once c#log"
42+
this.setAction(this.buttonElement, "c#stop:once c#log")
4343

4444
await this.nextFrame
4545
await this.triggerEvent(this.buttonElement, "click")
@@ -57,7 +57,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
5757
}
5858

5959
async "test global once actions"() {
60-
this.actionValue = "keydown@window->c#log:once"
60+
this.setAction(this.buttonElement, "keydown@window->c#log:once")
6161

6262
await this.nextFrame
6363
await this.triggerEvent("#outside", "keydown")
@@ -67,13 +67,13 @@ export default class EventOptionsTests extends LogControllerTestCase {
6767
}
6868

6969
async "test edge case when updating action list with setAttribute preserves once history"() {
70-
this.actionValue = "c#log:once"
70+
this.setAction(this.buttonElement, "c#log:once")
7171
await this.nextFrame
7272
await this.triggerEvent(this.buttonElement, "click")
7373
await this.triggerEvent(this.buttonElement, "click")
7474

7575
//modify with a setAttribute and c#log should not be called anyhow
76-
this.actionValue = "c#log2 c#log:once d#log"
76+
this.setAction(this.buttonElement, "c#log2 c#log:once d#log")
7777
await this.nextFrame
7878
await this.triggerEvent(this.buttonElement, "click")
7979

@@ -85,15 +85,15 @@ export default class EventOptionsTests extends LogControllerTestCase {
8585
}
8686

8787
async "test default passive action"() {
88-
this.actionValue = "scroll->c#logPassive:passive"
88+
this.setAction(this.buttonElement, "scroll->c#logPassive:passive")
8989
await this.nextFrame
9090

9191
await this.triggerEvent(this.buttonElement, "scroll", { setDefaultPrevented: false })
9292
this.assertActions({ name: "logPassive", eventType: "scroll", passive: true })
9393
}
9494

9595
async "test global passive actions"() {
96-
this.actionValue = "mouseup@window->c#logPassive:passive"
96+
this.setAction(this.buttonElement, "mouseup@window->c#logPassive:passive")
9797
await this.nextFrame
9898

9999
await this.triggerEvent("#outside", "mouseup", { setDefaultPrevented: false })
@@ -102,7 +102,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
102102

103103
async "test passive false actions"() {
104104
// by default touchmove is true in chrome
105-
this.actionValue = "touchmove@window->c#logPassive:!passive"
105+
this.setAction(this.buttonElement, "touchmove@window->c#logPassive:!passive")
106106
await this.nextFrame
107107

108108
await this.triggerEvent("#outside", "touchmove", { setDefaultPrevented: false })
@@ -111,7 +111,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
111111

112112
async "test multiple options"() {
113113
// by default touchmove is true in chrome
114-
this.actionValue = "touchmove@window->c#logPassive:once:!passive"
114+
this.setAction(this.buttonElement, "touchmove@window->c#logPassive:once:!passive")
115115
await this.nextFrame
116116

117117
await this.triggerEvent("#outside", "touchmove", { setDefaultPrevented: false })
@@ -120,7 +120,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
120120
}
121121

122122
async "test wrong options are silently ignored"() {
123-
this.actionValue = "c#log:wrong:verywrong"
123+
this.setAction(this.buttonElement, "c#log:wrong:verywrong")
124124
await this.nextFrame
125125
await this.triggerEvent(this.buttonElement, "click")
126126
await this.triggerEvent(this.buttonElement, "click")
@@ -132,8 +132,8 @@ export default class EventOptionsTests extends LogControllerTestCase {
132132
}
133133

134134
async "test stop option with implicit event"() {
135-
this.elementActionValue = "click->c#log"
136-
this.actionValue = "c#log2:stop"
135+
this.setAction(this.element, "click->c#log")
136+
this.setAction(this.buttonElement, "c#log2:stop")
137137
await this.nextFrame
138138

139139
await this.triggerEvent(this.buttonElement, "click")
@@ -144,8 +144,8 @@ export default class EventOptionsTests extends LogControllerTestCase {
144144
}
145145

146146
async "test stop option with explicit event"() {
147-
this.elementActionValue = "keydown->c#log"
148-
this.actionValue = "keydown->c#log2:stop"
147+
this.setAction(this.element, "keydown->c#log")
148+
this.setAction(this.buttonElement, "keydown->c#log2:stop")
149149
await this.nextFrame
150150

151151
await this.triggerEvent(this.buttonElement, "keydown")
@@ -156,8 +156,8 @@ export default class EventOptionsTests extends LogControllerTestCase {
156156
}
157157

158158
async "test event propagation without stop option"() {
159-
this.elementActionValue = "click->c#log"
160-
this.actionValue = "c#log2"
159+
this.setAction(this.element, "click->c#log")
160+
this.setAction(this.buttonElement, "c#log2")
161161
await this.nextFrame
162162

163163
await this.triggerEvent(this.buttonElement, "click")
@@ -169,7 +169,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
169169
}
170170

171171
async "test prevent option with implicit event"() {
172-
this.actionValue = "c#log:prevent"
172+
this.setAction(this.buttonElement, "c#log:prevent")
173173
await this.nextFrame
174174

175175
await this.triggerEvent(this.buttonElement, "click")
@@ -180,7 +180,7 @@ export default class EventOptionsTests extends LogControllerTestCase {
180180
}
181181

182182
async "test prevent option with explicit event"() {
183-
this.actionValue = "keyup->c#log:prevent"
183+
this.setAction(this.buttonElement, "keyup->c#log:prevent")
184184
await this.nextFrame
185185

186186
await this.triggerEvent(this.buttonElement, "keyup")
@@ -190,12 +190,8 @@ export default class EventOptionsTests extends LogControllerTestCase {
190190
)
191191
}
192192

193-
set actionValue(value: string) {
194-
this.buttonElement.setAttribute("data-action", value)
195-
}
196-
197-
set elementActionValue(value: string) {
198-
this.element.setAttribute("data-action", value)
193+
setAction(element: Element, value: string) {
194+
element.setAttribute("data-action", value)
199195
}
200196

201197
get element() {

0 commit comments

Comments
 (0)