AstrBot-Desktop/src/App.test.tsx

44 行
1.2 KiB
TypeScript

import { invoke } from "@tauri-apps/api/core";
import { render, screen } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { App } from "./App";
vi.mock("@tauri-apps/api/core", () => ({
invoke: vi.fn(),
}));
describe("App", () => {
beforeEach(() => {
vi.mocked(invoke).mockResolvedValue({
appVersion: "0.1.0-alpha.0",
platform: "windows",
rustCore: "ready",
protocolVersion: "desktop-v1alpha1",
databaseSchemaVersion: 1,
});
});
it("renders the verified Rust bootstrap status", async () => {
render(<App />);
expect(await screen.findByText("ready")).toBeInTheDocument();
expect(screen.getByText("desktop-v1alpha1")).toBeInTheDocument();
});
it("rejects an invalid Rust IPC payload", async () => {
vi.mocked(invoke).mockResolvedValueOnce({
appVersion: "0.1.0-alpha.0",
platform: "windows",
rustCore: "unexpected",
protocolVersion: "desktop-v1alpha1",
databaseSchemaVersion: 1,
});
render(<App />);
expect(await screen.findByText(/IPC unavailable:/)).toBeInTheDocument();
expect(screen.queryByText("unexpected")).not.toBeInTheDocument();
});
});