Skip to content

Commit

Permalink
fix: Clicking repeatedly on 'create' button result in multiple discus…
Browse files Browse the repository at this point in the history
…ions created (#33985)

Co-authored-by: dougfabris <[email protected]>
  • Loading branch information
MartinSchoeler and dougfabris authored Nov 19, 2024
1 parent d1e6a73 commit 2db1ecb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-stingrays-provide.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug
const t = useTranslation();

const {
formState: { isSubmitting, isValidating, errors },
formState: { errors },
handleSubmit,
control,
watch,
Expand Down Expand Up @@ -246,7 +246,7 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug
<Modal.Footer>
<Modal.FooterControllers>
<Button onClick={onClose}>{t('Cancel')}</Button>
<Button type='submit' primary loading={isSubmitting || isValidating}>
<Button type='submit' primary loading={createDiscussionMutation.isLoading}>
{t('Create')}
</Button>
</Modal.FooterControllers>
Expand Down
13 changes: 10 additions & 3 deletions apps/meteor/tests/e2e/message-actions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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';

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;
Expand All @@ -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);
});
Expand Down Expand Up @@ -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 }) => {
Expand Down
4 changes: 4 additions & 0 deletions apps/meteor/tests/e2e/page-objects/fragments/home-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await this.page.locator('role=main').waitFor();
await this.page.locator('role=main >> role=heading[level=1]').waitFor();
Expand Down

0 comments on commit 2db1ecb

Please sign in to comment.