import { test, expect } from "@playwright/test";

test("login redirects to dashboard, dashboard requires auth", async ({ page }) => {
  await page.goto("/");
  // unauthenticated -> middleware redirects to /login
  await expect(page).toHaveURL(/\/login$/);

  // wrong password
  await page.fill("#password", "wrong");
  await page.click('button[type="submit"]');
  await expect(page.locator("text=Invalid password")).toBeVisible();

  // correct password (set via seed-password)
  await page.fill("#password", "pmpassword123");
  await page.click('button[type="submit"]');
  await expect(page).toHaveURL(/\/$/);
  await expect(page.locator("h1")).toContainText("Projects");
});
