Skip to content

Commit 3f50a9c

Browse files
authored
test: add shortcut for pressing multiple keys simultaneously (#8536) (#8588)
1 parent 28ec6d4 commit 3f50a9c

File tree

29 files changed

+140
-256
lines changed

29 files changed

+140
-256
lines changed

packages/a11y-base/test/focus-trap-controller.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ async function tab() {
5858
}
5959

6060
async function shiftTab() {
61-
await sendKeys({ down: 'Shift' });
62-
await sendKeys({ press: 'Tab' });
63-
await sendKeys({ up: 'Shift' });
61+
await sendKeys({ press: 'Shift+Tab' });
6462
return document.activeElement;
6563
}
6664

packages/app-layout/test/helpers.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@ export async function tab() {
99
}
1010

1111
export async function shiftTab() {
12-
await sendKeys({ down: 'Shift' });
13-
await sendKeys({ press: 'Tab' });
14-
await sendKeys({ up: 'Shift' });
12+
await sendKeys({ press: 'Shift+Tab' });
1513
}

packages/checkbox-group/test/checkbox-group.common.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ describe('vaadin-checkbox-group', () => {
287287
await sendKeys({ press: 'Tab' });
288288

289289
// Move focus out of the checkbox group.
290-
await sendKeys({ down: 'Shift' });
291-
await sendKeys({ press: 'Tab' });
292-
await sendKeys({ up: 'Shift' });
290+
await sendKeys({ press: 'Shift+Tab' });
293291

294292
expect(checkboxes[0].hasAttribute('focused')).to.be.false;
295293
expect(group.hasAttribute('focused')).to.be.false;

packages/checkbox-group/test/validation.common.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ describe('validation', () => {
8282
expect(validateSpy.called).to.be.false;
8383

8484
// Move focus out of the checkbox group.
85-
await sendKeys({ down: 'Shift' });
86-
await sendKeys({ press: 'Tab' });
87-
await sendKeys({ up: 'Shift' });
85+
await sendKeys({ press: 'Shift+Tab' });
8886
expect(validateSpy.calledOnce).to.be.true;
8987
});
9088

@@ -132,9 +130,7 @@ describe('validation', () => {
132130
await sendKeys({ press: 'Tab' });
133131

134132
// Move focus out of the checkbox group.
135-
await sendKeys({ down: 'Shift' });
136-
await sendKeys({ press: 'Tab' });
137-
await sendKeys({ up: 'Shift' });
133+
await sendKeys({ press: 'Shift+Tab' });
138134

139135
expect(validateSpy.called).to.be.false;
140136
});

packages/checkbox/test/validation.common.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ describe('validation', () => {
108108
await sendKeys({ press: 'Tab' });
109109

110110
// Blur the checkbox.
111-
await sendKeys({ down: 'Shift' });
112-
await sendKeys({ press: 'Tab' });
113-
await sendKeys({ up: 'Shift' });
111+
await sendKeys({ press: 'Shift+Tab' });
114112

115113
expect(validateSpy.called).to.be.false;
116114
});

packages/component-base/test/virtualizer-reorder-elements.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ describe('reorder elements', () => {
152152
// Tab upwards
153153
for (let i = tabToIndex - 1; i >= 0; i--) {
154154
await nextFrame();
155-
await sendKeys({ down: 'Shift' });
156-
await sendKeys({ press: 'Tab' });
157-
await sendKeys({ up: 'Shift' });
155+
await sendKeys({ press: 'Shift+Tab' });
158156
await nextFrame();
159157
expect(document.activeElement.id).to.equal(`item-${i}`);
160158
}

packages/context-menu/test/a11y.common.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ describe('a11y', () => {
7979
it('should move focus to the prev element outside the menu on Shift+Tab pressed inside', async () => {
8080
contextMenuButton.click();
8181
await nextRender();
82-
await sendKeys({ down: 'Shift' });
83-
await sendKeys({ press: 'Tab' });
84-
await sendKeys({ up: 'Shift' });
82+
await sendKeys({ press: 'Shift+Tab' });
8583
expect(getDeepActiveElement()).to.equal(firstGlobalFocusable);
8684
});
8785

packages/dashboard/test/dashboard-keyboard.test.ts

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ describe('dashboard - keyboard interaction', () => {
8888
await sendKeys({ press: 'Space' });
8989

9090
// Focus the focus-button with shift + tab
91-
await sendKeys({ down: 'Shift' });
92-
await sendKeys({ press: 'Tab' });
93-
await sendKeys({ up: 'Shift' });
91+
await sendKeys({ press: 'Shift+Tab' });
9492

9593
// Click the focus-button
9694
await sendKeys({ press: 'Space' });
@@ -158,9 +156,7 @@ describe('dashboard - keyboard interaction', () => {
158156
it('should blur deselected widget on shift tab', async () => {
159157
const widget = getElementFromCell(dashboard, 0, 0)!;
160158
await sendKeys({ press: 'Escape' });
161-
await sendKeys({ down: 'Shift' });
162-
await sendKeys({ press: 'Tab' });
163-
await sendKeys({ up: 'Shift' });
159+
await sendKeys({ press: 'Shift+Tab' });
164160
expect(widget.hasAttribute('selected')).to.be.false;
165161
expect(widget.hasAttribute('focused')).to.be.false;
166162
expect(widget.contains(document.activeElement)).to.be.false;
@@ -233,29 +229,23 @@ describe('dashboard - keyboard interaction', () => {
233229
it('should increase the widget row span on shift + arrow down', async () => {
234230
// Set minimum row height to enable vertical resizing
235231
setMinimumRowHeight(dashboard, 100);
236-
await sendKeys({ down: 'Shift' });
237-
await sendKeys({ press: 'ArrowDown' });
238-
await sendKeys({ up: 'Shift' });
232+
await sendKeys({ press: 'Shift+ArrowDown' });
239233
expect((dashboard.items[0] as DashboardItem).rowspan).to.equal(2);
240234
});
241235

242236
it('should decrease the widget row span on shift + arrow up', async () => {
243237
// Set minimum row height to enable vertical resizing
244238
setMinimumRowHeight(dashboard, 100);
245-
await sendKeys({ down: 'Shift' });
246-
await sendKeys({ press: 'ArrowDown' });
239+
await sendKeys({ press: 'Shift+ArrowDown' });
247240
await updateComplete(dashboard);
248-
await sendKeys({ press: 'ArrowUp' });
249-
await sendKeys({ up: 'Shift' });
241+
await sendKeys({ press: 'Shift+ArrowUp' });
250242
expect((dashboard.items[0] as DashboardItem).rowspan).to.equal(1);
251243
});
252244

253245
it('should dispatch an item resized event shift + arrow down', async () => {
254246
const spy = sinon.spy();
255247
dashboard.addEventListener('dashboard-item-resized', spy);
256-
await sendKeys({ down: 'Shift' });
257-
await sendKeys({ press: 'ArrowDown' });
258-
await sendKeys({ up: 'Shift' });
248+
await sendKeys({ press: 'Shift+ArrowDown' });
259249
expect(spy.calledOnce).to.be.true;
260250
expect(spy.firstCall.args[0].detail.item).to.eql({ id: 0 });
261251
expect(spy.firstCall.args[0].detail.items).to.eql(dashboard.items);
@@ -266,23 +256,17 @@ describe('dashboard - keyboard interaction', () => {
266256
const spy = sinon.spy();
267257
// @ts-ignore unexpected event type
268258
dashboard.addEventListener('item-resize', spy);
269-
await sendKeys({ down: 'Shift' });
270-
await sendKeys({ press: 'ArrowDown' });
271-
await sendKeys({ up: 'Shift' });
259+
await sendKeys({ press: 'Shift+ArrowDown' });
272260
expect(spy.called).to.be.false;
273261
});
274262

275263
it('should not increase the widget row span on shift + arrow down if row min height is not defined', async () => {
276-
await sendKeys({ down: 'Shift' });
277-
await sendKeys({ press: 'ArrowDown' });
278-
await sendKeys({ up: 'Shift' });
264+
await sendKeys({ press: 'Shift+ArrowDown' });
279265
expect((dashboard.items[0] as DashboardItem).rowspan).to.not.equal(2);
280266
});
281267

282268
it('should not move the widget on arrow down if ctrl key is pressed', async () => {
283-
await sendKeys({ down: 'Control' });
284-
await sendKeys({ press: 'ArrowDown' });
285-
await sendKeys({ up: 'Control' });
269+
await sendKeys({ press: 'Control+ArrowDown' });
286270
expect(dashboard.items).to.eql([{ id: 0 }, { id: 1 }, { items: [{ id: 2 }, { id: 3 }] }]);
287271
});
288272

@@ -341,9 +325,7 @@ describe('dashboard - keyboard interaction', () => {
341325
it('should release focus trap on deselect', async () => {
342326
const widget = getElementFromCell(dashboard, 0, 0)!;
343327
await sendKeys({ press: 'Escape' });
344-
await sendKeys({ down: 'Shift' });
345-
await sendKeys({ press: 'Tab' });
346-
await sendKeys({ up: 'Shift' });
328+
await sendKeys({ press: 'Shift+Tab' });
347329
expect(widget.contains(document.activeElement)).to.be.false;
348330
});
349331

@@ -369,18 +351,14 @@ describe('dashboard - keyboard interaction', () => {
369351
});
370352

371353
it('should increase the widget column span on shift + arrow forwards', async () => {
372-
await sendKeys({ down: 'Shift' });
373-
await sendKeys({ press: arrowForwards });
374-
await sendKeys({ up: 'Shift' });
354+
await sendKeys({ press: `Shift+${arrowForwards}` });
375355
expect((dashboard.items[0] as DashboardItem).colspan).to.equal(2);
376356
});
377357

378358
it('should decrease the widget column span on shift + arrow backwards', async () => {
379-
await sendKeys({ down: 'Shift' });
380-
await sendKeys({ press: arrowForwards });
359+
await sendKeys({ press: `Shift+${arrowForwards}` });
381360
await updateComplete(dashboard);
382-
await sendKeys({ press: arrowBackwards });
383-
await sendKeys({ up: 'Shift' });
361+
await sendKeys({ press: `Shift+${arrowBackwards}` });
384362
expect((dashboard.items[0] as DashboardItem).colspan).to.equal(1);
385363
});
386364
});
@@ -412,9 +390,7 @@ describe('dashboard - keyboard interaction', () => {
412390

413391
it('should blur deselected selected on shift tab', async () => {
414392
await sendKeys({ press: 'Escape' });
415-
await sendKeys({ down: 'Shift' });
416-
await sendKeys({ press: 'Tab' });
417-
await sendKeys({ up: 'Shift' });
393+
await sendKeys({ press: 'Shift+Tab' });
418394
expect(section.hasAttribute('selected')).to.be.false;
419395
expect(section.hasAttribute('focused')).to.be.false;
420396
expect(section.contains(document.activeElement)).to.be.false;
@@ -446,16 +422,12 @@ describe('dashboard - keyboard interaction', () => {
446422

447423
it('should release focus trap on deselect', async () => {
448424
await sendKeys({ press: 'Escape' });
449-
await sendKeys({ down: 'Shift' });
450-
await sendKeys({ press: 'Tab' });
451-
await sendKeys({ up: 'Shift' });
425+
await sendKeys({ press: 'Shift+Tab' });
452426
expect(section.contains(document.activeElement)).to.be.false;
453427
});
454428

455429
it('should not increase the section row span on shift + arrow down', async () => {
456-
await sendKeys({ down: 'Shift' });
457-
await sendKeys({ press: 'ArrowDown' });
458-
await sendKeys({ up: 'Shift' });
430+
await sendKeys({ press: 'Shift+ArrowDown' });
459431
expect(dashboard.items).to.eql([{ id: 0 }, { id: 1 }, { items: [{ id: 2 }, { id: 3 }] }]);
460432
});
461433
});
@@ -565,10 +537,8 @@ describe('dashboard - keyboard interaction', () => {
565537
await sendKeys({ press: 'Space' });
566538
await nextFrame();
567539
// Focus backward button, click it
568-
await sendKeys({ down: 'Shift' });
569-
await sendKeys({ press: 'Tab' });
570-
await sendKeys({ press: 'Tab' });
571-
await sendKeys({ up: 'Shift' });
540+
await sendKeys({ press: 'Shift+Tab' });
541+
await sendKeys({ press: 'Shift+Tab' });
572542
await nextFrame();
573543

574544
expect(getMoveBackwardButton(widget).matches(':focus')).to.be.true;
@@ -598,10 +568,8 @@ describe('dashboard - keyboard interaction', () => {
598568
await sendKeys({ press: 'Space' });
599569
await nextFrame();
600570
// Focus backwards button, click it
601-
await sendKeys({ down: 'Shift' });
602-
await sendKeys({ press: 'Tab' });
603-
await sendKeys({ press: 'Tab' });
604-
await sendKeys({ up: 'Shift' });
571+
await sendKeys({ press: 'Shift+Tab' });
572+
await sendKeys({ press: 'Shift+Tab' });
605573
await sendKeys({ press: 'Space' });
606574
await nextFrame();
607575

packages/date-picker/test/fullscreen.common.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ describe('fullscreen mode', () => {
157157
it('should move focus to Cancel button on date cell Shift Tab', async () => {
158158
const spy = sinon.spy(overlayContent._cancelButton, 'focus');
159159

160-
await sendKeys({ down: 'Shift' });
161-
await sendKeys({ press: 'Tab' });
162-
await sendKeys({ up: 'Shift' });
160+
await sendKeys({ press: 'Shift+Tab' });
163161

164162
expect(spy.calledOnce).to.be.true;
165163
});
@@ -169,9 +167,7 @@ describe('fullscreen mode', () => {
169167
const spy = sinon.spy(cell, 'focus');
170168

171169
// Move focus to Cancel button
172-
await sendKeys({ down: 'Shift' });
173-
await sendKeys({ press: 'Tab' });
174-
await sendKeys({ up: 'Shift' });
170+
await sendKeys({ press: 'Shift+Tab' });
175171

176172
await sendKeys({ press: 'Tab' });
177173

packages/date-picker/test/keyboard-input.common.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ describe('keyboard', () => {
258258

259259
const spy = sinon.spy(input, 'focus');
260260

261-
await sendKeys({ down: 'Shift' });
262-
await sendKeys({ press: 'Tab' });
263-
await sendKeys({ up: 'Shift' });
261+
await sendKeys({ press: 'Shift+Tab' });
264262

265263
expect(spy.calledOnce).to.be.true;
266264
});
@@ -273,19 +271,15 @@ describe('keyboard', () => {
273271
});
274272

275273
it('should move focus to Cancel button on input Shift Tab', async () => {
276-
await sendKeys({ down: 'Shift' });
277-
await sendKeys({ press: 'Tab' });
278-
await sendKeys({ up: 'Shift' });
274+
await sendKeys({ press: 'Shift+Tab' });
279275
expect(overlayContent._cancelButton.hasAttribute('focused')).to.be.true;
280276
});
281277

282278
it('should reveal the focused date on Today button Shift Tab', async () => {
283279
const spy = sinon.spy(overlayContent, 'revealDate');
284280
overlayContent._todayButton.focus();
285281

286-
await sendKeys({ down: 'Shift' });
287-
await sendKeys({ press: 'Tab' });
288-
await sendKeys({ up: 'Shift' });
282+
await sendKeys({ press: 'Shift+Tab' });
289283

290284
await aTimeout(1);
291285
expect(spy.called).to.be.true;
@@ -328,9 +322,7 @@ describe('keyboard', () => {
328322
overlayContent._todayButton.focus();
329323

330324
// Move focus to the calendar
331-
await sendKeys({ down: 'Shift' });
332-
await sendKeys({ press: 'Tab' });
333-
await sendKeys({ up: 'Shift' });
325+
await sendKeys({ press: 'Shift+Tab' });
334326

335327
await waitForScrollToFinish(datePicker);
336328

0 commit comments

Comments
 (0)