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

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

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

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

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

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

  it("accepts string and object options without throwing", () => {
    const wrapper = mount(SelectOption, {
      props: {
        label: "X",
        options: ["one", { label: "Two", value: 2 }],
      },
    })
    expect(wrapper.exists()).toBe(true)
  })

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