Skip to content

Commit 0ca189f

Browse files
test: export messages with hide contextual bar preference (RocketChat#36564)
1 parent 759b178 commit 0ca189f

2 files changed

Lines changed: 85 additions & 7 deletions

File tree

apps/meteor/tests/e2e/export-messages.spec.ts

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import { faker } from '@faker-js/faker';
2+
13
import { Users } from './fixtures/userStates';
24
import { HomeChannel, Utils } from './page-objects';
35
import { ExportMessagesTab } from './page-objects/fragments/export-messages-tab';
4-
import { createTargetChannel } from './utils';
6+
import { createTargetChannel, deleteChannel } from './utils';
57
import { test, expect } from './utils/test';
68

79
test.use({ storageState: Users.admin.state });
810

9-
test.describe.serial('export-messages', () => {
11+
const uniqueMessage = (): string => `msg-${faker.string.uuid()}`;
12+
13+
test.describe('export-messages', () => {
1014
let poHomeChannel: HomeChannel;
1115
let poUtils: Utils;
1216
let targetChannel: string;
@@ -22,6 +26,13 @@ test.describe.serial('export-messages', () => {
2226
await page.goto('/home');
2327
});
2428

29+
test.afterAll(async ({ api }) => {
30+
await Promise.all([
31+
api.post('/users.setPreferences', { userId: 'rocketchat.internal.admin.test', data: { hideFlexTab: false } }),
32+
deleteChannel(api, targetChannel),
33+
]);
34+
});
35+
2536
test('should all export methods be available in targetChannel', async ({ page }) => {
2637
const exportMessagesTab = new ExportMessagesTab(page);
2738

@@ -66,15 +77,16 @@ test.describe.serial('export-messages', () => {
6677

6778
test('should display an error when trying to send email without filling to users or to additional emails', async ({ page }) => {
6879
const exportMessagesTab = new ExportMessagesTab(page);
80+
const testMessage = uniqueMessage();
6981

7082
await poHomeChannel.sidenav.openChat(targetChannel);
71-
await poHomeChannel.content.sendMessage('hello world');
83+
await poHomeChannel.content.sendMessage(testMessage);
7284
await poHomeChannel.tabs.kebab.click({ force: true });
7385
await poHomeChannel.tabs.btnExportMessages.click();
7486

7587
await expect(poHomeChannel.btnContextualbarClose).toBeVisible();
7688

77-
await poHomeChannel.content.getMessageByText('hello world').click();
89+
await poHomeChannel.content.getMessageByText(testMessage).click();
7890
await exportMessagesTab.send();
7991

8092
await expect(
@@ -96,14 +108,68 @@ test.describe.serial('export-messages', () => {
96108
});
97109

98110
test('should be able to send messages after closing export messages', async () => {
111+
const message1 = uniqueMessage();
112+
const message2 = uniqueMessage();
113+
99114
await poHomeChannel.sidenav.openChat(targetChannel);
115+
await poHomeChannel.content.sendMessage(message1);
100116
await poHomeChannel.tabs.kebab.click({ force: true });
101117
await poHomeChannel.tabs.btnExportMessages.click();
102118

103-
await poHomeChannel.content.getMessageByText('hello world').click();
119+
await poHomeChannel.content.getMessageByText(message1).click();
104120
await poHomeChannel.btnContextualbarClose.click();
105-
await poHomeChannel.content.sendMessage('hello export');
121+
await poHomeChannel.content.sendMessage(message2);
122+
123+
await expect(poHomeChannel.content.getMessageByText(message2)).toBeVisible();
124+
});
125+
126+
test('should be able to select a single message to export', async ({ page }) => {
127+
const exportMessagesTab = new ExportMessagesTab(page);
128+
const message1 = uniqueMessage();
129+
const message2 = uniqueMessage();
130+
131+
await poHomeChannel.sidenav.openChat(targetChannel);
132+
await poHomeChannel.content.sendMessage(message1);
133+
await poHomeChannel.content.sendMessage(message2);
134+
135+
await poHomeChannel.tabs.kebab.click({ force: true });
136+
await poHomeChannel.tabs.btnExportMessages.click();
137+
await expect(exportMessagesTab.dialog).toBeVisible();
138+
139+
await poHomeChannel.content.getMessageByText(message1).click();
140+
141+
await expect(exportMessagesTab.getMessageCheckbox(message1)).toBeChecked();
142+
await expect(exportMessagesTab.getMessageCheckbox(message2)).not.toBeChecked();
143+
await expect(exportMessagesTab.clearSelectionButton).toBeEnabled();
144+
145+
await expect(exportMessagesTab.sendButton).toBeEnabled();
146+
});
147+
148+
// TODO: Fix this test - the test is failing because when selecting the message, the import messages tab becomes not visible
149+
// and the message is not selected.
150+
test.fail('should be able to select a single message to export with hide contextual bar preference enabled', async ({ page, api }) => {
151+
await api.post('/users.setPreferences', {
152+
userId: 'rocketchat.internal.admin.test',
153+
data: { hideFlexTab: true },
154+
});
155+
const message1 = uniqueMessage();
156+
const message2 = uniqueMessage();
157+
158+
const exportMessagesTab = new ExportMessagesTab(page);
159+
160+
await poHomeChannel.sidenav.openChat(targetChannel);
161+
await poHomeChannel.content.sendMessage(message1);
162+
await poHomeChannel.content.sendMessage(message2);
163+
164+
await poHomeChannel.tabs.kebab.click({ force: true });
165+
await poHomeChannel.tabs.btnExportMessages.click();
166+
167+
await expect(exportMessagesTab.dialog).toBeVisible();
168+
await poHomeChannel.content.getMessageByText(message1).click();
169+
170+
await expect(exportMessagesTab.getMessageCheckbox(message1)).toBeChecked();
171+
await expect(exportMessagesTab.clearSelectionButton).toBeEnabled();
106172

107-
await expect(poHomeChannel.content.getMessageByText('hello export')).toBeVisible();
173+
await expect(exportMessagesTab.sendButton).toBeEnabled();
108174
});
109175
});

apps/meteor/tests/e2e/page-objects/fragments/export-messages-tab.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export class ExportMessagesTab {
77
this.root = page.getByRole('dialog', { name: 'Export Messages' });
88
}
99

10+
get dialog() {
11+
return this.root;
12+
}
13+
1014
async exposeMethods() {
1115
await this.method.click();
1216
}
@@ -53,6 +57,10 @@ export class ExportMessagesTab {
5357
await this.toAdditionalEmailsInput.fill(email);
5458
}
5559

60+
getMessageCheckbox(messageText: string): Locator {
61+
return this.root.page().getByRole('listitem').filter({ hasText: messageText }).getByRole('checkbox');
62+
}
63+
5664
get method() {
5765
return this.root.getByTestId('export-messages-method');
5866
}
@@ -72,4 +80,8 @@ export class ExportMessagesTab {
7280
get sendButton() {
7381
return this.root.getByRole('button', { name: 'Send', exact: true });
7482
}
83+
84+
get clearSelectionButton() {
85+
return this.root.page().getByRole('button', { name: 'Clear selection' });
86+
}
7587
}

0 commit comments

Comments
 (0)