Skip to content

Commit

Permalink
fix: tests for keyboard typing
Browse files Browse the repository at this point in the history
  • Loading branch information
okadurin authored and gerjanvangeest committed Oct 14, 2024
1 parent b25478e commit c808d9e
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 119 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-chefs-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': minor
---

[combobox] change mimicUserTyping test helper function async and use sendKeys() internally
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
},
{
files: [
'**/test-helpers/**/*.js',
'**/test-suites/**/*.js',
'**/test/**/*.js',
'**/test-node/**/*.{j,mj}s',
Expand Down
17 changes: 8 additions & 9 deletions packages/ui/components/combobox/test-helpers/combobox-helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getListboxMembers } from '@lion/ui/listbox-test-helpers.js';
import { sendKeys } from '@web/test-runner-commands';

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

/**
* @param {LionCombobox} el
* @param {string} value
* @param {string} keys
*/
// TODO: add keys that actually make sense...
export function mimicUserTyping(el, value) {
export async function mimicUserTyping(el, keys) {
const { _inputNode } = getComboboxMembers(el);
_inputNode.dispatchEvent(new Event('focusin', { bubbles: true }));
// eslint-disable-next-line no-param-reassign
_inputNode.value = value;
_inputNode.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
_inputNode.dispatchEvent(new KeyboardEvent('keyup', { key: value }));
_inputNode.dispatchEvent(new KeyboardEvent('keydown', { key: value }));
_inputNode.value = '';
_inputNode.focus();
await sendKeys({
type: keys,
});
}

/**
Expand Down
Loading

0 comments on commit c808d9e

Please sign in to comment.