|
|
@@ -1,8 +1,15 @@
|
|
|
import {render, waitFor} from '@testing-library/react';
|
|
|
-import {useExportFile} from '.';
|
|
|
+import {useTableExportEvent} from '.';
|
|
|
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
|
|
|
import {FC} from 'react';
|
|
|
import {act} from 'react-dom/test-utils';
|
|
|
+import {createTableSearchParamsContext} from '@hooks';
|
|
|
+import {LDTableSearchParamsProvider} from '@components';
|
|
|
+import {
|
|
|
+ RouteObject,
|
|
|
+ RouterProvider,
|
|
|
+ createBrowserRouter,
|
|
|
+} from 'react-router-dom';
|
|
|
|
|
|
const fn = vi.fn();
|
|
|
function mockAsync() {
|
|
|
@@ -14,36 +21,26 @@ function mockAsync() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-describe('useExportFile', function() {
|
|
|
- Object.assign(global, {
|
|
|
- URL: {
|
|
|
- createObjectURL(val: string) {
|
|
|
- return val;
|
|
|
- },
|
|
|
- revokeObjectURL(val: string) {
|
|
|
- return val;
|
|
|
- },
|
|
|
- },
|
|
|
- open() {
|
|
|
- /** mock fn */
|
|
|
- },
|
|
|
- });
|
|
|
-
|
|
|
+describe('useTableExportEvent', function() {
|
|
|
beforeEach(function() {
|
|
|
fn.mockClear();
|
|
|
});
|
|
|
|
|
|
it('定义正确', function() {
|
|
|
- expect(useExportFile).toBeDefined();
|
|
|
+ expect(useTableExportEvent).toBeDefined();
|
|
|
|
|
|
- expect(useExportFile).toBeInstanceOf(Function);
|
|
|
+ expect(useTableExportEvent).toBeInstanceOf(Function);
|
|
|
});
|
|
|
|
|
|
it('测试组件操作', async function() {
|
|
|
const client = new QueryClient();
|
|
|
+ const paramsContext = createTableSearchParamsContext({});
|
|
|
|
|
|
const App: FC = function() {
|
|
|
- const [isExporting, mutate] = useExportFile(mockAsync, '');
|
|
|
+ const [isExporting, mutate] = useTableExportEvent(
|
|
|
+ mockAsync,
|
|
|
+ paramsContext,
|
|
|
+ );
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
@@ -53,10 +50,20 @@ describe('useExportFile', function() {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+ const routes: RouteObject[] = [
|
|
|
+ {
|
|
|
+ path: '/',
|
|
|
+ element: (
|
|
|
+ <LDTableSearchParamsProvider context={paramsContext} state={{}}>
|
|
|
+ <QueryClientProvider client={client}>
|
|
|
+ <App />
|
|
|
+ </QueryClientProvider>,
|
|
|
+ </LDTableSearchParamsProvider>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
const {getByTestId} = render(
|
|
|
- <QueryClientProvider client={client}>
|
|
|
- <App />
|
|
|
- </QueryClientProvider>,
|
|
|
+ <RouterProvider router={createBrowserRouter(routes)} />,
|
|
|
);
|
|
|
|
|
|
expect(getByTestId('state').innerHTML).toBe('false');
|