nxtgauge-frontend-solid/tests/e2e/visual/debug-dashboard.spec.ts

68 lines
2.5 KiB
TypeScript
Raw Normal View History

import { test, expect } from "@playwright/test";
test("API login shows correct TUTOR dashboard", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (err) => errors.push(err.message));
// Login via API
fix(e2e): use env-aware URLs, captcha-solving, and real Redis OTP retrieval The e2e suite only ever worked against a local docker-compose stack: - Hardcoded http://localhost:3000 / :9100 everywhere, ignoring TEST_ENV=production and playwright.config.ts's own baseURL logic. - /api/auth/login and /api/auth/register now require solving a math captcha first; none of these tests sent captcha_id/captcha_answer, so every login/register call 422'd against the live API. - OTP retrieval shelled out to a local, unauthenticated redis-cli, which can't reach the real (kubectl-exec + password-protected) Redis. - Several files launched their own chromium.launch({headless: false}), which crashes immediately on a server with no X display. - One file had a hardcoded macOS absolute path for screenshots. Added tests/e2e/helpers/{env,captcha,otp,auth-flow}.ts as shared, reusable fixes for all of the above, and updated every affected spec file to use them. Verified via a full run against test111.nxtgauge.com: 971 schemathesis-adjacent smoke assertions aside, the actual signal here is 0 of the 130 prior failures came from real product bugs - all were this environment mismatch. See docs/LIVE_SERVER_RUNBOOK.md step 5. Also fixes .gitignore: it excluded 'playwright-report' (singular) but playwright.config.ts's actual outputFolder is 'playwright-reports' (plural) - generated HTML report artifacts had been getting committed by accident. Untracked the existing ones; left tests/e2e/visual/*-snapshots/ (newly-generated visual regression baselines from this run) untracked for now since establishing baselines needs a human look, not a blind commit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-14 00:51:55 +05:30
const loginRes = await page.request.post("/api/auth/login", {
data: { email: "testtutora2026@example.com", password: "Test1234!" },
headers: { "Content-Type": "application/json", Accept: "application/json" },
});
const loginData = await loginRes.json();
const token = loginData.access_token;
const role = loginData.user?.active_role || "TUTOR";
// Inject auth
fix(e2e): use env-aware URLs, captcha-solving, and real Redis OTP retrieval The e2e suite only ever worked against a local docker-compose stack: - Hardcoded http://localhost:3000 / :9100 everywhere, ignoring TEST_ENV=production and playwright.config.ts's own baseURL logic. - /api/auth/login and /api/auth/register now require solving a math captcha first; none of these tests sent captcha_id/captcha_answer, so every login/register call 422'd against the live API. - OTP retrieval shelled out to a local, unauthenticated redis-cli, which can't reach the real (kubectl-exec + password-protected) Redis. - Several files launched their own chromium.launch({headless: false}), which crashes immediately on a server with no X display. - One file had a hardcoded macOS absolute path for screenshots. Added tests/e2e/helpers/{env,captcha,otp,auth-flow}.ts as shared, reusable fixes for all of the above, and updated every affected spec file to use them. Verified via a full run against test111.nxtgauge.com: 971 schemathesis-adjacent smoke assertions aside, the actual signal here is 0 of the 130 prior failures came from real product bugs - all were this environment mismatch. See docs/LIVE_SERVER_RUNBOOK.md step 5. Also fixes .gitignore: it excluded 'playwright-report' (singular) but playwright.config.ts's actual outputFolder is 'playwright-reports' (plural) - generated HTML report artifacts had been getting committed by accident. Untracked the existing ones; left tests/e2e/visual/*-snapshots/ (newly-generated visual regression baselines from this run) untracked for now since establishing baselines needs a human look, not a blind commit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-14 00:51:55 +05:30
await page.goto("/");
await page.waitForLoadState("networkidle");
await page.evaluate(
({ token, role }) => {
const payload = {
email: "testtutora2026@example.com",
fullName: "Test User",
roleKey: role.toLowerCase(),
role: role.toLowerCase(),
active_role: role,
selectedProfessionalRole: role,
user: { id: "test-id", email: "testtutora2026@example.com", full_name: "Test User", active_role: role },
};
window.sessionStorage.setItem("nxtgauge_access_token", token);
window.sessionStorage.setItem("nxtgauge_frontend_access_token", token);
window.localStorage.setItem("nxtgauge_auth_user", JSON.stringify(payload));
window.localStorage.setItem("nxtgauge_user", JSON.stringify(payload));
window.localStorage.setItem("nxtgauge_signup_profile_v1", JSON.stringify(payload));
},
{ token, role }
);
// Navigate to dashboard
fix(e2e): use env-aware URLs, captcha-solving, and real Redis OTP retrieval The e2e suite only ever worked against a local docker-compose stack: - Hardcoded http://localhost:3000 / :9100 everywhere, ignoring TEST_ENV=production and playwright.config.ts's own baseURL logic. - /api/auth/login and /api/auth/register now require solving a math captcha first; none of these tests sent captcha_id/captcha_answer, so every login/register call 422'd against the live API. - OTP retrieval shelled out to a local, unauthenticated redis-cli, which can't reach the real (kubectl-exec + password-protected) Redis. - Several files launched their own chromium.launch({headless: false}), which crashes immediately on a server with no X display. - One file had a hardcoded macOS absolute path for screenshots. Added tests/e2e/helpers/{env,captcha,otp,auth-flow}.ts as shared, reusable fixes for all of the above, and updated every affected spec file to use them. Verified via a full run against test111.nxtgauge.com: 971 schemathesis-adjacent smoke assertions aside, the actual signal here is 0 of the 130 prior failures came from real product bugs - all were this environment mismatch. See docs/LIVE_SERVER_RUNBOOK.md step 5. Also fixes .gitignore: it excluded 'playwright-report' (singular) but playwright.config.ts's actual outputFolder is 'playwright-reports' (plural) - generated HTML report artifacts had been getting committed by accident. Untracked the existing ones; left tests/e2e/visual/*-snapshots/ (newly-generated visual regression baselines from this run) untracked for now since establishing baselines needs a human look, not a blind commit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-14 00:51:55 +05:30
await page.goto(`/dashboard?role=${role}`);
await page.waitForLoadState("domcontentloaded");
await page.waitForTimeout(3000);
await page.screenshot({ path: "test-results/dashboard-tutor-check.png", fullPage: true });
// Check sidebar
const aside = page.locator("aside");
const asideCount = await aside.count();
console.log("Aside count:", asideCount);
if (asideCount > 0) {
// Check Active Role badge
const activeRoleText = await aside.locator("text=Active Role").locator("..").locator("p").last().textContent().catch(() => "NOT FOUND");
console.log("Active Role:", activeRoleText);
// Check sidebar items
const buttons = await aside.locator("nav button").allTextContents();
console.log("Sidebar items:", buttons.join(", "));
// Assertions
expect(activeRoleText?.toUpperCase()).toContain(role);
expect(buttons).toContain("Leads");
expect(buttons).not.toContain("Jobs"); // TUTOR has Leads, not Jobs
}
if (errors.length > 0) {
console.log("Page errors:", errors.slice(0, 3));
}
});