Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
39 lines
874 B
TypeScript
39 lines
874 B
TypeScript
import { act, fireEvent } from '@mui/internal-test-utils';
|
|
|
|
function delay(ms: number) {
|
|
return new Promise((r) => {
|
|
setTimeout(r, ms);
|
|
});
|
|
}
|
|
|
|
export async function asyncFireEvent(node: Element, event: keyof typeof fireEvent, options?: any) {
|
|
await act(async () => {
|
|
fireEvent[event](node, options);
|
|
await delay(1);
|
|
});
|
|
}
|
|
|
|
export function startTouch(node: Element, options?: any) {
|
|
return asyncFireEvent(node, 'mouseDown', options);
|
|
}
|
|
|
|
export async function stopTouch(node: Element) {
|
|
return asyncFireEvent(node, 'mouseUp');
|
|
}
|
|
|
|
export async function startFocus(node: HTMLElement) {
|
|
await act(async () => {
|
|
node.blur();
|
|
fireEvent.keyDown(document.body, { key: 'Tab' });
|
|
node.focus();
|
|
await delay(1);
|
|
});
|
|
}
|
|
|
|
export async function stopFocus(node: HTMLElement) {
|
|
await act(async () => {
|
|
node.blur();
|
|
await delay(1);
|
|
});
|
|
}
|