/* @vitest-environment jsdom */ import { act, renderHook } from '@testing-library/react'; import { describe, expect, it, vi } from 'vitest'; import { useMudPointConfirmController } from './useMudPointConfirmController'; describe('useMudPointConfirmController', () => { it('opens closes and confirms with the latest handler', () => { const firstConfirm = vi.fn(); const secondConfirm = vi.fn(); const { result, rerender } = renderHook( ({ onConfirm }: { onConfirm: () => void }) => useMudPointConfirmController(onConfirm), { initialProps: { onConfirm: firstConfirm, }, }, ); expect(result.current.open).toBe(false); act(() => { result.current.requestOpen(); }); expect(result.current.open).toBe(true); act(() => { result.current.close(); }); expect(result.current.open).toBe(false); rerender({ onConfirm: secondConfirm }); act(() => { result.current.requestOpen(); }); act(() => { result.current.confirm(); }); expect(result.current.open).toBe(false); expect(firstConfirm).not.toHaveBeenCalled(); expect(secondConfirm).toHaveBeenCalledTimes(1); }); });