Reduce flake on edit mock test
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
// Copyright 2023 Signal Messenger, LLC
|
// Copyright 2023 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import type { Locator } from 'playwright';
|
||||||
|
|
||||||
export function bufferToUuid(buffer: Buffer): string {
|
export function bufferToUuid(buffer: Buffer): string {
|
||||||
const hex = buffer.toString('hex');
|
const hex = buffer.toString('hex');
|
||||||
|
|
||||||
@@ -12,3 +14,21 @@ export function bufferToUuid(buffer: Buffer): string {
|
|||||||
hex.substring(20),
|
hex.substring(20),
|
||||||
].join('-');
|
].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();
|
||||||
|
}
|
||||||
|
@@ -16,6 +16,7 @@ import { drop } from '../../util/drop';
|
|||||||
import { strictAssert } from '../../util/assert';
|
import { strictAssert } from '../../util/assert';
|
||||||
import { generateAci } from '../../types/ServiceId';
|
import { generateAci } from '../../types/ServiceId';
|
||||||
import { IMAGE_GIF } from '../../types/MIME';
|
import { IMAGE_GIF } from '../../types/MIME';
|
||||||
|
import { type } from '../helpers';
|
||||||
|
|
||||||
export const debug = createDebug('mock:test:edit');
|
export const debug = createDebug('mock:test:edit');
|
||||||
|
|
||||||
@@ -505,7 +506,7 @@ describe('editing', function (this: Mocha.Suite) {
|
|||||||
.click();
|
.click();
|
||||||
await page.getByRole('menuitem', { name: 'Edit' }).click();
|
await page.getByRole('menuitem', { name: 'Edit' }).click();
|
||||||
const input = await app.waitForEnabledComposer();
|
const input = await app.waitForEnabledComposer();
|
||||||
await input.type(additionalText);
|
await type(input, additionalText);
|
||||||
await input.press('Enter');
|
await input.press('Enter');
|
||||||
}
|
}
|
||||||
const { contacts, desktop } = bootstrap;
|
const { contacts, desktop } = bootstrap;
|
||||||
|
Reference in New Issue
Block a user