0a4ccdf45c
新增泥点确认状态机共享 hook 并接入拼图与抓大鹅工作台 将首页发现页与个人中心剩余切换条收口到 PlatformSegmentedTabs 统一平台弹窗 header 关闭入口并补齐相关测试 更新前端组件收口文档与团队决策记录
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
/* @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);
|
|
});
|
|
});
|