Vendor backend and frontend into the monorepo
The submodule collapse was only half applied: .gitmodules was deleted but backend/ and frontend/ were still recorded as gitlinks, so none of their files were tracked. Replace the gitlinks with the real trees. Also untrack .env (it carried placeholder secrets) in favour of a tracked .env.example, drop the committed __pycache__, and narrow the blanket *.png ignore that would have swallowed design assets. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
3cb16958ba
commit
1916f7f778
@@ -0,0 +1,205 @@
|
||||
import { expect, test } from "@playwright/test"
|
||||
import { firstSuperuser, firstSuperuserPassword } from "./config.ts"
|
||||
import { createUser } from "./utils/privateApi"
|
||||
import { randomEmail, randomPassword } from "./utils/random"
|
||||
import { logInUser } from "./utils/user"
|
||||
|
||||
test("Admin page is accessible and shows correct title", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
await expect(page.getByRole("heading", { name: "Users" })).toBeVisible()
|
||||
await expect(
|
||||
page.getByText("Manage user accounts and permissions"),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("Add User button is visible", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
await expect(page.getByRole("button", { name: "Add User" })).toBeVisible()
|
||||
})
|
||||
|
||||
test.describe("Admin user management", () => {
|
||||
test("Create a new user successfully", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const fullName = "Test User Admin"
|
||||
|
||||
await page.getByRole("button", { name: "Add User" }).click()
|
||||
|
||||
await page.getByPlaceholder("Email").fill(email)
|
||||
await page.getByPlaceholder("Full name").fill(fullName)
|
||||
await page.getByPlaceholder("Password").first().fill(password)
|
||||
await page.getByPlaceholder("Password").last().fill(password)
|
||||
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("User created successfully")).toBeVisible()
|
||||
|
||||
await expect(page.getByRole("dialog")).not.toBeVisible()
|
||||
|
||||
const userRow = page.getByRole("row").filter({ hasText: email })
|
||||
await expect(userRow).toBeVisible()
|
||||
})
|
||||
|
||||
test("Create a superuser", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
|
||||
await page.getByRole("button", { name: "Add User" }).click()
|
||||
|
||||
await page.getByPlaceholder("Email").fill(email)
|
||||
await page.getByPlaceholder("Password").first().fill(password)
|
||||
await page.getByPlaceholder("Password").last().fill(password)
|
||||
await page.getByLabel("Is superuser?").check()
|
||||
await page.getByLabel("Is active?").check()
|
||||
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("User created successfully")).toBeVisible()
|
||||
|
||||
await expect(page.getByRole("dialog")).not.toBeVisible()
|
||||
|
||||
const userRow = page.getByRole("row").filter({ hasText: email })
|
||||
await expect(userRow.getByText("Superuser")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Edit a user successfully", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const originalName = "Original Name"
|
||||
const updatedName = "Updated Name"
|
||||
|
||||
await page.getByRole("button", { name: "Add User" }).click()
|
||||
await page.getByPlaceholder("Email").fill(email)
|
||||
await page.getByPlaceholder("Full name").fill(originalName)
|
||||
await page.getByPlaceholder("Password").first().fill(password)
|
||||
await page.getByPlaceholder("Password").last().fill(password)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("User created successfully")).toBeVisible()
|
||||
await expect(page.getByRole("dialog")).not.toBeVisible()
|
||||
|
||||
const userRow = page.getByRole("row").filter({ hasText: email })
|
||||
await userRow.getByRole("button").click()
|
||||
|
||||
await page.getByRole("menuitem", { name: "Edit User" }).click()
|
||||
|
||||
await page.getByPlaceholder("Full name").fill(updatedName)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("User updated successfully")).toBeVisible()
|
||||
await expect(page.getByText(updatedName)).toBeVisible()
|
||||
})
|
||||
|
||||
test("Delete a user successfully", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
|
||||
await page.getByRole("button", { name: "Add User" }).click()
|
||||
await page.getByPlaceholder("Email").fill(email)
|
||||
await page.getByPlaceholder("Password").first().fill(password)
|
||||
await page.getByPlaceholder("Password").last().fill(password)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("User created successfully")).toBeVisible()
|
||||
|
||||
await expect(page.getByRole("dialog")).not.toBeVisible()
|
||||
|
||||
const userRow = page.getByRole("row").filter({ hasText: email })
|
||||
await userRow.getByRole("button").click()
|
||||
|
||||
await page.getByRole("menuitem", { name: "Delete User" }).click()
|
||||
|
||||
await page.getByRole("button", { name: "Delete" }).click()
|
||||
|
||||
await expect(
|
||||
page.getByText("The user was deleted successfully"),
|
||||
).toBeVisible()
|
||||
|
||||
await expect(
|
||||
page.getByRole("row").filter({ hasText: email }),
|
||||
).not.toBeVisible()
|
||||
})
|
||||
|
||||
test("Cancel user creation", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
|
||||
await page.getByRole("button", { name: "Add User" }).click()
|
||||
await page.getByPlaceholder("Email").fill("test@example.com")
|
||||
|
||||
await page.getByRole("button", { name: "Cancel" }).click()
|
||||
|
||||
await expect(page.getByRole("dialog")).not.toBeVisible()
|
||||
})
|
||||
|
||||
test("Email is required and must be valid", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
|
||||
await page.getByRole("button", { name: "Add User" }).click()
|
||||
|
||||
await page.getByPlaceholder("Email").fill("invalid-email")
|
||||
await page.getByPlaceholder("Email").blur()
|
||||
|
||||
await expect(page.getByText("Invalid email address")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Password must be at least 8 characters", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
|
||||
await page.getByRole("button", { name: "Add User" }).click()
|
||||
|
||||
await page.getByPlaceholder("Email").fill(randomEmail())
|
||||
await page.getByPlaceholder("Password").first().fill("short")
|
||||
await page.getByPlaceholder("Password").last().fill("short")
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(
|
||||
page.getByText("Password must be at least 8 characters"),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("Passwords must match", async ({ page }) => {
|
||||
await page.goto("/admin")
|
||||
|
||||
await page.getByRole("button", { name: "Add User" }).click()
|
||||
|
||||
await page.getByPlaceholder("Email").fill(randomEmail())
|
||||
await page.getByPlaceholder("Password").first().fill(randomPassword())
|
||||
await page.getByPlaceholder("Password").last().fill("different12345")
|
||||
await page.getByPlaceholder("Password").last().blur()
|
||||
|
||||
await expect(page.getByText("The passwords don't match")).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe("Admin page access control", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test("Non-superuser cannot access admin page", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
|
||||
await createUser({ email, password })
|
||||
await logInUser(page, email, password)
|
||||
|
||||
await page.goto("/admin")
|
||||
|
||||
await expect(page.getByRole("heading", { name: "Users" })).not.toBeVisible()
|
||||
await expect(page).not.toHaveURL(/\/admin/)
|
||||
})
|
||||
|
||||
test("Superuser can access admin page", async ({ page }) => {
|
||||
await logInUser(page, firstSuperuser, firstSuperuserPassword)
|
||||
|
||||
await page.goto("/admin")
|
||||
|
||||
await expect(page.getByRole("heading", { name: "Users" })).toBeVisible()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
import { test as setup } from "@playwright/test"
|
||||
import { firstSuperuser, firstSuperuserPassword } from "./config.ts"
|
||||
|
||||
const authFile = "playwright/.auth/user.json"
|
||||
|
||||
setup("authenticate", async ({ page }) => {
|
||||
await page.goto("/login")
|
||||
await page.getByTestId("email-input").fill(firstSuperuser)
|
||||
await page.getByTestId("password-input").fill(firstSuperuserPassword)
|
||||
await page.getByRole("button", { name: "Log In" }).click()
|
||||
await page.waitForURL("/")
|
||||
await page.context().storageState({ path: authFile })
|
||||
})
|
||||
@@ -0,0 +1,19 @@
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import dotenv from "dotenv"
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
dotenv.config({ path: path.join(__dirname, "../../.env") })
|
||||
|
||||
function getEnvVar(name: string): string {
|
||||
const value = process.env[name]
|
||||
if (!value) {
|
||||
throw new Error(`Environment variable ${name} is undefined`)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
export const firstSuperuser = getEnvVar("FIRST_SUPERUSER")
|
||||
export const firstSuperuserPassword = getEnvVar("FIRST_SUPERUSER_PASSWORD")
|
||||
@@ -0,0 +1,132 @@
|
||||
import { expect, test } from "@playwright/test"
|
||||
import { createUser } from "./utils/privateApi"
|
||||
import {
|
||||
randomEmail,
|
||||
randomItemDescription,
|
||||
randomItemTitle,
|
||||
randomPassword,
|
||||
} from "./utils/random"
|
||||
import { logInUser } from "./utils/user"
|
||||
|
||||
test("Items page is accessible and shows correct title", async ({ page }) => {
|
||||
await page.goto("/items")
|
||||
await expect(page.getByRole("heading", { name: "Items" })).toBeVisible()
|
||||
await expect(page.getByText("Create and manage your items")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Add Item button is visible", async ({ page }) => {
|
||||
await page.goto("/items")
|
||||
await expect(page.getByRole("button", { name: "Add Item" })).toBeVisible()
|
||||
})
|
||||
|
||||
test.describe("Items management", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
let email: string
|
||||
const password = randomPassword()
|
||||
|
||||
test.beforeAll(async () => {
|
||||
email = randomEmail()
|
||||
await createUser({ email, password })
|
||||
})
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await logInUser(page, email, password)
|
||||
await page.goto("/items")
|
||||
})
|
||||
|
||||
test("Create a new item successfully", async ({ page }) => {
|
||||
const title = randomItemTitle()
|
||||
const description = randomItemDescription()
|
||||
|
||||
await page.getByRole("button", { name: "Add Item" }).click()
|
||||
await page.getByLabel("Title").fill(title)
|
||||
await page.getByLabel("Description").fill(description)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("Item created successfully")).toBeVisible()
|
||||
await expect(page.getByText(title)).toBeVisible()
|
||||
})
|
||||
|
||||
test("Create item with only required fields", async ({ page }) => {
|
||||
const title = randomItemTitle()
|
||||
|
||||
await page.getByRole("button", { name: "Add Item" }).click()
|
||||
await page.getByLabel("Title").fill(title)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("Item created successfully")).toBeVisible()
|
||||
await expect(page.getByText(title)).toBeVisible()
|
||||
})
|
||||
|
||||
test("Cancel item creation", async ({ page }) => {
|
||||
await page.getByRole("button", { name: "Add Item" }).click()
|
||||
await page.getByLabel("Title").fill("Test Item")
|
||||
await page.getByRole("button", { name: "Cancel" }).click()
|
||||
|
||||
await expect(page.getByRole("dialog")).not.toBeVisible()
|
||||
})
|
||||
|
||||
test("Title is required", async ({ page }) => {
|
||||
await page.getByRole("button", { name: "Add Item" }).click()
|
||||
await page.getByLabel("Title").fill("")
|
||||
await page.getByLabel("Title").blur()
|
||||
|
||||
await expect(page.getByText("Title is required")).toBeVisible()
|
||||
})
|
||||
|
||||
test.describe("Edit and Delete", () => {
|
||||
let itemTitle: string
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
itemTitle = randomItemTitle()
|
||||
|
||||
await page.getByRole("button", { name: "Add Item" }).click()
|
||||
await page.getByLabel("Title").fill(itemTitle)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
await expect(page.getByText("Item created successfully")).toBeVisible()
|
||||
await expect(page.getByRole("dialog")).not.toBeVisible()
|
||||
})
|
||||
|
||||
test("Edit an item successfully", async ({ page }) => {
|
||||
const itemRow = page.getByRole("row").filter({ hasText: itemTitle })
|
||||
await itemRow.getByRole("button").last().click()
|
||||
await page.getByRole("menuitem", { name: "Edit Item" }).click()
|
||||
|
||||
const updatedTitle = randomItemTitle()
|
||||
await page.getByLabel("Title").fill(updatedTitle)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("Item updated successfully")).toBeVisible()
|
||||
await expect(page.getByText(updatedTitle)).toBeVisible()
|
||||
})
|
||||
|
||||
test("Delete an item successfully", async ({ page }) => {
|
||||
const itemRow = page.getByRole("row").filter({ hasText: itemTitle })
|
||||
await itemRow.getByRole("button").last().click()
|
||||
await page.getByRole("menuitem", { name: "Delete Item" }).click()
|
||||
|
||||
await page.getByRole("button", { name: "Delete" }).click()
|
||||
|
||||
await expect(
|
||||
page.getByText("The item was deleted successfully"),
|
||||
).toBeVisible()
|
||||
await expect(page.getByText(itemTitle)).not.toBeVisible()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test.describe("Items empty state", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test("Shows empty state message when no items exist", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
await createUser({ email, password })
|
||||
await logInUser(page, email, password)
|
||||
|
||||
await page.goto("/items")
|
||||
|
||||
await expect(page.getByText("You don't have any items yet")).toBeVisible()
|
||||
await expect(page.getByText("Add a new item to get started")).toBeVisible()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,117 @@
|
||||
import { expect, type Page, test } from "@playwright/test"
|
||||
import { firstSuperuser, firstSuperuserPassword } from "./config.ts"
|
||||
import { randomPassword } from "./utils/random.ts"
|
||||
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
const fillForm = async (page: Page, email: string, password: string) => {
|
||||
await page.getByTestId("email-input").fill(email)
|
||||
await page.getByTestId("password-input").fill(password)
|
||||
}
|
||||
|
||||
const verifyInput = async (page: Page, testId: string) => {
|
||||
const input = page.getByTestId(testId)
|
||||
await expect(input).toBeVisible()
|
||||
await expect(input).toHaveText("")
|
||||
await expect(input).toBeEditable()
|
||||
}
|
||||
|
||||
test("Inputs are visible, empty and editable", async ({ page }) => {
|
||||
await page.goto("/login")
|
||||
|
||||
await verifyInput(page, "email-input")
|
||||
await verifyInput(page, "password-input")
|
||||
})
|
||||
|
||||
test("Log In button is visible", async ({ page }) => {
|
||||
await page.goto("/login")
|
||||
|
||||
await expect(page.getByRole("button", { name: "Log In" })).toBeVisible()
|
||||
})
|
||||
|
||||
test("Forgot Password link is visible", async ({ page }) => {
|
||||
await page.goto("/login")
|
||||
|
||||
await expect(
|
||||
page.getByRole("link", { name: "Forgot your password?" }),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("Log in with valid email and password ", async ({ page }) => {
|
||||
await page.goto("/login")
|
||||
|
||||
await fillForm(page, firstSuperuser, firstSuperuserPassword)
|
||||
await page.getByRole("button", { name: "Log In" }).click()
|
||||
|
||||
await page.waitForURL("/")
|
||||
|
||||
await expect(
|
||||
page.getByText("Welcome back, nice to see you again!"),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("Log in with invalid email", async ({ page }) => {
|
||||
await page.goto("/login")
|
||||
|
||||
await fillForm(page, "invalidemail", firstSuperuserPassword)
|
||||
await page.getByRole("button", { name: "Log In" }).click()
|
||||
|
||||
await expect(page.getByText("Invalid email address")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Log in with invalid password", async ({ page }) => {
|
||||
const password = randomPassword()
|
||||
|
||||
await page.goto("/login")
|
||||
await fillForm(page, firstSuperuser, password)
|
||||
await page.getByRole("button", { name: "Log In" }).click()
|
||||
|
||||
await expect(page.getByText("Incorrect email or password")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Successful log out", async ({ page }) => {
|
||||
await page.goto("/login")
|
||||
|
||||
await fillForm(page, firstSuperuser, firstSuperuserPassword)
|
||||
await page.getByRole("button", { name: "Log In" }).click()
|
||||
|
||||
await page.waitForURL("/")
|
||||
|
||||
await expect(
|
||||
page.getByText("Welcome back, nice to see you again!"),
|
||||
).toBeVisible()
|
||||
|
||||
await page.getByTestId("user-menu").click()
|
||||
await page.getByRole("menuitem", { name: "Log out" }).click()
|
||||
await page.waitForURL("/login")
|
||||
})
|
||||
|
||||
test("Logged-out user cannot access protected routes", async ({ page }) => {
|
||||
await page.goto("/login")
|
||||
|
||||
await fillForm(page, firstSuperuser, firstSuperuserPassword)
|
||||
await page.getByRole("button", { name: "Log In" }).click()
|
||||
|
||||
await page.waitForURL("/")
|
||||
|
||||
await expect(
|
||||
page.getByText("Welcome back, nice to see you again!"),
|
||||
).toBeVisible()
|
||||
|
||||
await page.getByTestId("user-menu").click()
|
||||
await page.getByRole("menuitem", { name: "Log out" }).click()
|
||||
await page.waitForURL("/login")
|
||||
|
||||
await page.goto("/settings")
|
||||
await page.waitForURL("/login")
|
||||
})
|
||||
|
||||
test("Redirects to /login when token is wrong", async ({ page }) => {
|
||||
await page.goto("/settings")
|
||||
await page.evaluate(() => {
|
||||
localStorage.setItem("access_token", "invalid_token")
|
||||
})
|
||||
await page.goto("/settings")
|
||||
await page.waitForURL("/login")
|
||||
await expect(page).toHaveURL("/login")
|
||||
})
|
||||
@@ -0,0 +1,125 @@
|
||||
import { expect, test } from "@playwright/test"
|
||||
import { findLastEmail } from "./utils/mailcatcher"
|
||||
import { randomEmail, randomPassword } from "./utils/random"
|
||||
import { logInUser, signUpNewUser } from "./utils/user"
|
||||
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test("Password Recovery title is visible", async ({ page }) => {
|
||||
await page.goto("/recover-password")
|
||||
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Password Recovery" }),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("Input is visible, empty and editable", async ({ page }) => {
|
||||
await page.goto("/recover-password")
|
||||
|
||||
await expect(page.getByTestId("email-input")).toBeVisible()
|
||||
await expect(page.getByTestId("email-input")).toHaveText("")
|
||||
await expect(page.getByTestId("email-input")).toBeEditable()
|
||||
})
|
||||
|
||||
test("Continue button is visible", async ({ page }) => {
|
||||
await page.goto("/recover-password")
|
||||
|
||||
await expect(page.getByRole("button", { name: "Continue" })).toBeVisible()
|
||||
})
|
||||
|
||||
test("User can reset password successfully using the link", async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
const fullName = "Test User"
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const newPassword = randomPassword()
|
||||
|
||||
// Sign up a new user
|
||||
await signUpNewUser(page, fullName, email, password)
|
||||
|
||||
await page.goto("/recover-password")
|
||||
await page.getByTestId("email-input").fill(email)
|
||||
|
||||
await page.getByRole("button", { name: "Continue" }).click()
|
||||
|
||||
const emailData = await findLastEmail({
|
||||
request,
|
||||
filter: (e) => e.recipients.includes(`<${email}>`),
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
await page.goto(
|
||||
`${process.env.MAILCATCHER_HOST}/messages/${emailData.id}.html`,
|
||||
)
|
||||
|
||||
const selector = 'a[href*="/reset-password?token="]'
|
||||
|
||||
let url = await page.getAttribute(selector, "href")
|
||||
|
||||
// TODO: update var instead of doing a replace
|
||||
url = url!.replace("http://localhost/", "http://localhost:5173/")
|
||||
|
||||
// Set the new password and confirm it
|
||||
await page.goto(url)
|
||||
|
||||
await page.getByTestId("new-password-input").fill(newPassword)
|
||||
await page.getByTestId("confirm-password-input").fill(newPassword)
|
||||
await page.getByRole("button", { name: "Reset Password" }).click()
|
||||
await expect(page.getByText("Password updated successfully")).toBeVisible()
|
||||
|
||||
// Check if the user is able to login with the new password
|
||||
await logInUser(page, email, newPassword)
|
||||
})
|
||||
|
||||
test("Expired or invalid reset link", async ({ page }) => {
|
||||
const password = randomPassword()
|
||||
const invalidUrl = "/reset-password?token=invalidtoken"
|
||||
|
||||
await page.goto(invalidUrl)
|
||||
|
||||
await page.getByTestId("new-password-input").fill(password)
|
||||
await page.getByTestId("confirm-password-input").fill(password)
|
||||
await page.getByRole("button", { name: "Reset Password" }).click()
|
||||
|
||||
await expect(page.getByText("Invalid token")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Weak new password validation", async ({ page, request }) => {
|
||||
const fullName = "Test User"
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const weakPassword = "123"
|
||||
|
||||
// Sign up a new user
|
||||
await signUpNewUser(page, fullName, email, password)
|
||||
|
||||
await page.goto("/recover-password")
|
||||
await page.getByTestId("email-input").fill(email)
|
||||
await page.getByRole("button", { name: "Continue" }).click()
|
||||
|
||||
const emailData = await findLastEmail({
|
||||
request,
|
||||
filter: (e) => e.recipients.includes(`<${email}>`),
|
||||
timeout: 5000,
|
||||
})
|
||||
|
||||
await page.goto(
|
||||
`${process.env.MAILCATCHER_HOST}/messages/${emailData.id}.html`,
|
||||
)
|
||||
|
||||
const selector = 'a[href*="/reset-password?token="]'
|
||||
let url = await page.getAttribute(selector, "href")
|
||||
url = url!.replace("http://localhost/", "http://localhost:5173/")
|
||||
|
||||
// Set a weak new password
|
||||
await page.goto(url)
|
||||
await page.getByTestId("new-password-input").fill(weakPassword)
|
||||
await page.getByTestId("confirm-password-input").fill(weakPassword)
|
||||
await page.getByRole("button", { name: "Reset Password" }).click()
|
||||
|
||||
await expect(
|
||||
page.getByText("Password must be at least 8 characters"),
|
||||
).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,159 @@
|
||||
import { expect, type Page, test } from "@playwright/test"
|
||||
|
||||
import { randomEmail, randomPassword } from "./utils/random"
|
||||
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
const fillForm = async (
|
||||
page: Page,
|
||||
full_name: string,
|
||||
email: string,
|
||||
password: string,
|
||||
confirm_password: string,
|
||||
) => {
|
||||
await page.getByTestId("full-name-input").fill(full_name)
|
||||
await page.getByTestId("email-input").fill(email)
|
||||
await page.getByTestId("password-input").fill(password)
|
||||
await page.getByTestId("confirm-password-input").fill(confirm_password)
|
||||
}
|
||||
|
||||
const verifyInput = async (page: Page, testId: string) => {
|
||||
const input = page.getByTestId(testId)
|
||||
await expect(input).toBeVisible()
|
||||
await expect(input).toHaveText("")
|
||||
await expect(input).toBeEditable()
|
||||
}
|
||||
|
||||
test("Inputs are visible, empty and editable", async ({ page }) => {
|
||||
await page.goto("/signup")
|
||||
|
||||
await verifyInput(page, "full-name-input")
|
||||
await verifyInput(page, "email-input")
|
||||
await verifyInput(page, "password-input")
|
||||
await verifyInput(page, "confirm-password-input")
|
||||
})
|
||||
|
||||
test("Sign Up button is visible", async ({ page }) => {
|
||||
await page.goto("/signup")
|
||||
|
||||
await expect(page.getByRole("button", { name: "Sign Up" })).toBeVisible()
|
||||
})
|
||||
|
||||
test("Log In link is visible", async ({ page }) => {
|
||||
await page.goto("/signup")
|
||||
|
||||
await expect(page.getByRole("link", { name: "Log In" })).toBeVisible()
|
||||
})
|
||||
|
||||
test("Sign up with valid name, email, and password", async ({ page }) => {
|
||||
const full_name = "Test User"
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
|
||||
await page.goto("/signup")
|
||||
await fillForm(page, full_name, email, password, password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
})
|
||||
|
||||
test("Sign up with invalid email", async ({ page }) => {
|
||||
await page.goto("/signup")
|
||||
|
||||
await fillForm(
|
||||
page,
|
||||
"Playwright Test",
|
||||
"invalid-email",
|
||||
"changethis",
|
||||
"changethis",
|
||||
)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
|
||||
await expect(page.getByText("Invalid email address")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Sign up with existing email", async ({ page }) => {
|
||||
const fullName = "Test User"
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
|
||||
await page.goto("/signup")
|
||||
|
||||
await fillForm(page, fullName, email, password, password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
|
||||
await page.goto("/signup")
|
||||
|
||||
await fillForm(page, fullName, email, password, password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
|
||||
await page
|
||||
.getByText("The user with this email already exists in the system")
|
||||
.click()
|
||||
})
|
||||
|
||||
test("Sign up with weak password", async ({ page }) => {
|
||||
const fullName = "Test User"
|
||||
const email = randomEmail()
|
||||
const password = "weak"
|
||||
|
||||
await page.goto("/signup")
|
||||
|
||||
await fillForm(page, fullName, email, password, password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
|
||||
await expect(
|
||||
page.getByText("Password must be at least 8 characters"),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("Sign up with mismatched passwords", async ({ page }) => {
|
||||
const fullName = "Test User"
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const password2 = randomPassword()
|
||||
|
||||
await page.goto("/signup")
|
||||
|
||||
await fillForm(page, fullName, email, password, password2)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
|
||||
await expect(page.getByText("The passwords don't match")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Sign up with missing full name", async ({ page }) => {
|
||||
const fullName = ""
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
|
||||
await page.goto("/signup")
|
||||
|
||||
await fillForm(page, fullName, email, password, password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
|
||||
await expect(page.getByText("Full Name is required")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Sign up with missing email", async ({ page }) => {
|
||||
const fullName = "Test User"
|
||||
const email = ""
|
||||
const password = randomPassword()
|
||||
|
||||
await page.goto("/signup")
|
||||
|
||||
await fillForm(page, fullName, email, password, password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
|
||||
await expect(page.getByText("Invalid email address")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Sign up with missing password", async ({ page }) => {
|
||||
const fullName = ""
|
||||
const email = randomEmail()
|
||||
const password = ""
|
||||
|
||||
await page.goto("/signup")
|
||||
|
||||
await fillForm(page, fullName, email, password, password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
|
||||
await expect(page.getByText("Password is required")).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,256 @@
|
||||
import { expect, test } from "@playwright/test"
|
||||
import { firstSuperuser, firstSuperuserPassword } from "./config.ts"
|
||||
import { createUser } from "./utils/privateApi.ts"
|
||||
import { randomEmail, randomPassword } from "./utils/random"
|
||||
import { logInUser, logOutUser } from "./utils/user"
|
||||
|
||||
const tabs = ["My profile", "Password", "Danger zone"]
|
||||
|
||||
test("My profile tab is active by default", async ({ page }) => {
|
||||
await page.goto("/settings")
|
||||
await expect(page.getByRole("tab", { name: "My profile" })).toHaveAttribute(
|
||||
"aria-selected",
|
||||
"true",
|
||||
)
|
||||
})
|
||||
|
||||
test("All tabs are visible", async ({ page }) => {
|
||||
await page.goto("/settings")
|
||||
for (const tab of tabs) {
|
||||
await expect(page.getByRole("tab", { name: tab })).toBeVisible()
|
||||
}
|
||||
})
|
||||
|
||||
test.describe("Edit user profile", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
let email: string
|
||||
let password: string
|
||||
|
||||
test.beforeAll(async () => {
|
||||
email = randomEmail()
|
||||
password = randomPassword()
|
||||
await createUser({ email, password })
|
||||
})
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await logInUser(page, email, password)
|
||||
await page.goto("/settings")
|
||||
await page.getByRole("tab", { name: "My profile" }).click()
|
||||
})
|
||||
|
||||
test("Edit user name with a valid name", async ({ page }) => {
|
||||
const updatedName = "Test User 2"
|
||||
|
||||
await page.getByRole("button", { name: "Edit" }).click()
|
||||
await page.getByLabel("Full name").fill(updatedName)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("User updated successfully")).toBeVisible()
|
||||
await expect(
|
||||
page.locator("form").getByText(updatedName, { exact: true }),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("Edit user email with an invalid email shows error", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.getByRole("button", { name: "Edit" }).click()
|
||||
await page.getByLabel("Email").fill("")
|
||||
await page.locator("body").click()
|
||||
|
||||
await expect(page.getByText("Invalid email address")).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe("Edit user email", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test("Edit user email with a valid email", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const updatedEmail = randomEmail()
|
||||
|
||||
await createUser({ email, password })
|
||||
await logInUser(page, email, password)
|
||||
await page.goto("/settings")
|
||||
await page.getByRole("tab", { name: "My profile" }).click()
|
||||
|
||||
await page.getByRole("button", { name: "Edit" }).click()
|
||||
await page.getByLabel("Email").fill(updatedEmail)
|
||||
await page.getByRole("button", { name: "Save" }).click()
|
||||
|
||||
await expect(page.getByText("User updated successfully")).toBeVisible()
|
||||
await expect(
|
||||
page.locator("form").getByText(updatedEmail, { exact: true }),
|
||||
).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe("Cancel edit actions", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test("Cancel edit action restores original name", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const user = await createUser({ email, password })
|
||||
|
||||
await logInUser(page, email, password)
|
||||
await page.goto("/settings")
|
||||
await page.getByRole("tab", { name: "My profile" }).click()
|
||||
await page.getByRole("button", { name: "Edit" }).click()
|
||||
await page.getByLabel("Full name").fill("Test User")
|
||||
await page.getByRole("button", { name: "Cancel" }).first().click()
|
||||
|
||||
await expect(
|
||||
page.locator("form").getByText(user.full_name as string, { exact: true }),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("Cancel edit action restores original email", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
await createUser({ email, password })
|
||||
|
||||
await logInUser(page, email, password)
|
||||
await page.goto("/settings")
|
||||
await page.getByRole("tab", { name: "My profile" }).click()
|
||||
await page.getByRole("button", { name: "Edit" }).click()
|
||||
await page.getByLabel("Email").fill(randomEmail())
|
||||
await page.getByRole("button", { name: "Cancel" }).first().click()
|
||||
|
||||
await expect(
|
||||
page.locator("form").getByText(email, { exact: true }),
|
||||
).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
test.describe("Change password", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test("Update password successfully", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const newPassword = randomPassword()
|
||||
|
||||
await createUser({ email, password })
|
||||
await logInUser(page, email, password)
|
||||
|
||||
await page.goto("/settings")
|
||||
await page.getByRole("tab", { name: "Password" }).click()
|
||||
await page.getByTestId("current-password-input").fill(password)
|
||||
await page.getByTestId("new-password-input").fill(newPassword)
|
||||
await page.getByTestId("confirm-password-input").fill(newPassword)
|
||||
await page.getByRole("button", { name: "Update Password" }).click()
|
||||
|
||||
await expect(page.getByText("Password updated successfully")).toBeVisible()
|
||||
|
||||
await logOutUser(page)
|
||||
await logInUser(page, email, newPassword)
|
||||
})
|
||||
})
|
||||
|
||||
test.describe("Change password validation", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
let email: string
|
||||
let password: string
|
||||
|
||||
test.beforeAll(async () => {
|
||||
email = randomEmail()
|
||||
password = randomPassword()
|
||||
await createUser({ email, password })
|
||||
})
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await logInUser(page, email, password)
|
||||
await page.goto("/settings")
|
||||
await page.getByRole("tab", { name: "Password" }).click()
|
||||
})
|
||||
|
||||
test("Update password with weak passwords", async ({ page }) => {
|
||||
const weakPassword = "weak"
|
||||
|
||||
await page.getByTestId("current-password-input").fill(password)
|
||||
await page.getByTestId("new-password-input").fill(weakPassword)
|
||||
await page.getByTestId("confirm-password-input").fill(weakPassword)
|
||||
await page.getByRole("button", { name: "Update Password" }).click()
|
||||
|
||||
await expect(
|
||||
page.getByText("Password must be at least 8 characters"),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test("New password and confirmation password do not match", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.getByTestId("current-password-input").fill(password)
|
||||
await page.getByTestId("new-password-input").fill(randomPassword())
|
||||
await page.getByTestId("confirm-password-input").fill(randomPassword())
|
||||
await page.getByRole("button", { name: "Update Password" }).click()
|
||||
|
||||
await expect(page.getByText("The passwords don't match")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Current password and new password are the same", async ({ page }) => {
|
||||
await page.getByTestId("current-password-input").fill(password)
|
||||
await page.getByTestId("new-password-input").fill(password)
|
||||
await page.getByTestId("confirm-password-input").fill(password)
|
||||
await page.getByRole("button", { name: "Update Password" }).click()
|
||||
|
||||
await expect(
|
||||
page.getByText("New password cannot be the same as the current one"),
|
||||
).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
test("Appearance button is visible in sidebar", async ({ page }) => {
|
||||
await page.goto("/settings")
|
||||
await expect(page.getByTestId("theme-button")).toBeVisible()
|
||||
})
|
||||
|
||||
test("User can switch between theme modes", async ({ page }) => {
|
||||
await page.goto("/settings")
|
||||
|
||||
await page.getByTestId("theme-button").click()
|
||||
await page.getByTestId("dark-mode").click()
|
||||
await expect(page.locator("html")).toHaveClass(/dark/)
|
||||
|
||||
await expect(page.getByTestId("dark-mode")).not.toBeVisible()
|
||||
|
||||
await page.getByTestId("theme-button").click()
|
||||
await page.getByTestId("light-mode").click()
|
||||
await expect(page.locator("html")).toHaveClass(/light/)
|
||||
})
|
||||
|
||||
test("Selected mode is preserved across sessions", async ({ page }) => {
|
||||
await page.goto("/settings")
|
||||
|
||||
await page.getByTestId("theme-button").click()
|
||||
if (
|
||||
await page.evaluate(() =>
|
||||
document.documentElement.classList.contains("dark"),
|
||||
)
|
||||
) {
|
||||
await page.getByTestId("light-mode").click()
|
||||
await page.getByTestId("theme-button").click()
|
||||
}
|
||||
|
||||
const isLightMode = await page.evaluate(() =>
|
||||
document.documentElement.classList.contains("light"),
|
||||
)
|
||||
expect(isLightMode).toBe(true)
|
||||
|
||||
await page.getByTestId("theme-button").click()
|
||||
await page.getByTestId("dark-mode").click()
|
||||
let isDarkMode = await page.evaluate(() =>
|
||||
document.documentElement.classList.contains("dark"),
|
||||
)
|
||||
expect(isDarkMode).toBe(true)
|
||||
|
||||
await logOutUser(page)
|
||||
await logInUser(page, firstSuperuser, firstSuperuserPassword)
|
||||
|
||||
isDarkMode = await page.evaluate(() =>
|
||||
document.documentElement.classList.contains("dark"),
|
||||
)
|
||||
expect(isDarkMode).toBe(true)
|
||||
})
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { APIRequestContext } from "@playwright/test"
|
||||
|
||||
type Email = {
|
||||
id: number
|
||||
recipients: string[]
|
||||
subject: string
|
||||
}
|
||||
|
||||
async function findEmail({
|
||||
request,
|
||||
filter,
|
||||
}: {
|
||||
request: APIRequestContext
|
||||
filter?: (email: Email) => boolean
|
||||
}) {
|
||||
const response = await request.get(`${process.env.MAILCATCHER_HOST}/messages`)
|
||||
|
||||
let emails = await response.json()
|
||||
|
||||
if (filter) {
|
||||
emails = emails.filter(filter)
|
||||
}
|
||||
|
||||
const email = emails[emails.length - 1]
|
||||
|
||||
if (email) {
|
||||
return email as Email
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function findLastEmail({
|
||||
request,
|
||||
filter,
|
||||
timeout = 5000,
|
||||
}: {
|
||||
request: APIRequestContext
|
||||
filter?: (email: Email) => boolean
|
||||
timeout?: number
|
||||
}) {
|
||||
const timeoutPromise = new Promise<never>((_, reject) =>
|
||||
setTimeout(
|
||||
() => reject(new Error("Timeout while trying to get latest email")),
|
||||
timeout,
|
||||
),
|
||||
)
|
||||
|
||||
const checkEmails = async () => {
|
||||
while (true) {
|
||||
const emailData = await findEmail({ request, filter })
|
||||
|
||||
if (emailData) {
|
||||
return emailData
|
||||
}
|
||||
// Wait for 100ms before checking again
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.race([timeoutPromise, checkEmails()])
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Note: the `PrivateService` is only available when generating the client
|
||||
// for local environments
|
||||
import { OpenAPI, PrivateService } from "../../src/client"
|
||||
|
||||
OpenAPI.BASE = `${process.env.VITE_API_URL}`
|
||||
|
||||
export const createUser = async ({
|
||||
email,
|
||||
password,
|
||||
}: {
|
||||
email: string
|
||||
password: string
|
||||
}) => {
|
||||
return await PrivateService.createUser({
|
||||
requestBody: {
|
||||
email,
|
||||
password,
|
||||
is_verified: true,
|
||||
full_name: "Test User",
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
export const randomEmail = () =>
|
||||
`test_${Math.random().toString(36).substring(7)}@example.com`
|
||||
|
||||
export const randomTeamName = () =>
|
||||
`Team ${Math.random().toString(36).substring(7)}`
|
||||
|
||||
export const randomPassword = () => `${Math.random().toString(36).substring(2)}`
|
||||
|
||||
export const slugify = (text: string) =>
|
||||
text
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/[^\w-]+/g, "")
|
||||
|
||||
export const randomItemTitle = () =>
|
||||
`Item ${Math.random().toString(36).substring(7)}`
|
||||
|
||||
export const randomItemDescription = () =>
|
||||
`Description ${Math.random().toString(36).substring(7)}`
|
||||
@@ -0,0 +1,35 @@
|
||||
import { expect, type Page } from "@playwright/test"
|
||||
|
||||
export async function signUpNewUser(
|
||||
page: Page,
|
||||
name: string,
|
||||
email: string,
|
||||
password: string,
|
||||
) {
|
||||
await page.goto("/signup")
|
||||
|
||||
await page.getByTestId("full-name-input").fill(name)
|
||||
await page.getByTestId("email-input").fill(email)
|
||||
await page.getByTestId("password-input").fill(password)
|
||||
await page.getByTestId("confirm-password-input").fill(password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
await page.goto("/login")
|
||||
}
|
||||
|
||||
export async function logInUser(page: Page, email: string, password: string) {
|
||||
await page.goto("/login")
|
||||
|
||||
await page.getByTestId("email-input").fill(email)
|
||||
await page.getByTestId("password-input").fill(password)
|
||||
await page.getByRole("button", { name: "Log In" }).click()
|
||||
await page.waitForURL("/")
|
||||
await expect(
|
||||
page.getByText("Welcome back, nice to see you again!"),
|
||||
).toBeVisible()
|
||||
}
|
||||
|
||||
export async function logOutUser(page: Page) {
|
||||
await page.getByTestId("user-menu").click()
|
||||
await page.getByRole("menuitem", { name: "Log out" }).click()
|
||||
await page.goto("/login")
|
||||
}
|
||||
Reference in New Issue
Block a user