-
Notifications
You must be signed in to change notification settings - Fork 443
Expand file tree
/
Copy pathaction_tests.ts
More file actions
69 lines (60 loc) · 2.49 KB
/
Copy pathaction_tests.ts
File metadata and controls
69 lines (60 loc) · 2.49 KB
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
import { LogControllerTestCase } from "../../cases/log_controller_test_case"
export default class ActionTests extends LogControllerTestCase {
identifier = "c"
fixtureHTML = `
<div data-controller="c" data-action="keydown@window->c#log">
<button data-action="c#log"><span>Log</span></button>
<div id="outer" data-action="click->c#log">
<div id="inner" data-controller="c" data-action="click->c#log keyup@window->c#log"></div>
</div>
<div id="multiple" data-action="click->c#log click->c#log2 mousedown->c#log"></div>
</div>
<div id="outside"></div>
<svg id="svgRoot" data-controller="c" data-action="click->c#log">
<circle id="svgChild" data-action="mousedown->c#log" cx="5" cy="5" r="5">
</svg>
`
async "test default event"() {
await this.triggerEvent("button", "click")
this.assertActions({ name: "log", eventType: "click" })
}
async "test bubbling events"() {
await this.triggerEvent("span", "click")
this.assertActions({ eventType: "click", currentTarget: this.findElement("button") })
}
async "test non-bubbling events"() {
await this.triggerEvent("span", "click", { bubbles: false })
this.assertNoActions()
await this.triggerEvent("button", "click", { bubbles: false })
this.assertActions({ eventType: "click" })
}
async "test nested actions"() {
const innerController = this.controllers[1]
await this.triggerEvent("#inner", "click")
this.assert.ok(true)
this.assertActions({ controller: innerController, eventType: "click" })
}
async "test global actions"() {
await this.triggerKeyboardEvent("#outside", "keydown", { bubbles: true })
this.assertActions({ name: "log", eventType: "keydown" })
}
async "test nested global actions"() {
const innerController = this.controllers[1]
await this.triggerKeyboardEvent("#outside", "keyup", { bubbles: true })
this.assertActions({ controller: innerController, eventType: "keyup" })
}
async "test multiple actions"() {
await this.triggerEvent("#multiple", "mousedown")
await this.triggerEvent("#multiple", "click")
this.assertActions(
{ name: "log", eventType: "mousedown" },
{ name: "log", eventType: "click" },
{ name: "log2", eventType: "click" }
)
}
async "test actions on svg elements"() {
await this.triggerEvent("#svgRoot", "click")
await this.triggerEvent("#svgChild", "mousedown")
this.assertActions({ name: "log", eventType: "click" }, { name: "log", eventType: "mousedown" })
}
}