import { test, expect } from "@playwright/test";
import { loginAs } from "./helpers/login";
import { markOnboarded, clearQuizSessions } from "./helpers/reset-db";

test.describe("Quiz System", () => {
  test.beforeAll(async () => {
    // Ensure joey is onboarded so "Start Labeling Session" appears
    await markOnboarded("joey");
    // Clear any existing quiz sessions so the quiz page shows "Start Quiz"
    await clearQuizSessions("joey");
  });

  test.beforeEach(async ({ page }) => {
    await loginAs(page, "joey");
  });

  test("dashboard shows start labeling button", async ({ page }) => {
    await expect(page.getByText("Start Labeling Session")).toBeVisible();
  });

  test("clicking start session navigates to quiz", async ({ page }) => {
    await page.getByText("Start Labeling Session").click();
    await page.waitForURL("/quiz");
  });

  test("quiz page shows start quiz button", async ({ page }) => {
    await page.goto("/quiz");
    await expect(
      page.getByRole("button", { name: /start quiz/i }),
    ).toBeVisible();
  });

  test("quiz shows 8 questions and allows answering", async ({ page }) => {
    await page.goto("/quiz");
    await page.getByRole("button", { name: /start quiz/i }).click();

    // Should show question 1 of 8
    await expect(page.getByText(/question 1 of 8/i)).toBeVisible();

    // Should show paragraph text and radio options
    await expect(page.locator('[data-slot="radio-group"]')).toBeVisible();
  });
});
