Skip to content

Commit ebc7e58

Browse files
add dashboard tests
1 parent c688964 commit ebc7e58

File tree

2 files changed

+94
-11
lines changed

2 files changed

+94
-11
lines changed

docker-compose.override.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
services:
2-
32
# Local services are available on their ports, but also available on:
43
# http://api.localhost.tiangolo.com: backend
54
# http://dashboard.localhost.tiangolo.com: frontend
@@ -67,16 +66,16 @@ services:
6766
- run
6867
- --reload
6968
- "app/main.py"
70-
develop:
71-
watch:
72-
- path: ./backend
73-
action: sync
74-
target: /app
75-
ignore:
76-
- ./backend/.venv
77-
- .venv
78-
- path: ./backend/pyproject.toml
79-
action: rebuild
69+
# develop:
70+
# watch:
71+
# - path: ./backend
72+
# action: sync
73+
# target: /app
74+
# ignore:
75+
# - ./backend/.venv
76+
# - .venv
77+
# - path: ./backend/pyproject.toml
78+
# action: rebuild
8079
# TODO: remove once coverage is done locally
8180
volumes:
8281
- ./backend/htmlcov:/app/htmlcov

frontend/tests/dashboard.spec.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

Comments
 (0)