test(web): 添加WechatCallback页面基础单元测试
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 5s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 53s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 47s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 28s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 3m40s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m58s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 53s
AI Code Review / AI Code Review (pull_request) Successful in 3m56s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 13s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 6m47s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 29s
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 49m12s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1316h15m14s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 1316h15m18s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1316h15m22s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1316h15m24s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1316h15m36s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 1316h15m40s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 1316h15m42s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 1316h16m15s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 1316h16m17s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 1316h21m37s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 1316h21m39s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 1316h21m41s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 1316h48m0s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1316h47m42s

This commit is contained in:
2026-07-23 18:56:24 +08:00
parent ee916acb1b
commit 2f237c80cf
@@ -0,0 +1,72 @@
import { describe, expect, it, vi, beforeEach } from "vitest"
import { render, screen } from "@testing-library/react"
import { MemoryRouter } from "react-router-dom"
import WechatCallback from "@/pages/auth/WechatCallback"
// 重置 localStorage
beforeEach(() => {
vi.spyOn(Storage.prototype, "getItem").mockReturnValue(null)
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {})
vi.spyOn(Storage.prototype, "removeItem").mockImplementation(() => {})
})
vi.mock("react-router-dom", async () => {
const actual = await vi.importActual("react-router-dom")
return {
...actual,
useNavigate: () => vi.fn(),
useSearchParams: () => [new URLSearchParams()],
}
})
vi.mock("@/api/auth", () => ({
wechatCallback: vi.fn(),
getCurrentUser: vi.fn(),
normalizeUser: (u: unknown) => u,
}))
vi.mock("@/store/authStore", () => ({
useAuthStore: () => ({
setAuth: vi.fn(),
}),
}))
vi.mock("@/components/auth/BindContactModal", () => ({
default: ({ open }: { open: boolean }) => (
<div data-testid="bind-contact-modal" style={{ display: open ? "block" : "none" }}>
BindContactModal
</div>
),
}))
vi.mock("antd", async () => {
const actual = await vi.importActual("antd")
return {
...actual,
message: {
success: vi.fn(),
error: vi.fn(),
},
}
})
describe("WechatCallback Page", () => {
it("should render without crashing", () => {
const { container } = render(
<MemoryRouter>
<WechatCallback />
</MemoryRouter>,
)
expect(container).toBeTruthy()
})
it("should show loading state initially", () => {
render(
<MemoryRouter>
<WechatCallback />
</MemoryRouter>,
)
// 初始状态应该显示加载中
expect(screen.getByText("正在登录...")).toBeTruthy()
})
})