2022-03-28 20:06:41 +00:00
|
|
|
import { expect } from "@playwright/test";
|
|
|
|
|
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-09-07 23:29:24 +00:00
|
|
|
// a test to logout requires both a succesfull login as logout, to prevent
|
|
|
|
// a doubling of tests failing on logout & logout, we can group them.
|
|
|
|
test.describe("user can login & logout succesfully", async () => {
|
|
|
|
test.afterAll(async ({ users }) => {
|
2022-05-14 03:02:10 +00:00
|
|
|
await users.deleteAll();
|
|
|
|
});
|
2022-12-08 23:20:24 +00:00
|
|
|
test("login flow user & logout using dashboard", async ({ page, users }) => {
|
2022-09-07 23:29:24 +00:00
|
|
|
// log in trail user
|
|
|
|
await test.step("Log in", async () => {
|
2022-12-08 23:20:24 +00:00
|
|
|
const user = await users.create();
|
2022-05-14 03:02:10 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
//
|
|
|
|
await test.step("Log out", async () => {
|
|
|
|
const signOutLabel = (await localize("en"))("sign_out");
|
|
|
|
const userDropdownDisclose = async () => page.locator("[data-testid=user-dropdown-trigger]").click();
|
2022-04-06 15:13:09 +00:00
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
// disclose and click the sign out button from the user dropdown
|
|
|
|
await userDropdownDisclose();
|
|
|
|
const signOutBtn = await page.locator(`text=${signOutLabel}`);
|
|
|
|
await signOutBtn.click();
|
2022-04-06 15:13:09 +00:00
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
// 2s of delay to assure the session is cleared
|
|
|
|
await page.waitForURL("/auth/logout");
|
|
|
|
|
|
|
|
// Reroute to the home page to check if the login form shows up
|
|
|
|
await page.goto("/");
|
|
|
|
await expect(page.locator(`[data-testid=login-form]`)).toBeVisible();
|
|
|
|
});
|
2022-04-06 15:13:09 +00:00
|
|
|
});
|
2022-09-07 23:29:24 +00:00
|
|
|
});
|
2021-11-02 14:19:40 +00:00
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
test.describe("Login and logout tests", () => {
|
|
|
|
test.afterAll(async ({ users }) => {
|
|
|
|
await users.deleteAll();
|
|
|
|
});
|
2021-11-02 14:19:40 +00:00
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
test.afterEach(async ({ users, page }) => {
|
|
|
|
await users.logout();
|
2022-04-06 15:13:09 +00:00
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
// check if we are at the login page
|
|
|
|
await page.goto("/");
|
|
|
|
await expect(page.locator(`[data-testid=login-form]`)).toBeVisible();
|
2022-04-06 15:13:09 +00:00
|
|
|
});
|
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
test.describe("Login flow validations", async () => {
|
|
|
|
test("Should warn when user does not exist", async ({ page }) => {
|
2023-01-30 18:37:03 +00:00
|
|
|
const alertMessage = (await localize("en"))("incorrect_username_password");
|
2022-03-28 20:06:41 +00:00
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
// Login with a non-existent user
|
|
|
|
const never = "never";
|
|
|
|
await login({ username: never }, page);
|
2022-03-28 20:06:41 +00:00
|
|
|
|
2022-09-07 23:29:24 +00:00
|
|
|
// assert for the visibility of the localized alert message
|
|
|
|
await expect(page.locator(`text=${alertMessage}`)).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Should warn when password is incorrect", async ({ page, users }) => {
|
2023-01-30 18:37:03 +00:00
|
|
|
const alertMessage = (await localize("en"))("incorrect_username_password");
|
2022-09-07 23:29:24 +00:00
|
|
|
// by default password===username with the users fixture
|
|
|
|
const pro = await users.create({ username: "pro" });
|
|
|
|
|
|
|
|
// login with a wrong password
|
|
|
|
await login({ username: pro.username, password: "wrong" }, page);
|
|
|
|
|
|
|
|
// assert for the visibility of the localized alert message
|
|
|
|
await expect(page.locator(`text=${alertMessage}`)).toBeVisible();
|
|
|
|
});
|
2022-03-28 20:06:41 +00:00
|
|
|
});
|
2021-11-02 14:19:40 +00:00
|
|
|
});
|