Skip to content

Commit 5f6b887

Browse files
fix: Mentions popup remains open after canceling message edit (#38635)
1 parent afaabea commit 5f6b887

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ComposerBoxPopupResult<T extends { _id: string; sort?: number }> =
2828
suspended: boolean;
2929
filter: unknown;
3030
clear: () => void;
31+
update: () => void;
3132
}
3233
| {
3334
option: undefined;
@@ -39,6 +40,7 @@ type ComposerBoxPopupResult<T extends { _id: string; sort?: number }> =
3940
suspended: undefined;
4041
filter: unknown;
4142
clear: () => void;
43+
update: () => void;
4244
};
4345

4446
const keys = {
@@ -269,6 +271,7 @@ export const useComposerBoxPopup = <T extends { _id: string; sort?: number }>(
269271
suspended: undefined,
270272
filter: undefined,
271273
clear,
274+
update: setOptionByInput,
272275
};
273276
}
274277

@@ -282,5 +285,6 @@ export const useComposerBoxPopup = <T extends { _id: string; sort?: number }>(
282285
suspended,
283286
filter,
284287
clear,
288+
update: setOptionByInput,
285289
};
286290
};

apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,15 @@ const MessageBox = ({
178178
event.stopPropagation();
179179

180180
chat.currentEditingMessage.reset().then((reset) => {
181-
if (!reset) {
182-
chat.currentEditingMessage.cancel();
183-
chat.currentEditingMessage.stop();
181+
// NOTE: if the message was reset (i.e. content changed), we just update the popup (to re-apply/remove the preview)
182+
if (reset) {
183+
popup.update();
184+
return;
184185
}
186+
187+
chat.currentEditingMessage.cancel();
188+
chat.currentEditingMessage.stop();
189+
popup.clear();
185190
});
186191
}
187192
};
@@ -378,7 +383,6 @@ const MessageBox = ({
378383
);
379384

380385
const shouldPopupPreview = useEnablePopupPreview(popup.filter, popup.option);
381-
382386
return (
383387
<>
384388
{chat.composer?.quotedMessages && <MessageBoxReplies />}

apps/meteor/tests/e2e/message-composer.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,62 @@ test.describe.serial('message-composer', () => {
116116
});
117117
});
118118

119+
test('should close mention popup when canceling a message edit via "Cancel" button', async ({ page }) => {
120+
await poHomeChannel.navbar.openChat(targetChannel);
121+
await poHomeChannel.content.sendMessage('hello composer');
122+
123+
await test.step('expect to edit last message', async () => {
124+
await expect(poHomeChannel.composer.inputMessage).toHaveValue('');
125+
await poHomeChannel.content.openLastMessageMenu();
126+
await poHomeChannel.content.btnOptionEditMessage.click();
127+
await expect(poHomeChannel.composer.inputMessage).toHaveValue('hello composer');
128+
});
129+
130+
await test.step('expect to open popup on mention', async () => {
131+
await page.keyboard.type(' @');
132+
await expect(poHomeChannel.composer.boxPopup).toBeVisible();
133+
});
134+
135+
await test.step('expect popup to close after the first edit is cancelled', async () => {
136+
await poHomeChannel.composer.btnCancel.click();
137+
await expect(poHomeChannel.composer.inputMessage).toHaveValue('hello composer');
138+
await expect(poHomeChannel.composer.boxPopup).not.toBeVisible();
139+
});
140+
141+
await test.step('expect to leave editing mode', async () => {
142+
await poHomeChannel.composer.btnCancel.click();
143+
await expect(poHomeChannel.composer.inputMessage).toHaveValue('');
144+
});
145+
});
146+
147+
test('should close mention popup when canceling a message edit via keyboard', async ({ page }) => {
148+
await poHomeChannel.navbar.openChat(targetChannel);
149+
await poHomeChannel.content.sendMessage('hello composer');
150+
151+
await test.step('expect to edit last message', async () => {
152+
await expect(poHomeChannel.composer.inputMessage).toHaveValue('');
153+
await poHomeChannel.content.openLastMessageMenu();
154+
await poHomeChannel.content.btnOptionEditMessage.click();
155+
await expect(poHomeChannel.composer.inputMessage).toHaveValue('hello composer');
156+
});
157+
158+
await test.step('expect to open popup on mention', async () => {
159+
await page.keyboard.type(' @');
160+
await expect(poHomeChannel.composer.boxPopup).toBeVisible();
161+
});
162+
163+
await test.step('expect popup to close after the first edit is cancelled', async () => {
164+
await page.keyboard.press('Escape');
165+
await expect(poHomeChannel.composer.inputMessage).toHaveValue('hello composer');
166+
await expect(poHomeChannel.composer.boxPopup).not.toBeVisible();
167+
});
168+
169+
await test.step('expect to leave editing mode', async () => {
170+
await page.keyboard.press('Escape');
171+
await expect(poHomeChannel.composer.inputMessage).toHaveValue('');
172+
});
173+
});
174+
119175
test.describe('audio recorder', () => {
120176
test('should open audio recorder', async () => {
121177
await poHomeChannel.navbar.openChat(targetChannel);

apps/meteor/tests/e2e/page-objects/fragments/composer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export abstract class Composer {
3333
return this.root.getByRole('button', { name: 'Send' });
3434
}
3535

36+
get btnCancel(): Locator {
37+
return this.root.getByRole('button', { name: 'Cancel', exact: true });
38+
}
39+
3640
get btnOptionFileUpload(): Locator {
3741
return this.toolbarPrimaryActions.getByRole('button', { name: 'Upload file' });
3842
}

0 commit comments

Comments
 (0)