import { expect, test } from "@playwright/test";
import { createCase, openCaseOnStep, sendChat, sendMany, STEP_SCRIPT } from "./helpers";

test("step 1 Lock intent: name + US state opens intent gate", async ({ request, page }) => {
  const created = await createCase(request);
  const c = await sendMany(request, created.caseId, [STEP_SCRIPT.name, STEP_SCRIPT.state]);
  expect(c.profile.state).toBe("FL");
  expect(c.process.step).toBe(1);
  expect(c.process.missingRequired).toEqual(
    expect.arrayContaining(["intent", "coverage_on_whom"])
  );

  await openCaseOnStep(page, c.caseId);
  await expect(page.getByTestId("process-current")).toHaveText("Lock intent");
  await expect(page.getByTestId("process-exit-gate")).toContainText("Intent + who to cover");

  const next = await sendChat(request, c.caseId, STEP_SCRIPT.intent);
  expect(next.profile.intent).toBe("mortgage_protection");
  expect(next.profile.coverage_on_whom).toBe("primary");
  expect(next.process.step).toBe(2);
});
