diff --git a/ts/test-mock/helpers.ts b/ts/test-mock/helpers.ts index 9747647aedc..ed8ed68101f 100644 --- a/ts/test-mock/helpers.ts +++ b/ts/test-mock/helpers.ts @@ -1,6 +1,8 @@ // Copyright 2023 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only +import type { Locator } from 'playwright'; + export function bufferToUuid(buffer: Buffer): string { const hex = buffer.toString('hex'); @@ -12,3 +14,21 @@ export function bufferToUuid(buffer: Buffer): string { hex.substring(20), ].join('-'); } + +export async function type(input: Locator, text: string): Promise { + let currentValue = ''; + + try { + currentValue = await input.inputValue(); + } catch (e) { + // 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 }); + + // 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(); +} diff --git a/ts/test-mock/messaging/edit_test.ts b/ts/test-mock/messaging/edit_test.ts index 609bf9f5e4c..41c1bf537d6 100644 --- a/ts/test-mock/messaging/edit_test.ts +++ b/ts/test-mock/messaging/edit_test.ts @@ -16,6 +16,7 @@ import { drop } from '../../util/drop'; import { strictAssert } from '../../util/assert'; import { generateAci } from '../../types/ServiceId'; import { IMAGE_GIF } from '../../types/MIME'; +import { type } from '../helpers'; export const debug = createDebug('mock:test:edit'); @@ -505,7 +506,7 @@ describe('editing', function (this: Mocha.Suite) { .click(); await page.getByRole('menuitem', { name: 'Edit' }).click(); const input = await app.waitForEnabledComposer(); - await input.type(additionalText); + await type(input, additionalText); await input.press('Enter'); } const { contacts, desktop } = bootstrap;