Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 73 additions & 7 deletions apps/meteor/tests/e2e/export-messages.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,6 +26,13 @@ test.describe.serial('export-messages', () => {
await page.goto('/home');
});

test.afterAll(async ({ api }) => {
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 }) => {
const exportMessagesTab = new ExportMessagesTab(page);

Expand Down Expand Up @@ -66,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(
Expand All @@ -96,14 +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(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(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(message1).click();

await expect(exportMessagesTab.getMessageCheckbox(message1)).toBeChecked();
await expect(exportMessagesTab.getMessageCheckbox(message2)).not.toBeChecked();
await expect(exportMessagesTab.clearSelectionButton).toBeEnabled();

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: { hideFlexTab: true },
});
const message1 = uniqueMessage();
const message2 = uniqueMessage();

const exportMessagesTab = new ExportMessagesTab(page);

await poHomeChannel.sidenav.openChat(targetChannel);
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(message1).click();

await expect(exportMessagesTab.getMessageCheckbox(message1)).toBeChecked();
await expect(exportMessagesTab.clearSelectionButton).toBeEnabled();

await expect(poHomeChannel.content.getMessageByText('hello export')).toBeVisible();
await expect(exportMessagesTab.sendButton).toBeEnabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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');
}
Expand All @@ -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' });
}
}
Loading