2022-03-28 20:06:41 +00:00
|
|
|
import { expect } from "@playwright/test";
|
2022-04-06 15:13:09 +00:00
|
|
|
import { UserPlan } from "@prisma/client";
|
2022-03-28 20:06:41 +00:00
|
|
|
|
2022-04-06 15:13:09 +00:00
|
|
|
import { login } from "./fixtures/users";
|
2022-03-28 20:06:41 +00:00
|
|
|
import { test } from "./lib/fixtures";
|
2022-04-06 15:13:09 +00:00
|
|
|
import { localize } from "./lib/testUtils";
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test.describe.configure({ mode: "parallel" });
|
|
|
|
|
2022-04-06 15:13:09 +00:00
|
|
|
test.describe("Login and logout tests", () => {
|
2022-05-14 03:02:10 +00:00
|
|
|
test.afterEach(async ({ users }) => {
|
|
|
|
await users.deleteAll();
|
|
|
|
});
|
2022-04-06 15:13:09 +00:00
|
|
|
// Test login with all plans
|
|
|
|
const plans = [UserPlan.PRO, UserPlan.FREE, UserPlan.TRIAL];
|
|
|
|
plans.forEach((plan) => {
|
|
|
|
test(`Should login with a ${plan} account`, async ({ page, users }) => {
|
|
|
|
// Create user and login
|
2022-05-14 03:02:10 +00:00
|
|
|
const user = await users.create({ plan });
|
|
|
|
await user.login();
|
2022-04-06 15:13:09 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
const shellLocator = page.locator(`[data-testid=dashboard-shell]`);
|
2022-04-06 15:13:09 +00:00
|
|
|
|
|
|
|
// expects the home page for an authorized user
|
|
|
|
await page.goto("/");
|
|
|
|
await expect(shellLocator).toBeVisible();
|
|
|
|
|
|
|
|
// Asserts to read the tested plan
|
|
|
|
const planLocator = shellLocator.locator(`[data-testid=plan-${plan.toLowerCase()}]`);
|
|
|
|
await expect(planLocator).toBeVisible();
|
2022-05-14 03:02:10 +00:00
|
|
|
await expect(planLocator).toHaveText(`-${plan}`);
|
2022-04-06 15:13:09 +00:00
|
|
|
|
|
|
|
// When TRIAL check if the TRIAL banner is visible
|
|
|
|
if (plan === UserPlan.TRIAL) {
|
|
|
|
await expect(page.locator(`[data-testid=trial-banner]`)).toBeVisible();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("Should warn when user does not exist", async ({ page }) => {
|
2022-04-06 15:13:09 +00:00
|
|
|
const alertMessage = (await localize("en"))("no_account_exists");
|
|
|
|
|
|
|
|
// Login with a non-existent user
|
|
|
|
const never = "never";
|
|
|
|
await login({ username: never }, page);
|
|
|
|
|
|
|
|
// assert for the visibility of the localized alert message
|
|
|
|
await expect(page.locator(`text=${alertMessage}`)).toBeVisible();
|
|
|
|
});
|
2021-11-02 14:19:40 +00:00
|
|
|
|
2022-04-06 15:13:09 +00:00
|
|
|
test("Should warn when password is incorrect", async ({ page, users }) => {
|
|
|
|
const alertMessage = (await localize("en"))("incorrect_password");
|
|
|
|
// by default password===username with the users fixture
|
|
|
|
const pro = await users.create({ username: "pro" });
|
2021-11-02 14:19:40 +00:00
|
|
|
|
2022-04-06 15:13:09 +00:00
|
|
|
// login with a wrong password
|
2022-05-14 03:02:10 +00:00
|
|
|
await login({ username: pro.username, password: "wrong" }, page);
|
2022-04-06 15:13:09 +00:00
|
|
|
|
|
|
|
// assert for the visibility of the localized alert message
|
|
|
|
await expect(page.locator(`text=${alertMessage}`)).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Should logout", async ({ page, users }) => {
|
|
|
|
const signOutLabel = (await localize("en"))("sign_out");
|
2022-05-14 03:02:10 +00:00
|
|
|
const userDropdownDisclose = async () => page.locator("[data-testid=user-dropdown-trigger]").click();
|
2022-04-06 15:13:09 +00:00
|
|
|
|
|
|
|
// creates a user and login
|
|
|
|
const pro = await users.create();
|
|
|
|
await pro.login();
|
|
|
|
|
|
|
|
// disclose and click the sign out button from the user dropdown
|
|
|
|
await userDropdownDisclose();
|
2022-05-14 03:02:10 +00:00
|
|
|
const signOutBtn = page.locator(`text=${signOutLabel}`);
|
2022-04-06 15:13:09 +00:00
|
|
|
await signOutBtn.click();
|
|
|
|
|
|
|
|
// 2s of delay to assure the session is cleared
|
|
|
|
await page.waitForTimeout(2000);
|
|
|
|
|
|
|
|
// Reroute to the home page to check if the login form shows up
|
2022-03-17 19:36:11 +00:00
|
|
|
await page.goto("/");
|
2022-04-06 15:13:09 +00:00
|
|
|
await expect(page.locator(`[data-testid=login-form]`)).toBeVisible();
|
2022-03-17 19:36:11 +00:00
|
|
|
});
|
2022-03-28 20:06:41 +00:00
|
|
|
|
2022-04-06 15:13:09 +00:00
|
|
|
test("Should logout using the logout route", async ({ page, users }) => {
|
2022-03-28 20:06:41 +00:00
|
|
|
// creates a user and login
|
|
|
|
const pro = await users.create();
|
|
|
|
await pro.login();
|
|
|
|
|
|
|
|
// users.logout() action uses the logout route "/auth/logout" to clear the session
|
|
|
|
await users.logout();
|
|
|
|
|
|
|
|
// check if we are at the login page
|
|
|
|
await page.goto("/");
|
|
|
|
await expect(page.locator(`[data-testid=login-form]`)).toBeVisible();
|
|
|
|
});
|
2021-11-02 14:19:40 +00:00
|
|
|
});
|