import { beforeEach, describe, expect, it } from "vitest"
import { mount } from "@vue/test-utils"
import { createPinia, setActivePinia } from "pinia"
import { __clearElementCache } from "@/engine/useElementLoader"
import DialogBlock from "./DialogBlock.vue"

describe("DialogBlock", () => {
  beforeEach(() => {
    setActivePinia(createPinia())
    __clearElementCache()
  })

  it("renders a trigger button with the default label", () => {
    const wrapper = mount(DialogBlock)
    // The default label is "Dialog" — when triggerLabel is missing, it
    // falls back to label.
    expect(wrapper.text()).toContain("Dialog")
    // data-stub lives on the inner trigger Button, not the wrapper root.
    expect(wrapper.find("[data-stub]").attributes("data-stub")).toBe(
      "configuration-block/dialog",
    )
  })

  it("renders the triggerLabel prop when provided", () => {
    const wrapper = mount(DialogBlock, {
      props: { triggerLabel: "Configure plugin" },
    })
    expect(wrapper.text()).toContain("Configure plugin")
  })

  it("falls back to label when triggerLabel is missing", () => {
    const wrapper = mount(DialogBlock, { props: { label: "Configure" } })
    expect(wrapper.text()).toContain("Configure")
  })

  it("renders the style key as a badge", () => {
    const wrapper = mount(DialogBlock)
    expect(wrapper.text()).toContain("dialog")
  })
})
