fix: Clicking repeatedly on 'create' button result in multiple discusions created (#33985)

Co-authored-by: dougfabris <devfabris@gmail.com>
pull/33975/head^2
Martin Schoeler 1 year ago committed by GitHub
parent d1e6a73796
commit 2db1ecb0ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/happy-stingrays-provide.md
  2. 4
      apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx
  3. 13
      apps/meteor/tests/e2e/message-actions.spec.ts
  4. 4
      apps/meteor/tests/e2e/page-objects/fragments/home-content.ts

@ -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

@ -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
<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>

@ -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 }) => {

@ -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();

Loading…
Cancel
Save