Files
fast_api_template/frontend/tests/sign-up.spec.ts
T

162 lines
4.5 KiB
TypeScript
Raw Normal View History

2025-09-09 14:45:10 +02:00
import { expect, type Page, test } from "@playwright/test"
2024-07-29 12:53:43 -05:00
2024-08-01 11:45:05 -05:00
import { randomEmail, randomPassword } from "./utils/random"
2024-07-29 12:53:43 -05:00
test.use({ storageState: { cookies: [], origins: [] } })
const fillForm = async (
page: Page,
full_name: string,
email: string,
password: string,
confirm_password: string,
) => {
2025-12-07 13:21:13 +01:00
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)
2024-07-29 12:53:43 -05:00
}
2025-12-07 13:21:13 +01:00
const verifyInput = async (page: Page, testId: string) => {
const input = page.getByTestId(testId)
2024-07-29 12:53:43 -05:00
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")
2025-12-07 13:21:13 +01:00
await verifyInput(page, "full-name-input")
await verifyInput(page, "email-input")
await verifyInput(page, "password-input")
await verifyInput(page, "confirm-password-input")
2024-07-29 12:53:43 -05:00
})
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()
2024-08-01 11:45:05 -05:00
const password = randomPassword()
2024-07-29 12:53:43 -05:00
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 }) => {
2024-08-01 11:45:05 -05:00
const fullName = "Test User"
2024-07-29 12:53:43 -05:00
const email = randomEmail()
2024-08-01 11:45:05 -05:00
const password = randomPassword()
2024-07-29 12:53:43 -05:00
// Sign up with an email
await page.goto("/signup")
2024-08-01 11:45:05 -05:00
await fillForm(page, fullName, email, password, password)
2024-07-29 12:53:43 -05:00
await page.getByRole("button", { name: "Sign Up" }).click()
// Sign up again with the same email
await page.goto("/signup")
2024-08-01 11:45:05 -05:00
await fillForm(page, fullName, email, password, password)
2024-07-29 12:53:43 -05:00
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 }) => {
2024-08-01 11:45:05 -05:00
const fullName = "Test User"
2024-07-29 12:53:43 -05:00
const email = randomEmail()
const password = "weak"
await page.goto("/signup")
2024-08-01 11:45:05 -05:00
await fillForm(page, fullName, email, password, password)
2024-07-29 12:53:43 -05:00
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 }) => {
2024-08-01 11:45:05 -05:00
const fullName = "Test User"
2024-07-29 12:53:43 -05:00
const email = randomEmail()
2024-08-01 11:45:05 -05:00
const password = randomPassword()
const password2 = randomPassword()
2024-07-29 12:53:43 -05:00
await page.goto("/signup")
2024-08-01 11:45:05 -05:00
await fillForm(page, fullName, email, password, password2)
2024-07-29 12:53:43 -05:00
await page.getByRole("button", { name: "Sign Up" }).click()
2025-12-07 13:21:13 +01:00
await expect(page.getByText("The passwords don't match")).toBeVisible()
2024-07-29 12:53:43 -05:00
})
test("Sign up with missing full name", async ({ page }) => {
2024-08-01 11:45:05 -05:00
const fullName = ""
2024-07-29 12:53:43 -05:00
const email = randomEmail()
2024-08-01 11:45:05 -05:00
const password = randomPassword()
2024-07-29 12:53:43 -05:00
await page.goto("/signup")
2024-08-01 11:45:05 -05:00
await fillForm(page, fullName, email, password, password)
2024-07-29 12:53:43 -05:00
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 }) => {
2024-08-01 11:45:05 -05:00
const fullName = "Test User"
2024-07-29 12:53:43 -05:00
const email = ""
2024-08-01 11:45:05 -05:00
const password = randomPassword()
2024-07-29 12:53:43 -05:00
await page.goto("/signup")
2024-08-01 11:45:05 -05:00
await fillForm(page, fullName, email, password, password)
2024-07-29 12:53:43 -05:00
await page.getByRole("button", { name: "Sign Up" }).click()
2025-12-07 13:21:13 +01:00
await expect(page.getByText("Invalid email address")).toBeVisible()
2024-07-29 12:53:43 -05:00
})
test("Sign up with missing password", async ({ page }) => {
2024-08-01 11:45:05 -05:00
const fullName = ""
2024-07-29 12:53:43 -05:00
const email = randomEmail()
const password = ""
await page.goto("/signup")
2024-08-01 11:45:05 -05:00
await fillForm(page, fullName, email, password, password)
2024-07-29 12:53:43 -05:00
await page.getByRole("button", { name: "Sign Up" }).click()
await expect(page.getByText("Password is required")).toBeVisible()
})