Reduce flake on edit mock test

This commit is contained in:
trevor-signal 2023-12-06 19:44:08 -05:00 committed by GitHub
parent d6db3f7943
commit ecf5019cd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -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<void> {
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();
}

View file

@ -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;