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

describe("IframeDisplay", () => {
  it("renders an iframe with the given src", () => {
    const wrapper = mount(IframeDisplay, {
      props: { src: "https://example.com" },
    })
    const iframe = wrapper.find("iframe")
    expect(iframe.exists()).toBe(true)
    expect(iframe.attributes("src")).toBe("https://example.com")
  })

  it("does not render an iframe when src is missing", () => {
    const wrapper = mount(IframeDisplay, { props: {} })
    expect(wrapper.find("iframe").exists()).toBe(false)
  })

  it("applies the default sandbox attribute", () => {
    const wrapper = mount(IframeDisplay, {
      props: { src: "https://example.com" },
    })
    expect(wrapper.find("iframe").attributes("sandbox")).toBe(
      "allow-scripts allow-same-origin",
    )
  })

  it("allows overriding the sandbox attribute", () => {
    const wrapper = mount(IframeDisplay, {
      props: {
        src: "https://example.com",
        sandbox: "allow-scripts allow-same-origin allow-forms",
      },
    })
    expect(wrapper.find("iframe").attributes("sandbox")).toBe(
      "allow-scripts allow-same-origin allow-forms",
    )
  })

  it("applies the title attribute", () => {
    const wrapper = mount(IframeDisplay, {
      props: { src: "https://example.com", title: "Map" },
    })
    expect(wrapper.find("iframe").attributes("title")).toBe("Map")
  })

  it("applies classList to the root", () => {
    const wrapper = mount(IframeDisplay, {
      props: { src: "https://example.com", classList: "extra" },
    })
    expect(wrapper.attributes("class")).toContain("extra")
  })
})
