46 lines
1.9 KiB
TypeScript
46 lines
1.9 KiB
TypeScript
import { expect } from "@playwright/test";
|
|
import { test } from "../fixtures";
|
|
import { registerAndLogin } from "../helpers";
|
|
|
|
test("a user can register and log in", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await expect(page.locator("h1")).toContainText("Grocery lists");
|
|
});
|
|
|
|
test("a user can log out", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await page.click('button:has-text("Sign out")');
|
|
await expect(page).toHaveURL(/\/login/);
|
|
await expect(page.locator("h1")).toContainText("Welcome back");
|
|
});
|
|
|
|
test("a user can change their password", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await page.goto("/account");
|
|
await page.fill("#new-password", "a-new-strong-password");
|
|
await page.fill("#confirm-password", "a-new-strong-password");
|
|
await page.click('button:has-text("Update password")');
|
|
await expect(page.locator(".alert-success")).toContainText("updated");
|
|
|
|
// The old password no longer works; the new one does.
|
|
await page.click('button:has-text("Sign out")');
|
|
await page.fill("#email", "alice@example.com");
|
|
await page.fill("#password", "a-strong-password");
|
|
await page.click('button[type="submit"]');
|
|
await expect(page.locator(".alert-error")).toContainText("incorrect");
|
|
|
|
await page.fill("#email", "alice@example.com");
|
|
await page.fill("#password", "a-new-strong-password");
|
|
await page.click('button[type="submit"]');
|
|
await expect(page).toHaveURL(/\/lists/);
|
|
});
|
|
|
|
test("changing password rejects a mismatched confirmation", async ({ page }) => {
|
|
await registerAndLogin(page, "alice@example.com");
|
|
await page.goto("/account");
|
|
await page.fill("#new-password", "a-new-strong-password");
|
|
await page.fill("#confirm-password", "a-different-password");
|
|
await page.click('button:has-text("Update password")');
|
|
await expect(page.locator(".alert-error")).toContainText("do not match");
|
|
});
|