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

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

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

  it("hides the visible label when hideLabel is true", () => {
    const wrapper = mount(RadioOption, {
      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(RadioOption, {
      props: {
        label: "Size",
        options: [
          { label: "Small", value: "s" },
          { label: "Large", value: "l" },
        ],
      },
    })
    expect(wrapper.text()).toContain("Small")
    expect(wrapper.text()).toContain("Large")
  })

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

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

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