Skip to content

Commit

Permalink
try to fix tab navigation tests for grid and virtualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Jan 8, 2025
1 parent 6ff2b6a commit 5e7c09d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
import { fixtureSync, mousedown, mouseup, nextFrame, oneEvent } from '@vaadin/testing-helpers';
import { fixtureSync, mousedown, mouseup, nextFrame } from '@vaadin/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import { Virtualizer } from '../src/virtualizer.js';
Expand Down Expand Up @@ -144,21 +144,17 @@ describe('reorder elements', () => {
// Tab downwards
for (let i = 1; i <= tabToIndex; i++) {
await nextFrame();
queueMicrotask(async () => await sendKeys({ press: 'Tab' }));
await oneEvent(elementsContainer, 'focusin');
await sendKeys({ press: 'Tab' });
await nextFrame();
expect(document.activeElement.id).to.equal(`item-${i}`);
}

// Tab upwards
for (let i = tabToIndex - 1; i >= 0; i--) {
await nextFrame();
queueMicrotask(async () => {
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
});
await oneEvent(elementsContainer, 'focusin');
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await nextFrame();
expect(document.activeElement.id).to.equal(`item-${i}`);
}
Expand Down
14 changes: 5 additions & 9 deletions packages/grid/test/keyboard-interaction-mode.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@vaadin/chai-plugins';
import { aTimeout, fixtureSync, keyDownOn, nextFrame, nextRender, oneEvent } from '@vaadin/testing-helpers';
import { aTimeout, fixtureSync, keyDownOn, nextFrame, nextRender } from '@vaadin/testing-helpers';
import { sendKeys } from '@web/test-runner-commands';
import sinon from 'sinon';
import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js';
Expand Down Expand Up @@ -540,8 +540,7 @@ describe('keyboard interaction mode', () => {
// Tab downwards
for (let i = 1; i <= tabToIndex; i++) {
await rendered();
queueMicrotask(async () => await sendKeys({ press: 'Tab' }));
await oneEvent(grid, 'focusin');
await sendKeys({ press: 'Tab' });
await rendered();

const focusedRow = document.activeElement.parentElement.assignedSlot.parentElement.parentElement;
Expand All @@ -551,12 +550,9 @@ describe('keyboard interaction mode', () => {
// Tab upwards
for (let i = tabToIndex - 1; i >= 0; i--) {
await rendered();
queueMicrotask(async () => {
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
});
await oneEvent(grid, 'focusin');
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await rendered();
const focusedRow = document.activeElement.parentElement.assignedSlot.parentElement.parentElement;
expect(focusedRow.index).to.equal(i);
Expand Down

0 comments on commit 5e7c09d

Please sign in to comment.