import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react"; import { afterEach, describe, expect, it, vi } from "vitest"; import { HunkActionBar } from "./hunk-action-bar"; describe("HunkActionBar", () => { afterEach(() => { cleanup(); }); it("clears loading when revert resolves without unmounting the hunk", async () => { const onRevert = vi.fn().mockResolvedValue(undefined); render( {}} onMouseLeave={() => {}} />, ); const button = screen.getByRole("button", { name: "Undo" }); fireEvent.click(button); await waitFor(() => expect(onRevert).toHaveBeenCalledTimes(1)); await waitFor(() => expect(button.hasAttribute("disabled")).toBe(false)); }); it("clears loading and swallows the click error when revert rejects", async () => { const onRevert = vi.fn().mockRejectedValue(new Error("revert failed")); render( {}} onMouseLeave={() => {}} />, ); const button = screen.getByRole("button", { name: "Undo" }); fireEvent.click(button); await waitFor(() => expect(onRevert).toHaveBeenCalledTimes(1)); await waitFor(() => expect(button.hasAttribute("disabled")).toBe(false)); }); });