Skip to content

Commit

Permalink
chore: add some e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Dec 9, 2024
1 parent 845f2f0 commit ced342f
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ const ExportMessages = () => {
rules={{
validate: {
validateEmail: (additionalEmails) => {
if (additionalEmails === '') {
return undefined;
}

const emails = additionalEmails?.split(',').map((email) => email.trim());
if (Array.isArray(emails) && emails.every((email) => validateEmail(email.trim()))) {
return undefined;
Expand Down Expand Up @@ -290,7 +294,7 @@ const ExportMessages = () => {
/>
</FieldRow>
{errors?.additionalEmails && (
<FieldError aria-live='assertive' id={`${additionalEmailsField}-error`}>
<FieldError role='alert' id={`${additionalEmailsField}-error`}>
{errors.additionalEmails.message}
</FieldError>
)}
Expand Down
14 changes: 14 additions & 0 deletions apps/meteor/tests/e2e/e2e-encryption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ test.describe.serial('e2e-encryption initial setup', () => {
);
await expect(poHomeChannel.content.nthMessage(0).locator('.rcx-icon--name-key')).toBeVisible();
});

test('should display only the download file method when exporting messages in an e2ee room', async ({ page }) => {
await page.goto('/home');
const channelName = faker.string.uuid();
await poHomeChannel.sidenav.createEncryptedChannel(channelName);
await expect(page).toHaveURL(`/group/${channelName}`);

await poHomeChannel.dismissToast();
await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible();

await poHomeChannel.tabs.kebab.click({ force: true });
await poHomeChannel.tabs.btnExportMessages.click();
await expect(poHomeChannel.tabs.exportMessages.downloadFileMethod).toBeVisible();
});
});

test.describe.serial('e2e-encryption', () => {
Expand Down
61 changes: 61 additions & 0 deletions apps/meteor/tests/e2e/export-messages.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Users } from './fixtures/userStates';
import { HomeChannel, Utils } from './page-objects';
import { createTargetChannel } from './utils';
import { test, expect } from './utils/test';

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

test.describe.serial('export-messages', () => {
let poHomeChannel: HomeChannel;
let poUtils: Utils;
let targetChannel: string;

test.beforeAll(async ({ api }) => {
targetChannel = await createTargetChannel(api);
});

test.beforeEach(async ({ page }) => {
poHomeChannel = new HomeChannel(page);
poUtils = new Utils(page);

await page.goto('/home');
});

test('should all export methods be available in targetChannel', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.tabs.kebab.click({ force: true });
await poHomeChannel.tabs.btnExportMessages.click();
await expect(poHomeChannel.tabs.exportMessages.sendEmailMethod).not.toBeDisabled();

await poHomeChannel.tabs.exportMessages.sendEmailMethod.click();
await expect(poHomeChannel.tabs.exportMessages.getMethodByName('Send email')).toBeVisible();
await expect(poHomeChannel.tabs.exportMessages.getMethodByName('Send file via email')).toBeVisible();
await expect(poHomeChannel.tabs.exportMessages.getMethodByName('Download file')).toBeVisible();
});

test('should display an error when trying to send email without filling to users or to additional emails', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.content.sendMessage('hello world');
await poHomeChannel.tabs.kebab.click({ force: true });
await poHomeChannel.tabs.btnExportMessages.click();

await poHomeChannel.content.getMessageByText('hello world').click();
await poHomeChannel.tabs.exportMessages.btnSend.click();

await expect(
poUtils.getAlertByText('You must select one or more users or provide one or more email addresses, separated by commas'),
).toBeVisible();
});

test('should display an error when trying to send email without selecting any email', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.content.sendMessage('hello world');
await poHomeChannel.tabs.kebab.click({ force: true });
await poHomeChannel.tabs.btnExportMessages.click();

await poHomeChannel.tabs.exportMessages.textboxAdditionalEmails.fill('[email protected]');
await poHomeChannel.tabs.exportMessages.btnSend.click();

await expect(poUtils.getAlertByText(`You haven't selected any messages`)).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Page } from '@playwright/test';

export class HomeFlextabExportMessages {
private readonly page: Page;

constructor(page: Page) {
this.page = page;
}

get sendEmailMethod() {
return this.page.getByLabel('Send email');
}

get downloadFileMethod() {
return this.page.getByLabel('Download file');
}

getMethodByName(name: string) {
return this.page.getByRole('option', { name });
}

get textboxAdditionalEmails() {
return this.page.getByRole('textbox', { name: 'To additional emails' });
}

get btnSend() {
return this.page.locator('role=button[name="Send"]');
}
}
8 changes: 8 additions & 0 deletions apps/meteor/tests/e2e/page-objects/fragments/home-flextab.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Locator, Page } from '@playwright/test';

import { HomeFlextabChannels } from './home-flextab-channels';
import { HomeFlextabExportMessages } from './home-flextab-exportMessages';
import { HomeFlextabMembers } from './home-flextab-members';
import { HomeFlextabNotificationPreferences } from './home-flextab-notificationPreferences';
import { HomeFlextabRoom } from './home-flextab-room';
Expand All @@ -16,12 +17,15 @@ export class HomeFlextab {

readonly notificationPreferences: HomeFlextabNotificationPreferences;

readonly exportMessages: HomeFlextabExportMessages;

constructor(page: Page) {
this.page = page;
this.members = new HomeFlextabMembers(page);
this.room = new HomeFlextabRoom(page);
this.channels = new HomeFlextabChannels(page);
this.notificationPreferences = new HomeFlextabNotificationPreferences(page);
this.exportMessages = new HomeFlextabExportMessages(page);
}

get btnTabMembers(): Locator {
Expand All @@ -48,6 +52,10 @@ export class HomeFlextab {
return this.page.locator('role=menuitem[name="Notifications Preferences"]');
}

get btnExportMessages(): Locator {
return this.page.locator('role=menuitem[name="Export messages"]');
}

get btnE2EERoomSetupDisableE2E(): Locator {
return this.page.locator('[data-qa-id=ToolBoxAction-key]');
}
Expand Down
6 changes: 6 additions & 0 deletions apps/meteor/tests/e2e/page-objects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ export class Utils {
get btnModalConfirmDelete() {
return this.page.locator('.rcx-modal >> button >> text="Delete"');
}

getAlertByText(text: string): Locator {
return this.page.locator('[role="alert"]', {
hasText: text,
});
}
}

0 comments on commit ced342f

Please sign in to comment.