diff --git a/apps/e2e/tests/invitations/invitations.po.ts b/apps/e2e/tests/invitations/invitations.po.ts new file mode 100644 index 000000000..0d0a33ecb --- /dev/null +++ b/apps/e2e/tests/invitations/invitations.po.ts @@ -0,0 +1,60 @@ +import { Page } from '@playwright/test'; +import { AuthPageObject } from '../authentication/auth.po'; +import { TeamAccountsPageObject } from '../team-accounts/team-accounts.po'; + +export class InvitationsPageObject { + private readonly page: Page; + public auth: AuthPageObject; + public teamAccounts: TeamAccountsPageObject; + + constructor(page: Page) { + this.page = page; + this.auth = new AuthPageObject(page); + this.teamAccounts = new TeamAccountsPageObject(page); + } + + async setup() { + await this.teamAccounts.setup(); + } + + public async inviteMembers(invites: Array<{ + email: string; + role: string; + }>) { + const form = this.getInviteForm(); + + for (let index = 0; index < invites.length; index++) { + const invite = invites[index]; + + if (!invite) { + continue; + } + + const nth = index + 1; + + await this.page.fill(`[data-test="invite-member-form-item"]:nth-child(${nth}) [data-test="invite-email-input"]`, invite.email); + await this.page.click(`[data-test="invite-member-form-item"]:nth-child(${nth}) [data-test="role-selector-trigger"]`); + await this.page.click(`[data-test="role-option-${invite.role}"]`); + + if (index < invites.length - 1) { + await form.locator('[data-test="add-new-invite-button"]').click(); + } + } + + await form.locator('button[type="submit"]').click(); + } + + public navigateToMembers() { + return this.page.locator('a', { + hasText: 'Members', + }).click(); + } + + async openInviteForm() { + await this.page.locator('[data-test="invite-members-form-trigger"]').click(); + } + + private getInviteForm() { + return this.page.locator('[data-test="invite-members-form"]'); + } +} \ No newline at end of file diff --git a/apps/e2e/tests/invitations/invitations.spec.ts b/apps/e2e/tests/invitations/invitations.spec.ts new file mode 100644 index 000000000..dc2202258 --- /dev/null +++ b/apps/e2e/tests/invitations/invitations.spec.ts @@ -0,0 +1,34 @@ +import { Page, test } from '@playwright/test'; +import { InvitationsPageObject } from './invitations.po'; + +test.describe('Invitations', () => { + let page: Page; + let invitations: InvitationsPageObject; + + test.beforeAll(async ({ browser }) => { + page = await browser.newPage(); + invitations = new InvitationsPageObject(page); + + await invitations.setup(); + }); + + test('user invite users', async ({page}) => { + await page.waitForLoadState('networkidle'); + + await invitations.navigateToMembers(); + await invitations.openInviteForm(); + + const invites = [ + { + email: invitations.auth.createRandomEmail(), + role: 'member' + }, + { + email: invitations.auth.createRandomEmail(), + role: 'member' + }, + ]; + + await invitations.inviteMembers(invites); + }); +}); diff --git a/apps/web/app/(dashboard)/home/[account]/members/page.tsx b/apps/web/app/(dashboard)/home/[account]/members/page.tsx index 6924624eb..94ae5c8ba 100644 --- a/apps/web/app/(dashboard)/home/[account]/members/page.tsx +++ b/apps/web/app/(dashboard)/home/[account]/members/page.tsx @@ -135,7 +135,7 @@ async function TeamAccountMembersPage({ params }: Params) { accountId={account.id} accountSlug={account.slug} > -