mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Fix flakey edits mock test
This commit is contained in:
@@ -168,7 +168,7 @@ Bootstrap.benchmark(async (bootstrap: Bootstrap): Promise<void> => {
|
||||
const start = Date.now();
|
||||
|
||||
// test
|
||||
await typeIntoInput(SearchBar, searchContact.profileName);
|
||||
await typeIntoInput(SearchBar, searchContact.profileName, '');
|
||||
await CreateCallLink.waitFor({ state: 'hidden' }); // hides when searching
|
||||
await expect(OtherCallListItems).not.toBeAttached();
|
||||
await sendCallEventSync(
|
||||
|
||||
@@ -219,7 +219,7 @@ Bootstrap.benchmark(async (bootstrap: Bootstrap): Promise<void> => {
|
||||
});
|
||||
|
||||
debug('entering message text');
|
||||
await typeIntoInput(input, `my message ${runId}`);
|
||||
await typeIntoInput(input, `my message ${runId}`, '');
|
||||
await input.press('Enter');
|
||||
|
||||
debug('waiting for message on server side');
|
||||
|
||||
@@ -89,7 +89,7 @@ Bootstrap.benchmark(async (bootstrap: Bootstrap): Promise<void> => {
|
||||
const input = await waitForEnabledComposer(window);
|
||||
|
||||
debug('entering message text');
|
||||
await typeIntoInput(input, `my message ${runId}`);
|
||||
await typeIntoInput(input, `my message ${runId}`, '');
|
||||
await input.press('Enter');
|
||||
|
||||
debug('waiting for message on server side');
|
||||
|
||||
@@ -33,29 +33,34 @@ export function bufferToUuid(buffer: Buffer): string {
|
||||
|
||||
export async function typeIntoInput(
|
||||
input: Locator,
|
||||
text: string
|
||||
additionalText: string,
|
||||
previousText: string
|
||||
): Promise<void> {
|
||||
let currentValue = '';
|
||||
let isInputElement = true;
|
||||
const updatedText = `${previousText}${additionalText}`;
|
||||
|
||||
// Check if the element is an `input` or `[contenteditable]`
|
||||
let isInputElement = true;
|
||||
try {
|
||||
currentValue = await input.inputValue();
|
||||
// Discard value, we're using a matcher later to assert the previous value
|
||||
await input.inputValue();
|
||||
} catch (e) {
|
||||
isInputElement = false;
|
||||
// if input is actually not an input (e.g. contenteditable)
|
||||
currentValue = (await input.textContent()) ?? '';
|
||||
}
|
||||
|
||||
const newValue = `${currentValue}${text}`;
|
||||
if (isInputElement) {
|
||||
await expect(input).toHaveValue(previousText);
|
||||
} else {
|
||||
await expect(input).toHaveText(previousText);
|
||||
}
|
||||
|
||||
await input.fill(newValue);
|
||||
await input.fill(updatedText);
|
||||
|
||||
// Wait to ensure that the input (and react state controlling it) has actually
|
||||
// updated with the right value
|
||||
if (isInputElement) {
|
||||
await expect(input).toHaveValue(newValue);
|
||||
await expect(input).toHaveValue(updatedText);
|
||||
} else {
|
||||
await input.locator(`:text("${newValue}")`).waitFor();
|
||||
await expect(input).toHaveText(updatedText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,7 +366,7 @@ export async function sendMessageWithAttachments(
|
||||
|
||||
debug('sending message');
|
||||
const input = await waitForEnabledComposer(page);
|
||||
await typeIntoInput(input, text);
|
||||
await typeIntoInput(input, text, '');
|
||||
await input.press('Enter');
|
||||
|
||||
const Message = getTimelineMessageWithText(page, text);
|
||||
|
||||
@@ -98,7 +98,8 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
async function sendEditedMessage(
|
||||
page: Page,
|
||||
timestamp: number,
|
||||
additionalText: string
|
||||
additionalText: string,
|
||||
previousText: string
|
||||
) {
|
||||
await page
|
||||
.getByTestId(`${timestamp}`)
|
||||
@@ -106,7 +107,7 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
.click();
|
||||
await page.getByRole('menuitem', { name: 'Edit' }).click();
|
||||
const input = await waitForEnabledComposer(page);
|
||||
await typeIntoInput(input, additionalText);
|
||||
await typeIntoInput(input, additionalText, previousText);
|
||||
await input.press('Enter');
|
||||
}
|
||||
|
||||
@@ -324,7 +325,7 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
const input = await waitForEnabledComposer(window);
|
||||
|
||||
debug('entering original message text');
|
||||
await typeIntoInput(input, 'edit message 1');
|
||||
await typeIntoInput(input, 'edit message 1', '');
|
||||
await input.press('Enter');
|
||||
}
|
||||
|
||||
@@ -335,7 +336,8 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
await sendEditedMessage(
|
||||
window,
|
||||
originalMessage.timestamp?.toNumber() ?? 0,
|
||||
'.2'
|
||||
'.2',
|
||||
'edit message 1'
|
||||
);
|
||||
|
||||
debug("waiting for friend's edit message");
|
||||
@@ -349,7 +351,8 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
await sendEditedMessage(
|
||||
window,
|
||||
originalMessage.timestamp?.toNumber() ?? 0,
|
||||
'.3'
|
||||
'.3',
|
||||
'edit message 1.2'
|
||||
);
|
||||
|
||||
const { editMessage: secondEdit } = await friend.waitForEditMessage();
|
||||
@@ -545,7 +548,7 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
const input = await waitForEnabledComposer(page);
|
||||
|
||||
debug('sending message desktop -> friend');
|
||||
await typeIntoInput(input, originalText);
|
||||
await typeIntoInput(input, originalText, '');
|
||||
await input.press('Enter');
|
||||
}
|
||||
|
||||
@@ -615,7 +618,7 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
debug('finding composition input and clicking it v2');
|
||||
|
||||
debug('sending edit message v2 desktop -> friend');
|
||||
await sendEditedMessage(page, originalMessageTimestamp, '2');
|
||||
await sendEditedMessage(page, originalMessageTimestamp, '2', '1');
|
||||
|
||||
{
|
||||
const readReceiptTimestamp = bootstrap.getTimestamp();
|
||||
@@ -670,7 +673,8 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
await sendEditedMessage(
|
||||
page,
|
||||
originalMessage?.timestamp?.toNumber() ?? 0,
|
||||
'3'
|
||||
'3',
|
||||
'12'
|
||||
);
|
||||
|
||||
debug("waiting for message on friend's device (v3)");
|
||||
@@ -691,7 +695,8 @@ describe('editing', function (this: Mocha.Suite) {
|
||||
await sendEditedMessage(
|
||||
page,
|
||||
originalMessage?.timestamp?.toNumber() ?? 0,
|
||||
'4'
|
||||
'4',
|
||||
'123'
|
||||
);
|
||||
|
||||
debug("waiting for message on friend's device (v4)");
|
||||
|
||||
@@ -251,7 +251,7 @@ describe('messaging/expireTimerVersion', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello');
|
||||
await typeIntoInput(compositionInput, 'Hello', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ describe('safety number', function (this: Mocha.Suite) {
|
||||
await clickOnConversation(window, alice);
|
||||
|
||||
const input = await waitForEnabledComposer(window);
|
||||
await typeIntoInput(input, 'Hello Alice!');
|
||||
await typeIntoInput(input, 'Hello Alice!', '');
|
||||
|
||||
await changeIdentityKey();
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ describe('Libsignal-net', function (this: Mocha.Suite) {
|
||||
|
||||
debug('sending outgoing message');
|
||||
const input = await waitForEnabledComposer(window);
|
||||
await typeIntoInput(input, 'outgoing message');
|
||||
await typeIntoInput(input, 'outgoing message', '');
|
||||
await input.press('Enter');
|
||||
|
||||
debug('waiting for message on server side');
|
||||
|
||||
@@ -133,7 +133,7 @@ describe('pnp/merge', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello ACI');
|
||||
await typeIntoInput(compositionInput, 'Hello ACI', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ describe('pnp/merge', function (this: Mocha.Suite) {
|
||||
debug('Send message to PNI');
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello PNI');
|
||||
await typeIntoInput(compositionInput, 'Hello PNI', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ describe('pnp/merge', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello merged');
|
||||
await typeIntoInput(compositionInput, 'Hello merged', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ describe('pnp/merge', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello merged');
|
||||
await typeIntoInput(compositionInput, 'Hello merged', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -530,7 +530,7 @@ describe('pnp/merge', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello merged');
|
||||
await typeIntoInput(compositionInput, 'Hello merged', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ describe('pnp/phone discovery', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello PNI');
|
||||
await typeIntoInput(compositionInput, 'Hello PNI', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ describe('pnp/PNI Change', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'message to contactA');
|
||||
await typeIntoInput(compositionInput, 'message to contactA', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ describe('pnp/PNI Change', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'message to contactA');
|
||||
await typeIntoInput(compositionInput, 'message to contactA', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ describe('pnp/PNI Change', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'message to contactA');
|
||||
await typeIntoInput(compositionInput, 'message to contactA', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ describe('pnp/PNI Change', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'message to contactB');
|
||||
await typeIntoInput(compositionInput, 'message to contactB', '');
|
||||
await compositionInput.press('Enter');
|
||||
|
||||
// We get a safety number change warning, because we get a different identity key!
|
||||
@@ -440,7 +440,7 @@ describe('pnp/PNI Change', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'message to contactA');
|
||||
await typeIntoInput(compositionInput, 'message to contactA', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -526,7 +526,7 @@ describe('pnp/PNI Change', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'second message to contactA');
|
||||
await typeIntoInput(compositionInput, 'second message to contactA', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ describe('pnp/PNI Signature', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'first');
|
||||
await typeIntoInput(compositionInput, 'first', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
debug('Wait for the first message with pni signature');
|
||||
@@ -178,7 +178,7 @@ describe('pnp/PNI Signature', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'second');
|
||||
await typeIntoInput(compositionInput, 'second', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
debug('Wait for the second message with pni signature');
|
||||
@@ -212,7 +212,7 @@ describe('pnp/PNI Signature', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'third');
|
||||
await typeIntoInput(compositionInput, 'third', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
debug('Wait for the third message without pni signature');
|
||||
@@ -376,7 +376,7 @@ describe('pnp/PNI Signature', function (this: Mocha.Suite) {
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
debug('Enter an ACI message text');
|
||||
await typeIntoInput(compositionInput, 'Hello ACI');
|
||||
await typeIntoInput(compositionInput, 'Hello ACI', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ describe('pnp/username', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello username');
|
||||
await typeIntoInput(compositionInput, 'Hello username', '');
|
||||
await compositionInput.press('Enter');
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ describe('pnp/username', function (this: Mocha.Suite) {
|
||||
|
||||
debug('entering new username');
|
||||
const usernameField = profileEditor.locator('.Input__input');
|
||||
await typeIntoInput(usernameField, NICKNAME);
|
||||
await typeIntoInput(usernameField, NICKNAME, '');
|
||||
|
||||
debug('waiting for generated discriminator');
|
||||
const discriminator = profileEditor.locator(
|
||||
@@ -311,7 +311,7 @@ describe('pnp/username', function (this: Mocha.Suite) {
|
||||
await window.getByRole('button', { name: 'New chat' }).click();
|
||||
|
||||
const searchInput = window.locator('.module-SearchInput__container input');
|
||||
await typeIntoInput(searchInput, CARL_USERNAME);
|
||||
await typeIntoInput(searchInput, CARL_USERNAME, '');
|
||||
|
||||
debug('starting lookup');
|
||||
await window
|
||||
@@ -322,7 +322,7 @@ describe('pnp/username', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello Carl');
|
||||
await typeIntoInput(compositionInput, 'Hello Carl', '');
|
||||
await compositionInput.press('Enter');
|
||||
|
||||
const { body, source } = await carl.waitForMessage();
|
||||
@@ -379,7 +379,7 @@ describe('pnp/username', function (this: Mocha.Suite) {
|
||||
{
|
||||
const compositionInput = await waitForEnabledComposer(window);
|
||||
|
||||
await typeIntoInput(compositionInput, 'Hello Carl');
|
||||
await typeIntoInput(compositionInput, 'Hello Carl', '');
|
||||
await compositionInput.press('Enter');
|
||||
|
||||
const { body, source } = await carl.waitForMessage();
|
||||
|
||||
@@ -122,7 +122,7 @@ describe('challenge/receipts', function (this: Mocha.Suite) {
|
||||
debug('Sending a message back to user - will trigger captcha!');
|
||||
{
|
||||
const input = await waitForEnabledComposer(window);
|
||||
await typeIntoInput(input, 'Hi, good to hear from you!');
|
||||
await typeIntoInput(input, 'Hi, good to hear from you!', '');
|
||||
await input.press('Enter');
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ describe('challenge/receipts', function (this: Mocha.Suite) {
|
||||
debug('Sending a message back to ContactB - will trigger captcha!');
|
||||
{
|
||||
const input = await waitForEnabledComposer(window);
|
||||
await typeIntoInput(input, 'Hi, good to hear from you!');
|
||||
await typeIntoInput(input, 'Hi, good to hear from you!', '');
|
||||
await input.press('Enter');
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ describe('challenge/receipts', function (this: Mocha.Suite) {
|
||||
debug('Sending a message back to user - will trigger captcha!');
|
||||
{
|
||||
const input = await waitForEnabledComposer(window);
|
||||
await typeIntoInput(input, 'Hi, good to hear from you!');
|
||||
await typeIntoInput(input, 'Hi, good to hear from you!', '');
|
||||
await input.press('Enter');
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ describe('challenge/receipts', function (this: Mocha.Suite) {
|
||||
debug('Sending another message - this time it should not trigger captcha!');
|
||||
{
|
||||
const input = await waitForEnabledComposer(window);
|
||||
await typeIntoInput(input, 'How have you been lately?');
|
||||
await typeIntoInput(input, 'How have you been lately?', '');
|
||||
await input.press('Enter');
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ describe('challenge/receipts', function (this: Mocha.Suite) {
|
||||
);
|
||||
{
|
||||
const input = await waitForEnabledComposer(window);
|
||||
await typeIntoInput(input, 'You the cow guy from craigslist?');
|
||||
await typeIntoInput(input, 'You the cow guy from craigslist?', '');
|
||||
await input.press('Enter');
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ describe('storage service', function (this: Mocha.Suite) {
|
||||
|
||||
debug('Enter message text');
|
||||
const input = await waitForEnabledComposer(window);
|
||||
await typeIntoInput(input, 'hello stranger!');
|
||||
await typeIntoInput(input, 'hello stranger!', '');
|
||||
await input.press('Enter');
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user