// @vitest-environment jsdom
import { cleanup, fireEvent, render, screen } from "@testing-library/react"
import { afterEach, describe, expect, it } from "vitest"
import {
ActionGroup,
Bold,
Date,
LexicalActions,
LexicalBubbleToolbar,
LexicalContent,
LexicalFixedToolbar,
LexicalFooter,
LexicalRoot,
} from "."
afterEach(cleanup)
describe("declarative Lexical actions", () => {
it("renders actions only in their declared regions", () => {
render(
undefined}>
)
expect(screen.getByRole("toolbar", { name: "fixed" })).not.toBeNull()
expect(screen.getByLabelText("footer")).not.toBeNull()
expect(screen.getByRole("button", { name: "Bold" })).not.toBeNull()
expect(screen.getByRole("button", { name: "Date" })).not.toBeNull()
})
it("supports menu groups", () => {
render(
undefined}>
)
expect(screen.getByRole("button", { name: "格式" })).not.toBeNull()
})
it("forwards an action className to its default control", () => {
render(
undefined}>
)
expect(
screen
.getByRole("button", { name: "Bold" })
.classList.contains("text-destructive")
).toBe(true)
})
it("forwards an action className to its default menu item", async () => {
render(
undefined}>
)
fireEvent.click(screen.getByRole("button", { name: "格式" }))
expect(
(
await screen.findByRole("menuitem", { name: "Bold" })
).classList.contains("text-destructive")
).toBe(true)
})
it("does not render optional regions without matching actions", () => {
render(
undefined}>
)
expect(screen.queryByLabelText("bubble")).toBeNull()
expect(screen.queryByLabelText("footer")).toBeNull()
})
})