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

test("step 3 Build + tobacco: needs height, weight, BMI, tobacco", async ({ request, page }) => {
  const created = await createCase(request);
  const c = await sendMany(request, created.caseId, [
    STEP_SCRIPT.name,
    STEP_SCRIPT.state,
    STEP_SCRIPT.intent,
    STEP_SCRIPT.age,
    STEP_SCRIPT.loan,
  ]);
  expect(c.process.step).toBe(3);
  expect(c.process.missingRequired).toEqual(
    expect.arrayContaining(["height_ft_in", "weight_lb", "tobacco"])
  );

  await openCaseOnStep(page, c.caseId);
  await expect(page.getByTestId("process-current")).toHaveText("Build + tobacco");
  await expect(page.getByTestId("process-exit-gate")).toContainText("BMI computed + tobacco answered");

  const built = await sendChat(request, c.caseId, STEP_SCRIPT.build);
  expect(built.profile.height_ft_in).toBeTruthy();
  expect(built.profile.weight_lb).toBe(160);
  expect(built.profile.bmi_computed).toBeTruthy();
  expect(built.profile.tobacco_answered).toBe(true);
  expect(built.process.step).toBe(4);
});
