import { test, expect } from "@playwright/test";
import { USERS, login } from "./helpers";

/**
 * Issue #96 — sidebar section headings (Purchasing / Crewing / Administration) are
 * collapsible, collapsed by default, and act as a single-open accordion (opening one
 * collapses the others).
 */
test("#96 sidebar sections are collapsible and single-open", async ({ page }) => {
  await login(page, USERS.MANAGER);
  // /dashboard is not inside any section, so all sections start collapsed.
  await page.goto("/dashboard");

  const purchasing = page.getByRole("button", { name: "Purchasing" });
  const crewing = page.getByRole("button", { name: "Crewing" });
  await expect(purchasing).toBeVisible();
  await expect(crewing).toBeVisible();

  // Collapsed by default.
  await expect(purchasing).toHaveAttribute("aria-expanded", "false");
  await expect(crewing).toHaveAttribute("aria-expanded", "false");

  // Opening Purchasing expands it.
  await purchasing.click();
  await expect(purchasing).toHaveAttribute("aria-expanded", "true");

  // Opening Crewing collapses Purchasing (single-open accordion).
  await crewing.click();
  await expect(crewing).toHaveAttribute("aria-expanded", "true");
  await expect(purchasing).toHaveAttribute("aria-expanded", "false");
});
