✅ Add items and admin tests, and refactor existing ones (#2146)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@@ -6,8 +6,6 @@ import { logInUser, logOutUser } from "./utils/user"
|
||||
|
||||
const tabs = ["My profile", "Password", "Danger zone"]
|
||||
|
||||
// User Information
|
||||
|
||||
test("My profile tab is active by default", async ({ page }) => {
|
||||
await page.goto("/settings")
|
||||
await expect(page.getByRole("tab", { name: "My profile" })).toHaveAttribute(
|
||||
@@ -23,46 +21,64 @@ test("All tabs are visible", async ({ page }) => {
|
||||
}
|
||||
})
|
||||
|
||||
test.describe("Edit user full name and email successfully", () => {
|
||||
test.describe("Edit user profile", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
let email: string
|
||||
let password: string
|
||||
|
||||
test("Edit user name with a valid name", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const updatedName = "Test User 2"
|
||||
const password = randomPassword()
|
||||
|
||||
test.beforeAll(async () => {
|
||||
email = randomEmail()
|
||||
password = randomPassword()
|
||||
await createUser({ email, password })
|
||||
})
|
||||
|
||||
// Log in the user
|
||||
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()
|
||||
// Check if the new name is displayed on the page
|
||||
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 updatedEmail = randomEmail()
|
||||
const password = randomPassword()
|
||||
const updatedEmail = randomEmail()
|
||||
|
||||
await createUser({ email, password })
|
||||
|
||||
// Log in the user
|
||||
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 }),
|
||||
@@ -70,42 +86,21 @@ test.describe("Edit user full name and email successfully", () => {
|
||||
})
|
||||
})
|
||||
|
||||
test.describe("Edit user with invalid data", () => {
|
||||
test.describe("Cancel edit actions", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test("Edit user email with an invalid email", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const invalidEmail = ""
|
||||
|
||||
await createUser({ email, password })
|
||||
|
||||
// Log in the user
|
||||
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(invalidEmail)
|
||||
await page.locator("body").click()
|
||||
await expect(page.getByText("Invalid email address")).toBeVisible()
|
||||
})
|
||||
|
||||
test("Cancel edit action restores original name", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const updatedName = "Test User"
|
||||
|
||||
const user = await createUser({ email, password })
|
||||
|
||||
// Log in the user
|
||||
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(updatedName)
|
||||
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()
|
||||
@@ -114,73 +109,71 @@ test.describe("Edit user with invalid data", () => {
|
||||
test("Cancel edit action restores original email", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const updatedEmail = randomEmail()
|
||||
|
||||
await createUser({ email, password })
|
||||
|
||||
// Log in the user
|
||||
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.getByLabel("Email").fill(randomEmail())
|
||||
await page.getByRole("button", { name: "Cancel" }).first().click()
|
||||
|
||||
await expect(
|
||||
page.locator("form").getByText(email, { exact: true }),
|
||||
).toBeVisible()
|
||||
})
|
||||
})
|
||||
|
||||
// Change Password
|
||||
|
||||
test.describe("Change password successfully", () => {
|
||||
test.describe("Change password", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
|
||||
test("Update password successfully", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const NewPassword = randomPassword()
|
||||
const newPassword = randomPassword()
|
||||
|
||||
await createUser({ email, password })
|
||||
|
||||
// Log in the user
|
||||
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.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)
|
||||
|
||||
// Check if the user can log in with the new password
|
||||
await logInUser(page, email, NewPassword)
|
||||
await logInUser(page, email, newPassword)
|
||||
})
|
||||
})
|
||||
|
||||
test.describe("Change password with invalid data", () => {
|
||||
test.describe("Change password validation", () => {
|
||||
test.use({ storageState: { cookies: [], origins: [] } })
|
||||
let email: string
|
||||
let password: string
|
||||
|
||||
test("Update password with weak passwords", async ({ page }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const weakPassword = "weak"
|
||||
|
||||
test.beforeAll(async () => {
|
||||
email = randomEmail()
|
||||
password = randomPassword()
|
||||
await createUser({ email, password })
|
||||
})
|
||||
|
||||
// Log in the user
|
||||
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()
|
||||
@@ -189,48 +182,26 @@ test.describe("Change password with invalid data", () => {
|
||||
test("New password and confirmation password do not match", async ({
|
||||
page,
|
||||
}) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
const newPassword = randomPassword()
|
||||
const confirmPassword = randomPassword()
|
||||
|
||||
await createUser({ email, password })
|
||||
|
||||
// Log in the user
|
||||
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(confirmPassword)
|
||||
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 }) => {
|
||||
const email = randomEmail()
|
||||
const password = randomPassword()
|
||||
|
||||
await createUser({ email, password })
|
||||
|
||||
// Log in the user
|
||||
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(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()
|
||||
})
|
||||
})
|
||||
|
||||
// Appearance
|
||||
|
||||
test("Appearance button is visible in sidebar", async ({ page }) => {
|
||||
await page.goto("/settings")
|
||||
await expect(page.getByTestId("theme-button")).toBeVisible()
|
||||
@@ -243,7 +214,6 @@ test("User can switch between theme modes", async ({ page }) => {
|
||||
await page.getByTestId("dark-mode").click()
|
||||
await expect(page.locator("html")).toHaveClass(/dark/)
|
||||
|
||||
// wait for dropdown to close before reopening
|
||||
await expect(page.getByTestId("dark-mode")).not.toBeVisible()
|
||||
|
||||
await page.getByTestId("theme-button").click()
|
||||
|
||||
Reference in New Issue
Block a user