-
Notifications
You must be signed in to change notification settings - Fork 240
/
functional.ts
161 lines (136 loc) Β· 4.88 KB
/
functional.ts
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import userEvent from 'index'
import {setup} from '__tests__/helpers/utils'
test('produce extra events for the Control key when AltGraph is pressed', () => {
const {element, getEventSnapshot} = setup(`<input/>`)
userEvent.type(element as Element, '{AltGraph}')
expect(getEventSnapshot()).toMatchInlineSnapshot(`
Events fired on: input[value=""]
input[value=""] - pointerover
input[value=""] - pointerenter
input[value=""] - mouseover: Left (0)
input[value=""] - mouseenter: Left (0)
input[value=""] - pointermove
input[value=""] - mousemove: Left (0)
input[value=""] - pointerdown
input[value=""] - mousedown: Left (0)
input[value=""] - focus
input[value=""] - focusin
input[value=""] - pointerup
input[value=""] - mouseup: Left (0)
input[value=""] - click: Left (0)
input[value=""] - keydown: Control (17)
input[value=""] - keydown: AltGraph (0)
input[value=""] - keyup: AltGraph (0)
input[value=""] - keyup: Control (17)
`)
})
test('backspace to valid value', () => {
const {element, getEventSnapshot} = setup(`<input type="number"/>`)
userEvent.type(element as Element, '5e-[Backspace][Backspace]')
expect(element).toHaveValue(5)
expect(getEventSnapshot()).toMatchInlineSnapshot(`
Events fired on: input[value="5"]
input[value=""] - pointerover
input[value=""] - pointerenter
input[value=""] - mouseover: Left (0)
input[value=""] - mouseenter: Left (0)
input[value=""] - pointermove
input[value=""] - mousemove: Left (0)
input[value=""] - pointerdown
input[value=""] - mousedown: Left (0)
input[value=""] - focus
input[value=""] - focusin
input[value=""] - pointerup
input[value=""] - mouseup: Left (0)
input[value=""] - click: Left (0)
input[value=""] - keydown: 5 (53)
input[value=""] - keypress: 5 (53)
input[value="5"] - input
"{CURSOR}" -> "{CURSOR}5"
input[value="5"] - keyup: 5 (53)
input[value="5"] - keydown: e (101)
input[value="5"] - keypress: e (101)
input[value=""] - input
"{CURSOR}5" -> "{CURSOR}"
input[value=""] - keyup: e (101)
input[value=""] - keydown: - (45)
input[value=""] - keypress: - (45)
input[value=""] - input
input[value=""] - keyup: - (45)
input[value=""] - keydown: Backspace (8)
input[value=""] - input
input[value=""] - keyup: Backspace (8)
input[value=""] - keydown: Backspace (8)
input[value="5"] - input
"{CURSOR}" -> "{CURSOR}5"
input[value="5"] - keyup: Backspace (8)
`)
})
test('trigger click event on [Enter] keydown on HTMLAnchorElement', () => {
const {element, getEventSnapshot, getEvents} = setup(
`<a href="example.com" target="_blank"/>`,
)
;(element as HTMLAnchorElement).focus()
userEvent.keyboard('[Enter]')
expect(getEvents('click')).toHaveLength(1)
expect(getEvents('click')[0]).toHaveProperty('detail', 0)
// this snapshot should probably not contain a keypress event
// see https://github.com/testing-library/user-event/issues/589
expect(getEventSnapshot()).toMatchInlineSnapshot(`
Events fired on: a
a - focus
a - focusin
a - keydown: Enter (13)
a - keypress: Enter (13)
a - click: Left (0)
a - keyup: Enter (13)
`)
})
test('trigger click event on [Enter] keypress on HTMLButtonElement', () => {
const {element, getEventSnapshot, getEvents} = setup(`<button/>`)
;(element as HTMLButtonElement).focus()
userEvent.keyboard('[Enter]')
expect(getEvents('click')).toHaveLength(1)
expect(getEvents('click')[0]).toHaveProperty('detail', 0)
expect(getEventSnapshot()).toMatchInlineSnapshot(`
Events fired on: button
button - focus
button - focusin
button - keydown: Enter (13)
button - keypress: Enter (13)
button - click: Left (0)
button - keyup: Enter (13)
`)
})
test('trigger click event on [Space] keyup on HTMLButtonElement', () => {
const {element, getEventSnapshot, getEvents} = setup(`<button/>`)
;(element as HTMLButtonElement).focus()
userEvent.keyboard('[Space]')
expect(getEvents('click')).toHaveLength(1)
expect(getEvents('click')[0]).toHaveProperty('detail', 0)
expect(getEventSnapshot()).toMatchInlineSnapshot(`
Events fired on: button
button - focus
button - focusin
button - keydown: (32)
button - keypress: (32)
button - keyup: (32)
button - click: Left (0)
`)
})
test('trigger click event on [Space] keyup on HTMLInputElement type=button', () => {
const {element, getEventSnapshot, getEvents} = setup(`<button/>`)
;(element as HTMLButtonElement).focus()
userEvent.keyboard('[Space]')
expect(getEvents('click')).toHaveLength(1)
expect(getEvents('click')[0]).toHaveProperty('detail', 0)
expect(getEventSnapshot()).toMatchInlineSnapshot(`
Events fired on: button
button - focus
button - focusin
button - keydown: (32)
button - keypress: (32)
button - keyup: (32)
button - click: Left (0)
`)
})