Skip to content

Commit

Permalink
flip sendKeysElem arguments around (#3774)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlockhart authored and bearfriend committed Jun 27, 2023
1 parent 8b90731 commit 481269b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions components/list/test/list-item-drag-handle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ describe('ListItemDragHandle', () => {

async function dispatchKeyEvent(el, key, shiftKey = false) {
if (shiftKey) {
await sendKeysElem('press', `Shift+${key}`, el);
await sendKeysElem(el, 'press', `Shift+${key}`);
} else {
await sendKeysElem('press', key, el);
await sendKeysElem(el, 'press', key);
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/list/test/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('d2l-list', () => {
await focusElem(listItem);
await waitUntil(() => listItem.hasAttribute('_focusing'), 'List item should be focused', { timeout: 3000 });

setTimeout(() => sendKeysElem('down', testCase.keyPress, listItemLayout));
setTimeout(() => sendKeysElem(listItemLayout, 'down', testCase.keyPress));
await oneEvent(listItemLayout, 'keydown');

expect(listItem.hasAttribute('_focusing')).to.be.true;
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('d2l-list', () => {
await focusElem(listItem);
await waitUntil(() => listItem.hasAttribute('_focusing'), 'Initial item should be focused', { timeout: 3000 });

setTimeout(() => sendKeysElem('down', testCase.keyPress, listItemLayout));
setTimeout(() => sendKeysElem(listItemLayout, 'down', testCase.keyPress));
await oneEvent(listItemLayout, 'keydown');

const focusedElement = elem.querySelector(`[key=${testCase.expectedFocus}`);
Expand All @@ -151,7 +151,7 @@ describe('d2l-list', () => {
await focusElem(listItem);
await waitUntil(() => listItem.hasAttribute('_focusing'), 'List item should be focused', { timeout: 3000 });

setTimeout(() => sendKeysElem('down', 'ArrowUp', listItemLayout));
setTimeout(() => sendKeysElem(listItemLayout, 'down', 'ArrowUp'));
await oneEvent(listItemLayout, 'keydown');

expect(listItem.hasAttribute('_focusing')).to.be.true;
Expand Down
22 changes: 11 additions & 11 deletions components/menu/test/menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,42 +81,42 @@ describe('d2l-menu', () => {
});

it('moves focus to next focusable item when down arrow is pressed', async() => {
await sendKeysElem('press', 'ArrowDown', elem.querySelector('#c1'));
await sendKeysElem(elem.querySelector('#c1'), 'press', 'ArrowDown');
expect(document.activeElement).to.equal(elem.querySelector('#d1'));
});

it('moves focus to previous focusable item when up arrow is pressed', async() => {
await sendKeysElem('press', 'ArrowUp', elem.querySelector('#d1'));
await sendKeysElem(elem.querySelector('#d1'), 'press', 'ArrowUp');
expect(document.activeElement).to.equal(elem.querySelector('#c1'));
});

it('moves focus to first focusable item when down arrow is pressed on last focusable item', async() => {
await sendKeysElem('press', 'ArrowDown', elem.querySelector('#d1'));
await sendKeysElem(elem.querySelector('#d1'), 'press', 'ArrowDown');
expect(document.activeElement).to.equal(elem.querySelector('#a1'));
});

it('moves focus to last focusable item when up arrow is pressed on first focusable item', async() => {
await sendKeysElem('press', 'ArrowUp', elem.querySelector('#a1'));
await sendKeysElem(elem.querySelector('#a1'), 'press', 'ArrowUp');
expect(document.activeElement).to.equal(elem.querySelector('#d1'));
});

it('sets focus to disabled menu items', async() => {
await sendKeysElem('press', 'ArrowDown', elem.querySelector('#a1'));
await sendKeysElem(elem.querySelector('#a1'), 'press', 'ArrowDown');
expect(document.activeElement).to.equal(elem.querySelector('#b1'));
});

it('sets focus to next item that starts with character pressed', async() => {
await sendKeysElem('press', 'c', elem.querySelector('#a1'));
await sendKeysElem(elem.querySelector('#a1'), 'press', 'c');
expect(document.activeElement).to.equal(elem.querySelector('#c1'));
});

it('sets focus to next item that starts with uppercase character pressed', async() => {
await sendKeysElem('press', 'C', elem.querySelector('#a1'));
await sendKeysElem(elem.querySelector('#a1'), 'press', 'C');
expect(document.activeElement).to.equal(elem.querySelector('#c1'));
});

it('sets focus by rolling over to beginning of menu when searching if necessary', async() => {
await sendKeysElem('press', 'b', elem.querySelector('#c1'));
await sendKeysElem(elem.querySelector('#c1'), 'press', 'b');
expect(document.activeElement).to.equal(elem.querySelector('#b1'));
});

Expand Down Expand Up @@ -175,23 +175,23 @@ describe('d2l-menu', () => {
});

it('shows nested menu when right arrow is pressed on opener', async() => {
setTimeout(() => sendKeysElem('press', 'ArrowRight', elem.querySelector('#b1')));
setTimeout(() => sendKeysElem(elem.querySelector('#b1'), 'press', 'ArrowRight'));
await oneEvent(elem, 'd2l-hierarchical-view-show-complete');
expect(nestedMenu.isActive()).to.be.true;
});

it('hides nested menu when left arrow is pressed in nested menu', async() => {
setTimeout(() => clickElem(elem.querySelector('#b1')));
await oneEvent(elem, 'd2l-hierarchical-view-show-complete');
setTimeout(() => sendKeysElem('press', 'ArrowLeft', elem.querySelector('#b2')));
setTimeout(() => sendKeysElem(elem.querySelector('#b2'), 'press', 'ArrowLeft'));
await oneEvent(elem, 'd2l-hierarchical-view-hide-complete');
expect(elem.isActive()).to.be.true;
});

it('hides nested menu when escape is pressed in nested menu', async() => {
setTimeout(() => clickElem(elem.querySelector('#b1')));
await oneEvent(elem, 'd2l-hierarchical-view-show-complete');
setTimeout(() => sendKeysElem('press', 'Escape', elem.querySelector('#b2')));
setTimeout(() => sendKeysElem(elem.querySelector('#b2'), 'press', 'Escape'));
await oneEvent(elem, 'd2l-hierarchical-view-hide-complete');
expect(elem.isActive()).to.be.true;
});
Expand Down
2 changes: 1 addition & 1 deletion components/switch/test/switch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('d2l-switch', () => {
['Space', 'Enter'].forEach((key) => {
it(`should toggle when ${key} is pressed`, async() => {
const elem = await fixture(switchFixture);
setTimeout(() => sendKeysElem('press', key, elem));
setTimeout(() => sendKeysElem(elem, 'press', key));
await oneEvent(elem, 'change');
expect(elem.on).to.be.true;
});
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"@babel/eslint-parser": "^7",
"@brightspace-ui/stylelint-config": "^0.8",
"@brightspace-ui/testing": "^0.10",
"@brightspace-ui/testing": "^0.11",
"@open-wc/semantic-dom-diff": "^0.20",
"@rollup/plugin-dynamic-import-vars": "^2",
"@rollup/plugin-node-resolve": "^15",
Expand Down

0 comments on commit 481269b

Please sign in to comment.