Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX, #6659] bug/editing-a-sent-message-deletes-draft-of-new-message #6946

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ts/state/selectors/message.ts
Copy link
Contributor Author

@ben-biddington ben-biddington Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change okay? It's the simplest and first thing I tried.

Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ export const getPropsForMessage = (
textAttachment,
payment,
canCopy: canCopy(message),
canEditMessage: canEditMessage(message),
canEditMessage: !conversation.draftText && canEditMessage(message),
canDeleteForEveryone: canDeleteForEveryone(message, conversation.isMe),
canDownload: canDownload(message, conversationSelector),
canReact: canReact(message, ourConversationId, conversationSelector),
Expand Down
9 changes: 9 additions & 0 deletions ts/test-mock/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { drop } from '../util/drop';
import type { RendererConfigType } from '../types/RendererConfig';
import { App } from './playwright';
import { CONTACT_COUNT } from './benchmarks/fixtures';
import { SignalDesktopUI } from './signal-desktop-ui';

export { App };

Expand Down Expand Up @@ -347,6 +348,14 @@ export class Bootstrap {
return app;
}

public async signalDesktopUI(): Promise<SignalDesktopUI> {
assert(
this.lastApp !== undefined,
'Bootstrap has to be initialized first, see: bootstrap.init()'
);
return new SignalDesktopUI(this.lastApp);
}

public async linkAndClose(): Promise<void> {
const app = await this.link();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import type { Proto } from '@signalapp/mock-server';
import { assert } from 'chai';
import Long from 'long';
import type { App } from '../../playwright';
import * as durations from '../../../util/durations';
import { Bootstrap } from '../../bootstrap';
import type { SignalDesktopUI } from '../../signal-desktop-ui';

const pause = process.env.PAUSE;

const createMessage = (body: string): Proto.IDataMessage => {
return {
body,
groupV2: undefined,
timestamp: Long.fromNumber(Date.now()),
};
};

// https://github.com/signalapp/Signal-Desktop/issues/6659
describe('[6659] Editing a sent message does not delete draft of new message', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);

let bootstrap: Bootstrap;
let app: App;
let ui: SignalDesktopUI;
let sentMessage: Proto.IDataMessage;

beforeEach(async () => {
bootstrap = new Bootstrap({});
await bootstrap.init();
app = await bootstrap.link();
ui = await bootstrap.signalDesktopUI();

const { phone, desktop } = bootstrap;

sentMessage = createMessage('A B C');

await phone.sendRaw(
desktop,
{
dataMessage: sentMessage,
},
{
timestamp: Number(sentMessage.timestamp),
}
);
});

afterEach(async function (this: Mocha.Context) {
if (!pause) {
await bootstrap?.maybeSaveLogs(this.currentTest, app);
await app?.close();
await bootstrap?.teardown();
}
});

/*

See: `ts/components/conversation/MessageContextMenu.tsx`

@todo: test is flaky.

*/
it('disallows editing sent messages when there is a draft present', async () => {
await ui.openFirstConversation();
await ui.typeMessage('Draft message');

assert.isFalse(
await ui.isShowingEditMessageMenuItem(sentMessage.timestamp)
);
});
});
71 changes: 71 additions & 0 deletions ts/test-mock/signal-desktop-ui.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Locator } from 'playwright';
import type { App } from './playwright';

export class SignalDesktopUI {
constructor(private app: App) {}

public openFirstConversation = async (): Promise<void> => {
const window = await this.app.getWindow();
const leftPane = window.locator('#LeftPane');

await leftPane
.locator('.module-conversation-list__item--contact-or-conversation')
.first()
.click();
};

public editMessage = async (
timestamp: Long | null | undefined,
text: string
): Promise<void> => {
const editButton = await this.editMessageButton(timestamp);

await editButton.click();

await this.typeMessage(text);

await this.sendMessage();
};

public isShowingEditMessageMenuItem = async (
timestamp: Long | null | undefined
): Promise<boolean> => {
const page = await this.app.getWindow();

await page
.getByTestId(`${timestamp}`)
.locator('.module-message__buttons__menu')
.click();

const result = await page
.getByRole('menuitem', { name: 'Edit' })
.isVisible();

await page.keyboard.press('Escape');

return result;
};

public typeMessage = async (text: string): Promise<void> => {
const messageTextInput = await this.getMessageTextInput();
await messageTextInput.fill(text);
};

public clearMessage = async (): Promise<void> => {
const messageTextInput = await this.getMessageTextInput();
await messageTextInput.clear();
};

public sendMessage = async (): Promise<void> => {
const messageTextInput = await this.getMessageTextInput();
await messageTextInput.press('Enter');
};

public messageText = async (): Promise<string | null> => {
const messageTextInput = await this.getMessageTextInput();
return messageTextInput.textContent();
};

private getMessageTextInput = (): Promise<Locator> =>
this.app.waitForEnabledComposer();
}