Skip to content

Commit 27af6be

Browse files
authoredOct 14, 2024··
fix: tests for keyboard typing (#2371)
1 parent 96b09e5 commit 27af6be

File tree

5 files changed

+127
-119
lines changed

5 files changed

+127
-119
lines changed
 

‎.changeset/green-chefs-live.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lion/ui': minor
3+
---
4+
5+
[combobox] change mimicUserTyping test helper function async and use sendKeys() internally

‎.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
},
1818
{
1919
files: [
20+
'**/test-helpers/**/*.js',
2021
'**/test-suites/**/*.js',
2122
'**/test/**/*.js',
2223
'**/test-node/**/*.{j,mj}s',

‎packages/ui/components/combobox/test-helpers/combobox-helpers.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getListboxMembers } from '@lion/ui/listbox-test-helpers.js';
2+
import { sendKeys } from '@web/test-runner-commands';
23

34
/**
45
* @typedef {import('@lion/ui/combobox.js').LionCombobox} LionCombobox
@@ -34,17 +35,15 @@ export function getComboboxMembers(el) {
3435

3536
/**
3637
* @param {LionCombobox} el
37-
* @param {string} value
38+
* @param {string} keys
3839
*/
39-
// TODO: add keys that actually make sense...
40-
export function mimicUserTyping(el, value) {
40+
export async function mimicUserTyping(el, keys) {
4141
const { _inputNode } = getComboboxMembers(el);
42-
_inputNode.dispatchEvent(new Event('focusin', { bubbles: true }));
43-
// eslint-disable-next-line no-param-reassign
44-
_inputNode.value = value;
45-
_inputNode.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
46-
_inputNode.dispatchEvent(new KeyboardEvent('keyup', { key: value }));
47-
_inputNode.dispatchEvent(new KeyboardEvent('keydown', { key: value }));
42+
_inputNode.value = '';
43+
_inputNode.focus();
44+
await sendKeys({
45+
type: keys,
46+
});
4847
}
4948

5049
/**

‎packages/ui/components/combobox/test/lion-combobox.test.js

+111-108
Large diffs are not rendered by default.

‎packages/ui/components/combobox/test/validators.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ describe('MatchesOption validation', () => {
2525
config.node = el;
2626
const validator = new MatchesOption();
2727

28-
mimicUserTyping(el, 'Artichoke');
28+
await mimicUserTyping(el, 'Artichoke');
2929
await el.updateComplete;
3030

3131
isEnabled = validator.execute('Artichoke', undefined, config);
3232
expect(isEnabled).to.be.false;
3333

34-
mimicUserTyping(el, 'Foo');
34+
await mimicUserTyping(el, 'Foo');
3535
await el.updateComplete;
3636

3737
isEnabled = validator.execute('Foo', undefined, config);

0 commit comments

Comments
 (0)
Please sign in to comment.