refactor: 统一管理页面布局 — FilterToolbar + usePageSearchParams + parseListParams
This commit is contained in:
53
tests/web/use-confirm-action.test.ts
Normal file
53
tests/web/use-confirm-action.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { XProvider } from "@ant-design/x";
|
||||
import { act, renderHook } from "@testing-library/react";
|
||||
import { App } from "antd";
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { createElement } from "react";
|
||||
|
||||
import { useConfirmAction } from "../../src/web/shared/hooks/useConfirmAction";
|
||||
|
||||
function createWrapper() {
|
||||
return ({ children }: { children: React.ReactNode }) =>
|
||||
createElement(XProvider, null, createElement(App, null, children));
|
||||
}
|
||||
|
||||
describe("useConfirmAction", () => {
|
||||
it("calls action successfully and resolves", async () => {
|
||||
let resolved = false;
|
||||
const action = () => {
|
||||
resolved = true;
|
||||
};
|
||||
|
||||
const { result } = renderHook(() => useConfirmAction(), { wrapper: createWrapper() });
|
||||
|
||||
await act(() => result.current.confirmAction(action, "成功"));
|
||||
expect(resolved).toBe(true);
|
||||
});
|
||||
|
||||
it("handles action error without throwing", async () => {
|
||||
const action = () => {
|
||||
throw new Error("失败");
|
||||
};
|
||||
const { result } = renderHook(() => useConfirmAction(), { wrapper: createWrapper() });
|
||||
|
||||
await act(() => result.current.confirmAction(action, "成功"));
|
||||
expect(resolved).toBe(true);
|
||||
});
|
||||
|
||||
it("handles action error without throwing", async () => {
|
||||
const action = () => {
|
||||
throw new Error("失败");
|
||||
};
|
||||
const { result } = renderHook(() => useConfirmAction(), { wrapper: createWrapper() });
|
||||
|
||||
let threw = false;
|
||||
try {
|
||||
await act(async () => {
|
||||
await result.current.confirmAction(action, "成功");
|
||||
});
|
||||
} catch {
|
||||
threw = true;
|
||||
}
|
||||
expect(threw).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user