继续收口平台分段与泥点确认
新增泥点确认状态机共享 hook 并接入拼图与抓大鹅工作台 将首页发现页与个人中心剩余切换条收口到 PlatformSegmentedTabs 统一平台弹窗 header 关闭入口并补齐相关测试 更新前端组件收口文档与团队决策记录
This commit is contained in:
47
src/components/common/useMudPointConfirmController.test.tsx
Normal file
47
src/components/common/useMudPointConfirmController.test.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
/* @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);
|
||||
});
|
||||
});
|
||||
29
src/components/common/useMudPointConfirmController.ts
Normal file
29
src/components/common/useMudPointConfirmController.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
/**
|
||||
* 泥点确认状态机只收口最小开关语义。
|
||||
* 业务页继续自己持有点数、文案、禁用条件和是否需要弹确认的判断。
|
||||
*/
|
||||
export function useMudPointConfirmController(onConfirm: () => void) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const requestOpen = useCallback(() => {
|
||||
setOpen(true);
|
||||
}, []);
|
||||
|
||||
const close = useCallback(() => {
|
||||
setOpen(false);
|
||||
}, []);
|
||||
|
||||
const confirm = useCallback(() => {
|
||||
setOpen(false);
|
||||
onConfirm();
|
||||
}, [onConfirm]);
|
||||
|
||||
return {
|
||||
open,
|
||||
requestOpen,
|
||||
close,
|
||||
confirm,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user