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

// UI smoke against the React frontend served by Vite. We don't need a real
// Wails backend: the only runtime call on mount (GetLastUserID) throws because
// window.go is undefined, the catch path drops the loading overlay, and
// LoginScreen renders identically to what the production app shows on first
// launch. This catches HTML/CSS/asset regressions + Mantine bundle errors
// without dragging the full Go+goolm compile into CI.

test("LoginScreen renders with Sign-in button", async ({ page }) => {
  // Swallow uncaught Wails-runtime errors so they don't fail the test.
  page.on("pageerror", () => {});
  await page.goto("/");
  await expect(page.getByRole("heading", { name: /matrix_client_pc/i })).toBeVisible();
  await expect(
    page.getByRole("button", { name: /sign in with matrix/i }),
  ).toBeVisible();
});

test("LoginScreen mentions homeserver + MAS context", async ({ page }) => {
  page.on("pageerror", () => {});
  await page.goto("/");
  await expect(page.getByText(/matrix-af2f3d/)).toBeVisible();
  await expect(
    page.getByText(/matrix authentication service/i),
  ).toBeVisible();
});

test("LoginScreen shows version tag", async ({ page }) => {
  page.on("pageerror", () => {});
  await page.goto("/");
  await expect(page.getByText(/v0\.1\.0 \(issue 0147\)/i)).toBeVisible();
});
