import { describe, expect, it } from "vitest"
import { mount } from "@vue/test-utils"
import CheckboxOption from "./CheckboxOption.vue"

describe("CheckboxOption (props-based composition)", () => {
  it("mounts without error", () => {
    const wrapper = mount(CheckboxOption, { props: { label: "Prefs" } })
    expect(wrapper.exists()).toBe(true)
  })

  it("renders the label via FieldFrame", () => {
    const wrapper = mount(CheckboxOption, {
      props: { label: "Custom label" },
    })
    expect(wrapper.text()).toContain("Custom label")
  })

  it("hides the visible label when hideLabel is true", () => {
    const wrapper = mount(CheckboxOption, {
      props: { label: "Hidden", hideLabel: true },
    })
    expect(wrapper.find("[data-testid='field-frame-label-sr']").exists()).toBe(
      true,
    )
  })

  it("renders each option label", () => {
    const wrapper = mount(CheckboxOption, {
      props: {
        label: "Prefs",
        options: [
          { label: "Newsletter", value: "news" },
          { label: "SMS", value: "sms" },
        ],
      },
    })
    expect(wrapper.text()).toContain("Newsletter")
    expect(wrapper.text()).toContain("SMS")
  })

  it("renders help text", () => {
    const wrapper = mount(CheckboxOption, {
      props: { label: "X", helpText: "Pick any" },
    })
    expect(wrapper.find("[data-testid='field-frame-help']").text()).toBe(
      "Pick any",
    )
  })

  it("renders errors when provided", () => {
    const wrapper = mount(CheckboxOption, {
      props: { label: "X", errors: ["Pick one"] },
    })
    expect(wrapper.find("[data-testid='field-frame-errors']").exists()).toBe(
      true,
    )
  })

  it("works without any props at all", () => {
    const wrapper = mount(CheckboxOption)
    expect(wrapper.exists()).toBe(true)
  })
})
