From 7f7436e77b2933ee42d2c4ab4983e41a5dbf0247 Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Mon, 18 Nov 2024 17:25:06 -0300 Subject: [PATCH 1/6] fix: Clicking repeatedly on 'create' button result in multiple discusions created --- .../client/components/CreateDiscussion/CreateDiscussion.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 - From f1ec30d73128331134e4545afa46fe1d413e1165 Mon Sep 17 00:00:00 2001 From: Martin Schoeler Date: Mon, 18 Nov 2024 17:26:50 -0300 Subject: [PATCH 2/6] Create happy-stingrays-provide.md --- .changeset/happy-stingrays-provide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/happy-stingrays-provide.md 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 From 26a038b18477779e1776938b406e381ad9a5b4d8 Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Tue, 19 Nov 2024 11:23:30 -0300 Subject: [PATCH 3/6] test: Check if only one discussion is being created --- apps/meteor/tests/e2e/message-actions.spec.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/meteor/tests/e2e/message-actions.spec.ts b/apps/meteor/tests/e2e/message-actions.spec.ts index 8c84d6205e8c..8a85fe1773e0 100644 --- a/apps/meteor/tests/e2e/message-actions.spec.ts +++ b/apps/meteor/tests/e2e/message-actions.spec.ts @@ -137,6 +137,7 @@ 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(); @@ -144,8 +145,12 @@ test.describe.serial('message-actions', () => { const createButton = page.getByRole('dialog').getByRole('button', { name: 'create' }); // Name should be prefilled thus making the create button enabled await expect(createButton).not.toBeDisabled(); + await page.locator('role=textbox[name="Name"]').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(page.locator('div.messages-box').getByText(discussionName)).toBeVisible(); }); test('expect star the message', async ({ page }) => { From 6c8e25e0fb4af51fee436333882fe618c036ead0 Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Tue, 19 Nov 2024 15:40:31 -0300 Subject: [PATCH 4/6] test: fix reviews --- apps/meteor/tests/e2e/message-actions.spec.ts | 8 +++++--- apps/meteor/tests/e2e/page-objects/utils.ts | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/meteor/tests/e2e/message-actions.spec.ts b/apps/meteor/tests/e2e/message-actions.spec.ts index 8a85fe1773e0..bb4a1e473c98 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 { Utils, HomeChannel } 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 poUtils: Utils; 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); + poUtils = new Utils(page); await page.goto('/home'); await poHomeChannel.sidenav.openChat(targetChannel); }); @@ -145,12 +147,12 @@ test.describe.serial('message-actions', () => { const createButton = page.getByRole('dialog').getByRole('button', { name: 'create' }); // Name should be prefilled thus making the create button enabled await expect(createButton).not.toBeDisabled(); - await page.locator('role=textbox[name="Name"]').fill(discussionName); + await poUtils.inputName.fill(discussionName); await createButton.click(); 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(page.locator('div.messages-box').getByText(discussionName)).toBeVisible(); + await expect(poUtils.mainContent.getByText(discussionName)).toBeVisible(); }); test('expect star the message', async ({ page }) => { diff --git a/apps/meteor/tests/e2e/page-objects/utils.ts b/apps/meteor/tests/e2e/page-objects/utils.ts index 066c5eac153f..64f3f3924723 100644 --- a/apps/meteor/tests/e2e/page-objects/utils.ts +++ b/apps/meteor/tests/e2e/page-objects/utils.ts @@ -26,4 +26,8 @@ export class Utils { get btnModalConfirmDelete() { return this.page.locator('.rcx-modal >> button >> text="Delete"'); } + + get inputName(): Locator { + return this.page.locator('role=textbox[name="Name"]'); + } } From 8e976caf5588dcb1f01d15c9870cc97097e6ea08 Mon Sep 17 00:00:00 2001 From: dougfabris Date: Tue, 19 Nov 2024 16:29:56 -0300 Subject: [PATCH 5/6] fix: e2e test --- apps/meteor/tests/e2e/message-actions.spec.ts | 12 ++++++------ .../tests/e2e/page-objects/fragments/home-content.ts | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/meteor/tests/e2e/message-actions.spec.ts b/apps/meteor/tests/e2e/message-actions.spec.ts index bb4a1e473c98..9a9fc039c7cd 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 { Utils, 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,7 +8,7 @@ import { expect, test } from './utils/test'; test.use({ storageState: Users.admin.state }); test.describe.serial('message-actions', () => { let poHomeChannel: HomeChannel; - let poUtils: Utils; + let poHomeDiscussion: HomeDiscussion; let targetChannel: string; let forwardChannel: string; let forwardTeam: string; @@ -19,7 +19,7 @@ test.describe.serial('message-actions', () => { }); test.beforeEach(async ({ page }) => { poHomeChannel = new HomeChannel(page); - poUtils = new Utils(page); + poHomeDiscussion = new HomeDiscussion(page); await page.goto('/home'); await poHomeChannel.sidenav.openChat(targetChannel); }); @@ -144,15 +144,15 @@ test.describe.serial('message-actions', () => { 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 poUtils.inputName.fill(discussionName); + await poHomeDiscussion.inputName.fill(discussionName); await createButton.click(); 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(poUtils.mainContent.getByText(discussionName)).toBeVisible(); + await expect(poHomeChannel.content.getMessageByContent(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 2f7677fb8d5d..1f0b4ce65d8e 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts @@ -31,6 +31,10 @@ export class HomeContent { return this.page.locator('role=menu[name="People"]'); } + getMessageByContent(content: string): Locator { + return this.page.locator('[role="listitem"][role-description="message"]').filter({ hasText: content }); + } + get lastUserMessage(): Locator { return this.page.locator('[data-qa-type="message"]').last(); } From 8f389c28d9920ebb793dfd53e61e59378b3d2ea5 Mon Sep 17 00:00:00 2001 From: dougfabris Date: Tue, 19 Nov 2024 18:19:35 -0300 Subject: [PATCH 6/6] test: fix locator --- apps/meteor/tests/e2e/message-actions.spec.ts | 2 +- .../tests/e2e/page-objects/fragments/home-content.ts | 8 ++++---- apps/meteor/tests/e2e/page-objects/utils.ts | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/apps/meteor/tests/e2e/message-actions.spec.ts b/apps/meteor/tests/e2e/message-actions.spec.ts index 9a9fc039c7cd..1dbaf04b3b9b 100644 --- a/apps/meteor/tests/e2e/message-actions.spec.ts +++ b/apps/meteor/tests/e2e/message-actions.spec.ts @@ -152,7 +152,7 @@ test.describe.serial('message-actions', () => { 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.getMessageByContent(discussionName)).toHaveCount(1); + 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 8cc90afdd2c1..0c77364ed57a 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-content.ts @@ -31,10 +31,6 @@ export class HomeContent { return this.page.locator('role=menu[name="People"]'); } - getMessageByContent(content: string): Locator { - return this.page.locator('[role="listitem"][role-description="message"]').filter({ hasText: content }); - } - get lastUserMessage(): Locator { return this.page.locator('[data-qa-type="message"]').last(); } @@ -395,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(); diff --git a/apps/meteor/tests/e2e/page-objects/utils.ts b/apps/meteor/tests/e2e/page-objects/utils.ts index 64f3f3924723..066c5eac153f 100644 --- a/apps/meteor/tests/e2e/page-objects/utils.ts +++ b/apps/meteor/tests/e2e/page-objects/utils.ts @@ -26,8 +26,4 @@ export class Utils { get btnModalConfirmDelete() { return this.page.locator('.rcx-modal >> button >> text="Delete"'); } - - get inputName(): Locator { - return this.page.locator('role=textbox[name="Name"]'); - } }