Files
Alfred/tests/web/routes/404.test.tsx
lanyuanxiaoyao b1dec691e9 refactor(web): 前端目录重构 — consoles/pages → layouts/features + shared
- consoles/admin/ → layouts/admin-layout/
- consoles/workbench/ → layouts/workbench-layout/ + features/chat/
- pages/ → features/ (dashboard, models, projects, not-found)
- components/ → shared/components/
- hooks/ → shared/hooks/
- utils/ → shared/utils/
- 更新所有 import 路径 (src/web/ + tests/web/)
- 更新开发文档 (README.md, frontend.md, architecture.md)
2026-06-02 23:17:28 +08:00

34 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { fireEvent, screen } from "@testing-library/react";
import { describe, expect, test } from "bun:test";
import { createElement } from "react";
import { useLocation } from "react-router";
import { NotFoundPage } from "../../../src/web/features/not-found";
import { renderWithProviders } from "../test-utils";
function LocationProbe() {
const location = useLocation();
return <span>{location.pathname}</span>;
}
describe("NotFoundPage", () => {
test("渲染 404 页面", () => {
renderWithProviders(createElement(NotFoundPage));
expect(screen.getByText("404")).not.toBeNull();
expect(screen.getByText("您访问的页面不存在")).not.toBeNull();
expect(screen.getByRole("button", { name: "返回首页" })).not.toBeNull();
});
test("点击返回首页按钮导航到首页", () => {
renderWithProviders(createElement("div", null, createElement(NotFoundPage), createElement(LocationProbe)), {
initialRoute: "/missing",
});
const button = screen.getByRole("button", { name: "返回首页" });
fireEvent.click(button);
expect(screen.getByText("当前路径:/")).not.toBeNull();
});
});