Use typing helper in mock-tests
This commit is contained in:
parent
257813265c
commit
e96a1e4bc3
11 changed files with 83 additions and 89 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue