-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
Copy pathrange-events.e2e.ts
212 lines (152 loc) · 7.39 KB
/
range-events.e2e.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import { expect } from '@playwright/test';
import { configs, dragElementBy, test } from '@utils/test/playwright';
/**
* This behavior does not vary across modes/directions.
*/
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('range: events:'), () => {
test.describe('range: knob events', () => {
/**
* The mouse events are flaky on CI
*/
test.fixme('should emit start/end events', async ({ page }) => {
/**
* Requires padding to prevent the knob from being clipped.
* If it's clipped, then the value might be one off.
* For example, if the knob is clipped on the right, then the value
* will be 99 instead of 100.
*/
await page.setContent(
`
<div style="padding: 0 20px">
<ion-range aria-label="Range" value="20"></ion-range>
</div>
`,
config
);
const rangeStart = await page.spyOnEvent('ionKnobMoveStart');
const rangeEnd = await page.spyOnEvent('ionKnobMoveEnd');
const rangeEl = page.locator('ion-range');
await dragElementBy(rangeEl, page, 300, 0);
await page.waitForChanges();
/**
* dragElementBy defaults to starting the drag from the middle of the el,
* so the start value should jump to 50 despite the range defaulting to 20.
*/
expect(rangeStart).toHaveReceivedEventDetail({ value: 50 });
expect(rangeEnd).toHaveReceivedEventDetail({ value: 100 });
/**
* Verify both events fire if range is clicked without dragging.
*/
await dragElementBy(rangeEl, page, 0, 0);
await page.waitForChanges();
expect(rangeStart).toHaveReceivedEventDetail({ value: 50 });
expect(rangeEnd).toHaveReceivedEventDetail({ value: 50 });
});
test('should emit start/end events, keyboard', async ({ page }) => {
await page.setContent(`<ion-range aria-label="Range" value="20"></ion-range>`, config);
const rangeStart = await page.spyOnEvent('ionKnobMoveStart');
const rangeEnd = await page.spyOnEvent('ionKnobMoveEnd');
await page.keyboard.press('Tab'); // focus first range
await page.keyboard.press('ArrowRight');
await rangeStart.next();
await rangeEnd.next();
expect(rangeStart).toHaveReceivedEventDetail({ value: 20 });
expect(rangeEnd).toHaveReceivedEventDetail({ value: 21 });
});
// TODO FW-2873
test.skip('should not scroll when the knob is swiped', async ({ page, skip }) => {
skip.browser('webkit', 'mouse.wheel is not available in WebKit');
await page.goto(`/src/components/range/test/legacy/basic`, config);
const knobEl = page.locator('ion-range#stacked-range .range-knob-handle');
const scrollEl = page.locator('ion-content .inner-scroll');
expect(await scrollEl.evaluate((el: HTMLElement) => el.scrollTop)).toEqual(0);
await dragElementBy(knobEl, page, 30, 0, undefined, undefined, false);
/**
* Do not use scrollToBottom() or other scrolling methods
* on ion-content as those will update the scroll position.
* Setting scrollTop still works even with overflow-y: hidden.
* However, simulating a user gesture should not scroll the content.
*/
await page.mouse.wheel(0, 100);
await page.waitForChanges();
expect(await scrollEl.evaluate((el: HTMLElement) => el.scrollTop)).toEqual(0);
});
});
test.describe('ionChange', () => {
test('should not emit if the value is set programmatically', async ({ page }) => {
await page.setContent(`<ion-range aria-label="range"></ion-range>`, config);
const range = page.locator('ion-range');
const ionChangeSpy = await page.spyOnEvent('ionChange');
await range.evaluate((el: HTMLIonRangeElement) => {
el.value = 50;
});
await page.waitForChanges();
expect(ionChangeSpy).toHaveReceivedEventTimes(0);
// Update the value again to make sure it doesn't emit a second time
await range.evaluate((el: HTMLIonRangeElement) => {
el.value = 60;
});
await page.waitForChanges();
expect(ionChangeSpy).toHaveReceivedEventTimes(0);
});
// TODO FW-2873
test.skip('should emit when the knob is released', async ({ page }) => {
await page.setContent(`<ion-range aria-label="range"></ion-range>`, config);
const rangeHandle = page.locator('ion-range .range-knob-handle');
const ionChangeSpy = await page.spyOnEvent('ionChange');
await dragElementBy(rangeHandle, page, 100, 0);
await ionChangeSpy.next();
expect(ionChangeSpy).toHaveReceivedEventTimes(1);
});
test('should emit when the knob is moved with the keyboard', async ({ page }) => {
await page.setContent(`<ion-range aria-label="range" value="50"></ion-range>`, config);
const rangeHandle = page.locator('ion-range .range-knob-handle');
const ionChangeSpy = await page.spyOnEvent('ionChange');
await rangeHandle.click();
await page.keyboard.press('ArrowLeft');
await ionChangeSpy.next();
expect(ionChangeSpy).toHaveReceivedEventDetail({ value: 49 });
await page.keyboard.press('ArrowRight');
await ionChangeSpy.next();
expect(ionChangeSpy).toHaveReceivedEventDetail({ value: 50 });
await page.keyboard.press('ArrowUp');
await ionChangeSpy.next();
expect(ionChangeSpy).toHaveReceivedEventDetail({ value: 51 });
await page.keyboard.press('ArrowDown');
await ionChangeSpy.next();
expect(ionChangeSpy).toHaveReceivedEventDetail({ value: 50 });
});
});
test.describe('ionInput', () => {
// TODO(FW-2873) Enable this test when touch events/gestures are better supported in Playwright
test.skip('should emit when the knob is dragged', async ({ page }) => {
await page.setContent(`<ion-range aria-label="range"></ion-range>`, config);
const rangeHandle = page.locator('ion-range .range-knob-handle');
const ionInputSpy = await page.spyOnEvent('ionInput');
await rangeHandle.hover();
await dragElementBy(rangeHandle, page, 100, 0, undefined, undefined, false);
await ionInputSpy.next();
expect(ionInputSpy).toHaveReceivedEvent();
});
test('should emit when the knob is moved with the keyboard', async ({ page }) => {
await page.setContent(`<ion-range aria-label="range" value="50"></ion-range>`, config);
const rangeHandle = page.locator('ion-range .range-knob-handle');
const ionInputSpy = await page.spyOnEvent('ionInput');
await rangeHandle.click();
await page.keyboard.press('ArrowLeft');
await ionInputSpy.next();
expect(ionInputSpy).toHaveReceivedEventDetail({ value: 49 });
await page.keyboard.press('ArrowRight');
await ionInputSpy.next();
expect(ionInputSpy).toHaveReceivedEventDetail({ value: 50 });
await page.keyboard.press('ArrowUp');
await ionInputSpy.next();
expect(ionInputSpy).toHaveReceivedEventDetail({ value: 51 });
await page.keyboard.press('ArrowDown');
await ionInputSpy.next();
expect(ionInputSpy).toHaveReceivedEventDetail({ value: 50 });
});
});
});
});