fix: close browser session lifecycle gaps
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { App } from "../src/App.js";
|
||||
import { createInitialHarnessState, type HarnessClientState } from "../src/store/reducer.js";
|
||||
|
||||
@@ -24,6 +24,7 @@ function makeStore() {
|
||||
subscribe: () => () => undefined,
|
||||
sendMessage,
|
||||
cancel: vi.fn().mockResolvedValue({ cancelled: false }),
|
||||
dispose: vi.fn().mockResolvedValue(undefined),
|
||||
start: vi.fn().mockResolvedValue(undefined),
|
||||
getModelConfig: vi.fn().mockResolvedValue({
|
||||
modelConfig: { configured: true, source: "environment", providerId: "openai", api: "openai-responses", modelId: "gpt-test", supportsImages: true },
|
||||
@@ -31,6 +32,8 @@ function makeStore() {
|
||||
};
|
||||
}
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
describe("App", () => {
|
||||
it("renders the three primary work areas", () => {
|
||||
render(<App store={makeStore()} autoStart={false} modelConfigured />);
|
||||
@@ -55,4 +58,37 @@ describe("App", () => {
|
||||
expect(screen.getByRole("button", { name: "发送消息" })).toBeDisabled();
|
||||
expect(screen.getByText("请先配置模型连接")).toBeVisible();
|
||||
});
|
||||
|
||||
it("switches to the event timeline in the mobile tab layout", async () => {
|
||||
vi.stubGlobal("matchMedia", vi.fn(() => ({
|
||||
matches: true,
|
||||
media: "(max-width: 720px)",
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
})));
|
||||
const user = userEvent.setup();
|
||||
render(<App store={makeStore()} autoStart={false} modelConfigured />);
|
||||
|
||||
await user.click(screen.getByRole("tab", { name: "Events" }));
|
||||
|
||||
expect(screen.getByRole("tab", { name: "Events" })).toHaveAttribute("aria-selected", "true");
|
||||
expect(screen.getByRole("region", { name: "Event Timeline" })).toBeVisible();
|
||||
expect(screen.queryByRole("main", { name: "Streaming Chat" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("deletes the old session before starting a reset session", async () => {
|
||||
const user = userEvent.setup();
|
||||
const store = makeStore();
|
||||
render(<App store={store} autoStart={false} modelConfigured />);
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "重置训练会话" }));
|
||||
|
||||
expect(store.dispose).toHaveBeenCalledTimes(1);
|
||||
expect(store.start).toHaveBeenCalledTimes(1);
|
||||
expect(store.dispose.mock.invocationCallOrder[0]).toBeLessThan(store.start.mock.invocationCallOrder[0] ?? 0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user