import "@testing-library/jest-dom"; import { fireEvent, getQueriesForElement, render } from "@lynx-js/react/testing-library"; import { describe, expect, it, vi } from "vitest"; import { ContextualFloatingButton } from "./ContextualFloatingButton"; function getRenderedRoot() { const root = elementTree.root; if (!root) { throw new Error("Expected Lynx render root to exist."); } return root; } function getContextualFloatingButtonRoot() { const root = getRenderedRoot(); if (root.classList.contains("seed-contextual-floating-button__root")) return root; const button = root.querySelector(".seed-contextual-floating-button__root"); if (!button) { throw new Error("Expected ContextualFloatingButton root to exist."); } return button; } describe("ContextualFloatingButton", () => { it("preserves its label under the loading indicator while blocking taps", () => { const onTap = vi.fn(); render( 저장하기 , ); const root = getContextualFloatingButtonRoot(); expect(getQueriesForElement(getRenderedRoot()).getByText("저장하기")).toBeInTheDocument(); expect(root.querySelector(".seed-progress-circle__root")).toBeInTheDocument(); fireEvent.tap(root); expect(onTap).not.toHaveBeenCalled(); }); it("taps normally again after loading ends", () => { const onTap = vi.fn(); const { rerender } = render( 저장하기 , ); fireEvent.tap(getContextualFloatingButtonRoot()); expect(onTap).not.toHaveBeenCalled(); rerender(저장하기); const root = getContextualFloatingButtonRoot(); expect(root.querySelector(".seed-progress-circle__root")).not.toBeInTheDocument(); fireEvent.tap(root); expect(onTap).toHaveBeenCalledTimes(1); expect(root).toHaveAttribute("accessibility-traits", "button"); }); it("blocks taps and exposes disabled accessibility state when disabled", () => { const onTap = vi.fn(); render( 저장하기 , ); const root = getContextualFloatingButtonRoot(); fireEvent.tap(root); expect(onTap).not.toHaveBeenCalled(); expect(root).toHaveAttribute("accessibility-traits", "disabled"); }); });