Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add shortcut for pressing multiple keys simultaneously (#8536) (CP: 24.5) #8589

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/a11y-base/test/focus-trap-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ async function tab() {
}

async function shiftTab() {
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
return document.activeElement;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/app-layout/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ export async function tab() {
}

export async function shiftTab() {
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
}
4 changes: 1 addition & 3 deletions packages/checkbox-group/test/checkbox-group.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ describe('vaadin-checkbox-group', () => {
await sendKeys({ press: 'Tab' });

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

expect(checkboxes[0].hasAttribute('focused')).to.be.false;
expect(group.hasAttribute('focused')).to.be.false;
Expand Down
8 changes: 2 additions & 6 deletions packages/checkbox-group/test/validation.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ describe('validation', () => {
expect(validateSpy.called).to.be.false;

// Move focus out of the checkbox group.
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
expect(validateSpy.calledOnce).to.be.true;
});

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

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

expect(validateSpy.called).to.be.false;
});
Expand Down
4 changes: 1 addition & 3 deletions packages/checkbox/test/validation.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ describe('validation', () => {
await sendKeys({ press: 'Tab' });

// Blur the checkbox.
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });

expect(validateSpy.called).to.be.false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ describe('reorder elements', () => {
// Tab upwards
for (let i = tabToIndex - 1; i >= 0; i--) {
await nextFrame();
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
await nextFrame();
expect(document.activeElement.id).to.equal(`item-${i}`);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/context-menu/test/a11y.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ describe('a11y', () => {
it('should move focus to the prev element outside the menu on Shift+Tab pressed inside', async () => {
contextMenuButton.click();
await nextRender();
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
expect(getDeepActiveElement()).to.equal(firstGlobalFocusable);
});

Expand Down
8 changes: 2 additions & 6 deletions packages/date-picker/test/fullscreen.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ describe('fullscreen mode', () => {
it('should move focus to Cancel button on date cell Shift Tab', async () => {
const spy = sinon.spy(overlayContent._cancelButton, 'focus');

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });

expect(spy.calledOnce).to.be.true;
});
Expand All @@ -170,9 +168,7 @@ describe('fullscreen mode', () => {
const spy = sinon.spy(cell, 'focus');

// Move focus to Cancel button
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });

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

Expand Down
16 changes: 4 additions & 12 deletions packages/date-picker/test/keyboard-input.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ describe('keyboard', () => {

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

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });

expect(spy.calledOnce).to.be.true;
});
Expand All @@ -240,19 +238,15 @@ describe('keyboard', () => {
});

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

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

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });

await aTimeout(1);
expect(spy.called).to.be.true;
Expand Down Expand Up @@ -295,9 +289,7 @@ describe('keyboard', () => {
overlayContent._todayButton.focus();

// Move focus to the calendar
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });

await waitForScrollToFinish(datePicker);

Expand Down
32 changes: 8 additions & 24 deletions packages/date-picker/test/keyboard-navigation.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,13 @@ describe('keyboard navigation', () => {
});

it('should focus next year with shift and pagedown', async () => {
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'PageDown' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+PageDown' });
await waitForScrollToFinish(overlay);
expect(overlay.focusedDate).to.eql(new Date(2001, 0, 1));
});

it('should focus previous year with shift and pageup', async () => {
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'PageUp' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+PageUp' });
await waitForScrollToFinish(overlay);
expect(overlay.focusedDate).to.eql(new Date(1999, 0, 1));
});
Expand All @@ -361,9 +357,7 @@ describe('keyboard navigation', () => {
const spy = sinon.spy();
overlay.addEventListener('scroll-animation-finished', spy);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'PageUp' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+PageUp' });

await waitForScrollToFinish(overlay);
const e = spy.firstCall.args[0];
Expand All @@ -382,9 +376,7 @@ describe('keyboard navigation', () => {
const spy = sinon.spy();
overlay.addEventListener('scroll-animation-finished', spy);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'PageDown' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+PageDown' });

await waitForScrollToFinish(overlay);
const e = spy.firstCall.args[0];
Expand Down Expand Up @@ -455,9 +447,7 @@ describe('keyboard navigation', () => {
it('should focus max date with shift and pagedown', async () => {
overlay.maxDate = new Date(2000, 11, 28);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'PageDown' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+PageDown' });

await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
Expand All @@ -467,9 +457,7 @@ describe('keyboard navigation', () => {
it('should focus min date with shift and pageup', async () => {
overlay.minDate = new Date(1999, 5, 3);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'PageUp' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+PageUp' });

await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
Expand Down Expand Up @@ -501,9 +489,7 @@ describe('keyboard navigation', () => {
overlay.minDate = new Date(1999, 11, 25);
await nextRender(overlay);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'PageUp' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+PageUp' });

await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
Expand All @@ -515,9 +501,7 @@ describe('keyboard navigation', () => {
overlay.maxDate = new Date(1999, 11, 25);
await nextRender(overlay);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'PageDown' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+PageDown' });

await waitForScrollToFinish(overlay);
const cell = getFocusedCell(overlay);
Expand Down
4 changes: 1 addition & 3 deletions packages/date-time-picker/test/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ const fixtures = {
await aTimeout(1);

// Move focus to date-picker
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
expect(validateSpy.called).to.be.false;
});

Expand Down
8 changes: 2 additions & 6 deletions packages/field-highlighter/test/field-components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,18 +453,14 @@ describe('field components', () => {

it('should dispatch vaadin-highlight-hide event on Shift Tab to date picker', async () => {
time.focus();
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
expect(hideSpy.callCount).to.equal(1);
expect(hideSpy.firstCall.args[0].detail.fieldIndex).to.equal(1);
});

it('should dispatch second vaadin-highlight-show event on Shift Tab to date picker', async () => {
time.focus();
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
expect(showSpy.callCount).to.equal(2);
expect(showSpy.getCalls()[1].args[0].detail.fieldIndex).to.equal(0);
});
Expand Down
36 changes: 9 additions & 27 deletions packages/grid-pro/test/edit-column.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,12 @@ describe('edit column', () => {
await nextFrame();

// Press Shift + Tab to edit the select cell
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
expect(getCellEditor(selectCell)).to.be.ok;
await nextFrame();

// Press Shift + Tab to edit the text cell
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
expect(getCellEditor(textCell)).to.be.ok;
});
});
Expand Down Expand Up @@ -148,9 +144,7 @@ describe('edit column', () => {
const firstCell = getContainerCell(grid.$.items, 1, 1);
dblclick(firstCell._content);

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });

expect(grid.$.table.scrollLeft).to.closeTo(1, 1);
});
Expand Down Expand Up @@ -458,22 +452,16 @@ describe('edit column', () => {
await sendKeys({ press: 'Enter' });
expect(getCellEditor(cell)).to.be.ok;

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
cell = getContainerCell(grid.$.items, 3, 1);
expect(getCellEditor(cell)).to.be.ok;

// Should skip non-editable rows
await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
cell = getContainerCell(grid.$.items, 1, 3);
expect(getCellEditor(cell)).to.be.ok;

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
cell = getContainerCell(grid.$.items, 1, 2);
expect(getCellEditor(cell)).to.be.ok;
});
Expand Down Expand Up @@ -514,9 +502,7 @@ describe('edit column', () => {
expect(getCellEditor(cell)).to.be.ok;
expect(grid.querySelector('vaadin-grid-pro-edit-text-field')).to.be.ok;

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Tab' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Tab' });
expect(grid.querySelector('vaadin-grid-pro-edit-text-field')).to.not.be.ok;
const target = cell._focusButton || cell;
expect(grid.shadowRoot.activeElement).to.equal(target);
Expand Down Expand Up @@ -546,9 +532,7 @@ describe('edit column', () => {
await sendKeys({ press: 'Enter' });
expect(getCellEditor(cell)).to.be.ok;

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Enter' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Enter' });
cell = getContainerCell(grid.$.items, 1, 1);
expect(getCellEditor(cell)).to.be.ok;
});
Expand All @@ -574,9 +558,7 @@ describe('edit column', () => {
expect(getCellEditor(cell)).to.be.ok;
expect(grid.querySelector('vaadin-grid-pro-edit-text-field')).to.be.ok;

await sendKeys({ down: 'Shift' });
await sendKeys({ press: 'Enter' });
await sendKeys({ up: 'Shift' });
await sendKeys({ press: 'Shift+Enter' });
expect(grid.querySelector('vaadin-grid-pro-edit-text-field')).to.not.be.ok;
const target = cell._focusButton || cell;
expect(grid.shadowRoot.activeElement).to.equal(target);
Expand Down
Loading