53 lines
1.6 KiB
TypeScript
Raw Normal View History

2026-06-15 19:47:45 +09:00
import { vi } from 'vitest';
// Generic API envelope used by the real backend: `{ code, msg, data }`.
// `data` carries the object-shaped fields pages read off `request(...)`
// directly (`list` for the login tenant search, `nodes`/`edges` for the CRM
// graph), all empty so access never throws.
function makeData() {
return { list: [], total: 0, records: [], nodes: [], edges: [] };
}
export const request = vi.fn(() =>
Promise.resolve({ code: 0, msg: 'ok', success: true, data: makeData() }),
);
export const history = {
push: vi.fn(),
replace: vi.fn(),
back: vi.fn(),
go: vi.fn(),
location: { pathname: '/', search: '', hash: '', state: null },
};
export const useModel = vi.fn(() => ({
initialState: { currentUser: { name: 'tester', menuPaths: [] }, menuPaths: [] },
setInitialState: vi.fn(),
refresh: vi.fn(),
loading: false,
}));
export const useParams = vi.fn(() => ({ id: '1' }));
export const useSearchParams = vi.fn(() => [new URLSearchParams(), vi.fn()]);
export const useNavigate = vi.fn(() => vi.fn());
export const useLocation = vi.fn(() => history.location);
export const useAccess = vi.fn(() => ({}));
export const useIntl = vi.fn(() => ({ formatMessage: ({ defaultMessage }: any) => defaultMessage }));
export const Link = ({ children }: any) => children;
export const NavLink = ({ children }: any) => children;
export const Access = ({ children }: any) => children;
export const Outlet = () => null;
export const getLocale = vi.fn(() => 'zh-CN');
export const setLocale = vi.fn();
export default {
request,
history,
useModel,
useParams,
useNavigate,
Link,
};