Use typing helper in mock-tests

This commit is contained in:
trevor-signal 2024-04-03 13:17:39 -04:00 committed by GitHub
parent 257813265c
commit e96a1e4bc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 83 additions and 89 deletions

View file

@ -3,6 +3,7 @@
import { assert } from 'chai';
import type { Locator, Page } from 'playwright';
import { expect } from 'playwright/test';
export function bufferToUuid(buffer: Buffer): string {
const hex = buffer.toString('hex');
@ -16,22 +17,30 @@ export function bufferToUuid(buffer: Buffer): string {
].join('-');
}
export async function type(input: Locator, text: string): Promise<void> {
export async function typeIntoInput(
input: Locator,
text: string
): Promise<void> {
let currentValue = '';
let isInputElement = true;
try {
currentValue = await input.inputValue();
} catch (e) {
isInputElement = false;
// if input is actually not an input (e.g. contenteditable)
currentValue = (await input.textContent()) ?? '';
}
// Type with a reasonably human delay
await input.type(text, { delay: 100 });
await input.type(text, { delay: 30 });
// Wait to ensure that the input (and react state controlling it) has actually
// updated with the right value
await input.locator(`:text("${currentValue}${text}")`).waitFor();
if (isInputElement) {
await expect(input).toHaveValue(`${currentValue}${text}`);
} else {
await input.locator(`:text("${currentValue}${text}")`).waitFor();
}
}
export async function expectItemsWithText(