import { test, expect, openContentEntry } from "./fixtures"

test.describe("Admin pagebuilder registry and preview rendering", () => {
    test("renders seeded image-backed blocks through the configured pagebuilder registry", async ({ page }) => {
        await openContentEntry(page, /Playwright Pagebuilder Preview/)

        const previewRoot = page.locator("[data-admin-preview]")
        const heroPreview = previewRoot.locator("[data-block='hero']").first()
        const richtextPreview = previewRoot.locator("[data-block='richtext']").first()

        await expect(previewRoot.first()).toBeVisible()
        await expect(heroPreview.getByRole("heading", { name: "Playwright Registry Hero" })).toBeVisible()
        await expect(richtextPreview).toContainText("Richtext mit Bild")
        await expect(richtextPreview).toContainText("dass ein image-gestuetzter Preview-Block")

        const previewImages = previewRoot.locator("img[data-entry-id]")
        await expect(previewImages.first()).toBeVisible()
        await expect(previewImages.first()).toHaveAttribute("src", /\/medialib\/[^/]+\/file\/[^?]+(?:\?filter=[^"']+)?/)
        await expect(previewImages).toHaveCount(2)
    })
})
