|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { randomEmail, randomPassword } from "./utils/random"; |
| 3 | +import { signUpNewUser, logInUser, logOutUser } from "./utils/user"; |
| 4 | + |
| 5 | +test.describe("Dashboard page", () => { |
| 6 | + test("is visible after login", async ({ page }) => { |
| 7 | + const email = randomEmail(); |
| 8 | + const password = randomPassword(); |
| 9 | + |
| 10 | + // Sign up a new user |
| 11 | + await signUpNewUser(page, "Playwright Dashboard Test", email, password); |
| 12 | + |
| 13 | + // Log in with the new user |
| 14 | + await logInUser(page, email, password); |
| 15 | + |
| 16 | + // Navigate to dashboard (root path) |
| 17 | + await page.goto("/"); |
| 18 | + // Debug: take screenshot if fails |
| 19 | + try { |
| 20 | + await expect( |
| 21 | + page.getByText("Welcome back, nice to see you again!") |
| 22 | + ).toBeVisible({ timeout: 10000 }); |
| 23 | + } catch (e) { |
| 24 | + await page.screenshot({ |
| 25 | + path: "dashboard-visible-after-login-fail.png", |
| 26 | + fullPage: true, |
| 27 | + }); |
| 28 | + throw e; |
| 29 | + } |
| 30 | + // Check for greeting (user's name or email) |
| 31 | + await expect(page.getByText(/^Hi, /)).toBeVisible({ timeout: 10000 }); |
| 32 | + // Check for at least one button (UI loaded) |
| 33 | + const buttons = await page.getByRole("button").all(); |
| 34 | + expect(buttons.length).toBeGreaterThan(0); |
| 35 | + }); |
| 36 | + |
| 37 | + test("redirects to login when not authenticated", async ({ page }) => { |
| 38 | + await page.goto("/"); |
| 39 | + // Wait for redirect to /login |
| 40 | + await page.waitForURL("/login", { timeout: 10000 }); |
| 41 | + // Debug: take screenshot if fails |
| 42 | + try { |
| 43 | + await expect(page.getByPlaceholder("Email")).toBeVisible({ |
| 44 | + timeout: 10000, |
| 45 | + }); |
| 46 | + await expect( |
| 47 | + page.getByPlaceholder("Password", { exact: true }) |
| 48 | + ).toBeVisible({ timeout: 10000 }); |
| 49 | + } catch (e) { |
| 50 | + await page.screenshot({ |
| 51 | + path: "dashboard-redirect-login-fail.png", |
| 52 | + fullPage: true, |
| 53 | + }); |
| 54 | + throw e; |
| 55 | + } |
| 56 | + }); |
| 57 | + |
| 58 | + test("user can log out from dashboard", async ({ page }) => { |
| 59 | + const email = randomEmail(); |
| 60 | + const password = randomPassword(); |
| 61 | + |
| 62 | + // Sign up and log in |
| 63 | + await signUpNewUser(page, "Playwright Logout Test", email, password); |
| 64 | + await logInUser(page, email, password); |
| 65 | + |
| 66 | + // Log out |
| 67 | + await logOutUser(page); |
| 68 | + // Debug: take screenshot if fails |
| 69 | + try { |
| 70 | + await expect(page.getByPlaceholder("Email")).toBeVisible({ |
| 71 | + timeout: 10000, |
| 72 | + }); |
| 73 | + await expect( |
| 74 | + page.getByPlaceholder("Password", { exact: true }) |
| 75 | + ).toBeVisible({ timeout: 10000 }); |
| 76 | + } catch (e) { |
| 77 | + await page.screenshot({ |
| 78 | + path: "dashboard-logout-login-fail.png", |
| 79 | + fullPage: true, |
| 80 | + }); |
| 81 | + throw e; |
| 82 | + } |
| 83 | + }); |
| 84 | +}); |
0 commit comments