import { composeStories } from "@storybook/react"
import { expect, userEvent, waitFor } from "storybook/test"
import { test } from "vitest"
import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts"
import { mountStory } from "../mountStory.testHelpers.ts"
import { expectAgentDrivable } from "../testing/index.ts"
import * as stories from "./Lightbox.stories.tsx"
const { Controlled, Playground, Interactive, WithCaption } =
composeStories(stories)
test("the thumbnail opens the enlarged image", async () => {
const { body, canvas } = await mountStory(Playground)
await userEvent.click(
expectAgentDrivable(canvas, {
name: "Enlarge THE OUTFIT poster",
role: "button",
}),
)
const dialog = expectAgentDrivable(body, {
name: "THE OUTFIT poster",
role: "dialog",
})
// The enlarged image carries the name — a bare `
` in a dialog
// otherwise announces as nothing.
expectAgentDrivable(body, {
name: "THE OUTFIT poster",
role: "img",
})
// The open dialog audits itself: the empty-alt thumbnail, the
// named trigger and the named enlarged image are the arrangement
// most likely to trip `button-name` or a duplicate name.
await expectNoAxeViolations(dialog)
})
test("the caption rides along with the enlarged image", async () => {
const { body, canvas } = await mountStory(WithCaption)
await userEvent.click(
canvas.getByRole("button", {
name: "Enlarge THE OUTFIT poster",
}),
)
await expect(
body.getByText("2022 · Blu-ray · 1080p"),
).toBeInTheDocument()
})
/**
* The keyboard contract, inherited from `Dialog` and asserted here so
* the skin cannot quietly drop it — Escape routes through `onClose`,
* and focus returns to the trigger `FloatingFocusManager` restored it
* to. Escape is a real `userEvent` keypress now, since the overlay is
* no longer a native `