Files
myeasycms-v2/apps/e2e/tests/invitations/invitations.spec.ts
Giancarlo Buomprisco 02e2502dcc Enhance E2E Tests and Configuration (#358)
* Enhance E2E Tests and Configuration

- Updated `.gitignore` to exclude `.auth/` directory for cleaner test environment.
- Added `test:fast` script in `package.json` for faster Playwright test execution.
- Configured Playwright to include a setup project for initializing tests.
- Introduced `AUTH_STATES` utility for managing authentication states in tests.
- Created `auth.setup.ts` for user authentication tests, ensuring proper login flows.
- Refactored various test files to utilize the new authentication state management, improving test reliability and maintainability.
- Adjusted team and user billing tests to streamline setup and enhance clarity.
- Refactored some dialogs
2025-09-21 12:28:42 +08:00

142 lines
3.4 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { InvitationsPageObject } from './invitations.po';
test.describe('Invitations', () => {
let invitations: InvitationsPageObject;
test.beforeEach(async ({ page }) => {
invitations = new InvitationsPageObject(page);
await invitations.setup();
});
test('users can delete invites', async () => {
await invitations.navigateToMembers();
await invitations.openInviteForm();
const email = invitations.auth.createRandomEmail();
const invites = [
{
email,
role: 'member',
},
];
await invitations.inviteMembers(invites);
await expect(invitations.getInvitations()).toHaveCount(1);
await invitations.deleteInvitation(email);
await expect(invitations.getInvitations()).toHaveCount(0);
});
test('users can update invites', async () => {
await invitations.navigateToMembers();
await invitations.openInviteForm();
const email = invitations.auth.createRandomEmail();
const invites = [
{
email,
role: 'member',
},
];
await invitations.inviteMembers(invites);
await expect(invitations.getInvitations()).toHaveCount(1);
await invitations.updateInvitation(email, 'owner');
const row = invitations.getInvitationRow(email);
await expect(row.locator('[data-test="member-role-badge"]')).toHaveText(
'Owner',
);
});
test('user cannot invite a member of the team again', async ({ page }) => {
await invitations.navigateToMembers();
const email = invitations.auth.createRandomEmail();
const invites = [
{
email,
role: 'member',
},
];
await invitations.openInviteForm();
await invitations.inviteMembers(invites);
await expect(invitations.getInvitations()).toHaveCount(1);
// Try to invite the same member again
// This should fail
await invitations.openInviteForm();
await invitations.inviteMembers(invites);
await page.waitForTimeout(500);
await expect(invitations.getInvitations()).toHaveCount(1);
});
});
test.describe('Full Invitation Flow', () => {
test('should invite users and let users accept an invite', async ({
page,
}) => {
const invitations = new InvitationsPageObject(page);
await invitations.setup();
await invitations.navigateToMembers();
const invites = [
{
email: invitations.auth.createRandomEmail(),
role: 'member',
},
{
email: invitations.auth.createRandomEmail(),
role: 'member',
},
];
await invitations.openInviteForm();
await invitations.inviteMembers(invites);
const firstEmail = invites[0]!.email;
await expect(invitations.getInvitations()).toHaveCount(2);
// sign out and sign in with the first email
await page.context().clearCookies();
await page.reload();
console.log(`Finding email to ${firstEmail} ...`);
await invitations.auth.visitConfirmEmailLink(firstEmail);
console.log(`Signing up with ${firstEmail} ...`);
await invitations.auth.signUp({
email: firstEmail,
password: 'password',
repeatPassword: 'password',
});
await invitations.auth.visitConfirmEmailLink(firstEmail);
console.log(`Accepting invitation as ${firstEmail}`);
await invitations.acceptInvitation();
await invitations.teamAccounts.openAccountsSelector();
await expect(invitations.teamAccounts.getTeams()).toHaveCount(1);
});
});