Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
hariombalhara committed Dec 18, 2023
1 parent c70a2cc commit f15b504
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions apps/web/playwright/organization/organization-invitation.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ test.describe.serial("Organization", () => {
});

assertInviteLink(inviteLink);
await signupFromEmailInviteLink(browser, inviteLink);
await signupFromEmailInviteLink({
browser,
inviteLink,
expectedEmail: invitedUserEmail,
expectedUsername: usernameDerivedFromEmail,
});

const dbUser = await prisma.user.findUnique({ where: { email: invitedUserEmail } });
expect(dbUser?.username).toBe(usernameDerivedFromEmail);
Expand Down Expand Up @@ -118,7 +123,12 @@ test.describe.serial("Organization", () => {

assertInviteLink(inviteLink);

await signupFromEmailInviteLink(browser, inviteLink);
await signupFromEmailInviteLink({
browser,
inviteLink,
expectedEmail: invitedUserEmail,
expectedUsername: usernameDerivedFromEmail,
});

const dbUser = await prisma.user.findUnique({ where: { email: invitedUserEmail } });
expect(dbUser?.username).toBe(usernameDerivedFromEmail);
Expand Down Expand Up @@ -200,7 +210,12 @@ test.describe.serial("Organization", () => {
});

assertInviteLink(inviteLink);
await signupFromEmailInviteLink(browser, inviteLink);
await signupFromEmailInviteLink({
browser,
inviteLink,
expectedEmail: invitedUserEmail,
expectedUsername: usernameDerivedFromEmail,
});

const dbUser = await prisma.user.findUnique({ where: { email: invitedUserEmail } });
expect(dbUser?.username).toBe(usernameDerivedFromEmail);
Expand Down Expand Up @@ -276,7 +291,12 @@ test.describe.serial("Organization", () => {

assertInviteLink(inviteLink);

await signupFromEmailInviteLink(browser, inviteLink);
await signupFromEmailInviteLink({
browser,
inviteLink,
expectedEmail: invitedUserEmail,
expectedUsername: usernameDerivedFromEmail,
});

const dbUser = await prisma.user.findUnique({ where: { email: invitedUserEmail } });
expect(dbUser?.username).toBe(usernameDerivedFromEmail);
Expand Down Expand Up @@ -356,14 +376,30 @@ async function signupFromInviteLink({
return { email };
}

async function signupFromEmailInviteLink(browser: Browser, inviteLink: string) {
async function signupFromEmailInviteLink({
browser,
inviteLink,
expectedUsername,
expectedEmail,
}: {
browser: Browser;
inviteLink: string;
expectedUsername: string;
expectedEmail: string;
}) {
// Follow invite link in new window
const context = await browser.newContext();
const signupPage = await context.newPage();

signupPage.goto(inviteLink);
await signupPage.waitForLoadState("networkidle");
await expect(signupPage.locator(`[data-testid="signup-usernamefield"]`)).toBeDisabled();
expect(await signupPage.locator(`[data-testid="signup-usernamefield"]`).inputValue()).toBe(
expectedUsername
);
await expect(signupPage.locator(`[data-testid="signup-emailfield"]`)).toBeDisabled();
expect(await signupPage.locator(`[data-testid="signup-emailfield"]`).inputValue()).toBe(expectedEmail);

await signupPage.waitForLoadState("networkidle");
// Check required fields
await signupPage.locator("input[name=password]").fill(`P4ssw0rd!`);
Expand Down

0 comments on commit f15b504

Please sign in to comment.