diff --git a/.changeset/happy-stingrays-provide.md b/.changeset/happy-stingrays-provide.md new file mode 100644 index 000000000000..fba25665133a --- /dev/null +++ b/.changeset/happy-stingrays-provide.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixes issue that could cause multiple discussions to be created when creating it from a message action diff --git a/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx b/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx index b1dcb9d8dfbc..99bcd5db6bf7 100644 --- a/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx +++ b/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx @@ -46,7 +46,7 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug const t = useTranslation(); const { - formState: { isSubmitting, isValidating, errors }, + formState: { errors }, handleSubmit, control, watch, @@ -246,7 +246,7 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug - diff --git a/apps/meteor/tests/e2e/message-actions.spec.ts b/apps/meteor/tests/e2e/message-actions.spec.ts index 8c84d6205e8c..1dbaf04b3b9b 100644 --- a/apps/meteor/tests/e2e/message-actions.spec.ts +++ b/apps/meteor/tests/e2e/message-actions.spec.ts @@ -1,6 +1,6 @@ import { ADMIN_CREDENTIALS } from './config/constants'; import { Users } from './fixtures/userStates'; -import { HomeChannel } from './page-objects'; +import { HomeChannel, HomeDiscussion } from './page-objects'; import { createTargetChannel, createTargetTeam } from './utils'; import { setUserPreferences } from './utils/setUserPreferences'; import { expect, test } from './utils/test'; @@ -8,6 +8,7 @@ import { expect, test } from './utils/test'; test.use({ storageState: Users.admin.state }); test.describe.serial('message-actions', () => { let poHomeChannel: HomeChannel; + let poHomeDiscussion: HomeDiscussion; let targetChannel: string; let forwardChannel: string; let forwardTeam: string; @@ -18,6 +19,7 @@ test.describe.serial('message-actions', () => { }); test.beforeEach(async ({ page }) => { poHomeChannel = new HomeChannel(page); + poHomeDiscussion = new HomeDiscussion(page); await page.goto('/home'); await poHomeChannel.sidenav.openChat(targetChannel); }); @@ -137,15 +139,20 @@ test.describe.serial('message-actions', () => { test('expect create a discussion from message', async ({ page }) => { const message = `Message for discussion - ${Date.now()}`; + const discussionName = `Discussion Name - ${Date.now()}`; await poHomeChannel.content.sendMessage(message); await poHomeChannel.content.openLastMessageMenu(); await page.locator('role=menuitem[name="Start a Discussion"]').click(); - const createButton = page.getByRole('dialog').getByRole('button', { name: 'create' }); + const createButton = poHomeDiscussion.btnCreate; // Name should be prefilled thus making the create button enabled await expect(createButton).not.toBeDisabled(); + await poHomeDiscussion.inputName.fill(discussionName); await createButton.click(); - await expect(page.locator('header h1')).toHaveText(message); + await expect(page.locator('header h1')).toHaveText(discussionName); + await poHomeChannel.sidenav.openChat(targetChannel); + // Should fail if more than one discussion has been created + await expect(poHomeChannel.content.getMessageByText(discussionName)).toHaveCount(1); }); test('expect star the message', async ({ page }) => { diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts index 55d2d2a91a96..0c77364ed57a 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts @@ -391,6 +391,10 @@ export class HomeContent { return this.page.locator('[aria-roledescription="system message"]', { hasText: text }); } + getMessageByText(text: string): Locator { + return this.page.locator('[role="listitem"][aria-roledescription="message"]', { hasText: text }); + } + async waitForChannel(): Promise { await this.page.locator('role=main').waitFor(); await this.page.locator('role=main >> role=heading[level=1]').waitFor();