From 99eafc64cfb76b778f13072db607a099b4949e36 Mon Sep 17 00:00:00 2001 From: Jessica Schelly Souza Date: Tue, 29 Jul 2025 16:16:03 -0300 Subject: [PATCH 1/2] test: add tests for hide contextual bar preference on export msgs --- apps/meteor/tests/e2e/export-messages.spec.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/apps/meteor/tests/e2e/export-messages.spec.ts b/apps/meteor/tests/e2e/export-messages.spec.ts index 3c1804f6c2062..46ee51cecce03 100644 --- a/apps/meteor/tests/e2e/export-messages.spec.ts +++ b/apps/meteor/tests/e2e/export-messages.spec.ts @@ -22,6 +22,10 @@ test.describe.serial('export-messages', () => { await page.goto('/home'); }); + test.afterAll(async ({ api }) => { + await api.post('/users.setPreferences', { userId: 'rocketchat.internal.admin.test', data: { hideContextualBar: false } }); + }); + test('should all export methods be available in targetChannel', async ({ page }) => { const exportMessagesTab = new ExportMessagesTab(page); @@ -106,4 +110,41 @@ test.describe.serial('export-messages', () => { await expect(poHomeChannel.content.getMessageByText('hello export')).toBeVisible(); }); + + test('should be able to select a single message to export', async ({ page }) => { + const exportMessagesTab = new ExportMessagesTab(page); + + await poHomeChannel.sidenav.openChat(targetChannel); + await poHomeChannel.content.sendMessage('hello world'); + await poHomeChannel.content.sendMessage('hello export'); + + await poHomeChannel.tabs.kebab.click({ force: true }); + await poHomeChannel.tabs.btnExportMessages.click(); + + await poHomeChannel.content.getMessageByText('hello world').click(); + + await exportMessagesTab.setAdditionalEmail('mail@mail.com'); + await expect(exportMessagesTab.sendButton).toBeEnabled(); + }); + + test.fail('should be able to select a single message to export with hide contextual bar preference enabled', async ({ page, api }) => { + await api.post('/users.setPreferences', { + userId: 'rocketchat.internal.admin.test', + data: { hideContextualBar: true }, + }); + + const exportMessagesTab = new ExportMessagesTab(page); + + await poHomeChannel.sidenav.openChat(targetChannel); + await poHomeChannel.content.sendMessage('hello world'); + await poHomeChannel.content.sendMessage('hello export'); + + await poHomeChannel.tabs.kebab.click({ force: true }); + await poHomeChannel.tabs.btnExportMessages.click(); + + await poHomeChannel.content.getMessageByText('hello world').click(); + + await exportMessagesTab.setAdditionalEmail('mail@mail.com'); + await expect(exportMessagesTab.sendButton).toBeEnabled(); + }); }); From fee671c8fc2edd49e8dcc009c55e1e1b3e987405 Mon Sep 17 00:00:00 2001 From: Jessica Schelly Souza Date: Tue, 29 Jul 2025 18:37:44 -0300 Subject: [PATCH 2/2] improve selectors --- apps/meteor/tests/e2e/export-messages.spec.ts | 59 +++++++++++++------ .../fragments/export-messages-tab.ts | 12 ++++ 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/apps/meteor/tests/e2e/export-messages.spec.ts b/apps/meteor/tests/e2e/export-messages.spec.ts index 46ee51cecce03..238a6a1d9d9cf 100644 --- a/apps/meteor/tests/e2e/export-messages.spec.ts +++ b/apps/meteor/tests/e2e/export-messages.spec.ts @@ -1,12 +1,16 @@ +import { faker } from '@faker-js/faker'; + import { Users } from './fixtures/userStates'; import { HomeChannel, Utils } from './page-objects'; import { ExportMessagesTab } from './page-objects/fragments/export-messages-tab'; -import { createTargetChannel } from './utils'; +import { createTargetChannel, deleteChannel } from './utils'; import { test, expect } from './utils/test'; test.use({ storageState: Users.admin.state }); -test.describe.serial('export-messages', () => { +const uniqueMessage = (): string => `msg-${faker.string.uuid()}`; + +test.describe('export-messages', () => { let poHomeChannel: HomeChannel; let poUtils: Utils; let targetChannel: string; @@ -23,7 +27,10 @@ test.describe.serial('export-messages', () => { }); test.afterAll(async ({ api }) => { - await api.post('/users.setPreferences', { userId: 'rocketchat.internal.admin.test', data: { hideContextualBar: false } }); + await Promise.all([ + api.post('/users.setPreferences', { userId: 'rocketchat.internal.admin.test', data: { hideFlexTab: false } }), + deleteChannel(api, targetChannel), + ]); }); test('should all export methods be available in targetChannel', async ({ page }) => { @@ -70,15 +77,16 @@ test.describe.serial('export-messages', () => { test('should display an error when trying to send email without filling to users or to additional emails', async ({ page }) => { const exportMessagesTab = new ExportMessagesTab(page); + const testMessage = uniqueMessage(); await poHomeChannel.sidenav.openChat(targetChannel); - await poHomeChannel.content.sendMessage('hello world'); + await poHomeChannel.content.sendMessage(testMessage); await poHomeChannel.tabs.kebab.click({ force: true }); await poHomeChannel.tabs.btnExportMessages.click(); await expect(poHomeChannel.btnContextualbarClose).toBeVisible(); - await poHomeChannel.content.getMessageByText('hello world').click(); + await poHomeChannel.content.getMessageByText(testMessage).click(); await exportMessagesTab.send(); await expect( @@ -100,51 +108,68 @@ test.describe.serial('export-messages', () => { }); test('should be able to send messages after closing export messages', async () => { + const message1 = uniqueMessage(); + const message2 = uniqueMessage(); + await poHomeChannel.sidenav.openChat(targetChannel); + await poHomeChannel.content.sendMessage(message1); await poHomeChannel.tabs.kebab.click({ force: true }); await poHomeChannel.tabs.btnExportMessages.click(); - await poHomeChannel.content.getMessageByText('hello world').click(); + await poHomeChannel.content.getMessageByText(message1).click(); await poHomeChannel.btnContextualbarClose.click(); - await poHomeChannel.content.sendMessage('hello export'); + await poHomeChannel.content.sendMessage(message2); - await expect(poHomeChannel.content.getMessageByText('hello export')).toBeVisible(); + await expect(poHomeChannel.content.getMessageByText(message2)).toBeVisible(); }); test('should be able to select a single message to export', async ({ page }) => { const exportMessagesTab = new ExportMessagesTab(page); + const message1 = uniqueMessage(); + const message2 = uniqueMessage(); await poHomeChannel.sidenav.openChat(targetChannel); - await poHomeChannel.content.sendMessage('hello world'); - await poHomeChannel.content.sendMessage('hello export'); + await poHomeChannel.content.sendMessage(message1); + await poHomeChannel.content.sendMessage(message2); await poHomeChannel.tabs.kebab.click({ force: true }); await poHomeChannel.tabs.btnExportMessages.click(); + await expect(exportMessagesTab.dialog).toBeVisible(); - await poHomeChannel.content.getMessageByText('hello world').click(); + await poHomeChannel.content.getMessageByText(message1).click(); + + await expect(exportMessagesTab.getMessageCheckbox(message1)).toBeChecked(); + await expect(exportMessagesTab.getMessageCheckbox(message2)).not.toBeChecked(); + await expect(exportMessagesTab.clearSelectionButton).toBeEnabled(); - await exportMessagesTab.setAdditionalEmail('mail@mail.com'); await expect(exportMessagesTab.sendButton).toBeEnabled(); }); + // TODO: Fix this test - the test is failing because when selecting the message, the import messages tab becomes not visible + // and the message is not selected. test.fail('should be able to select a single message to export with hide contextual bar preference enabled', async ({ page, api }) => { await api.post('/users.setPreferences', { userId: 'rocketchat.internal.admin.test', - data: { hideContextualBar: true }, + data: { hideFlexTab: true }, }); + const message1 = uniqueMessage(); + const message2 = uniqueMessage(); const exportMessagesTab = new ExportMessagesTab(page); await poHomeChannel.sidenav.openChat(targetChannel); - await poHomeChannel.content.sendMessage('hello world'); - await poHomeChannel.content.sendMessage('hello export'); + await poHomeChannel.content.sendMessage(message1); + await poHomeChannel.content.sendMessage(message2); await poHomeChannel.tabs.kebab.click({ force: true }); await poHomeChannel.tabs.btnExportMessages.click(); - await poHomeChannel.content.getMessageByText('hello world').click(); + await expect(exportMessagesTab.dialog).toBeVisible(); + await poHomeChannel.content.getMessageByText(message1).click(); + + await expect(exportMessagesTab.getMessageCheckbox(message1)).toBeChecked(); + await expect(exportMessagesTab.clearSelectionButton).toBeEnabled(); - await exportMessagesTab.setAdditionalEmail('mail@mail.com'); await expect(exportMessagesTab.sendButton).toBeEnabled(); }); }); diff --git a/apps/meteor/tests/e2e/page-objects/fragments/export-messages-tab.ts b/apps/meteor/tests/e2e/page-objects/fragments/export-messages-tab.ts index b2604b6b6f409..fdb6822f1362f 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/export-messages-tab.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/export-messages-tab.ts @@ -7,6 +7,10 @@ export class ExportMessagesTab { this.root = page.getByRole('dialog', { name: 'Export Messages' }); } + get dialog() { + return this.root; + } + async exposeMethods() { await this.method.click(); } @@ -53,6 +57,10 @@ export class ExportMessagesTab { await this.toAdditionalEmailsInput.fill(email); } + getMessageCheckbox(messageText: string): Locator { + return this.root.page().getByRole('listitem').filter({ hasText: messageText }).getByRole('checkbox'); + } + get method() { return this.root.getByTestId('export-messages-method'); } @@ -72,4 +80,8 @@ export class ExportMessagesTab { get sendButton() { return this.root.getByRole('button', { name: 'Send', exact: true }); } + + get clearSelectionButton() { + return this.root.page().getByRole('button', { name: 'Clear selection' }); + } }