feat: expand intelligent investigation workspace
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import "@/test/radix-select-test-setup";
|
||||
import { PresentationViewHistory } from "../utils/presentation-view-history";
|
||||
import { PresentationHistorySwitcher } from "./presentation-history-switcher";
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
function entries() {
|
||||
const history = new PresentationViewHistory();
|
||||
history.record("压力曲线", "preview", null);
|
||||
history.update({ ...history.current, records: [{ element_id: "V1" }] });
|
||||
history.record("阀门列表", "preview", null);
|
||||
return history.entries;
|
||||
}
|
||||
|
||||
it("merges the latest result into current and skips its duplicate when going back", async () => {
|
||||
const user = userEvent.setup();
|
||||
const history = entries();
|
||||
const onSelect = vi.fn();
|
||||
render(
|
||||
<PresentationHistorySwitcher
|
||||
entries={history}
|
||||
currentEntryId={history[1].id}
|
||||
selectedId={null}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
);
|
||||
await user.click(screen.getByRole("combobox", { name: "切换展示动作" }));
|
||||
expect(screen.getAllByRole("option")).toHaveLength(2);
|
||||
expect(screen.getByRole("option", { name: /当前(最新).*阀门列表/ })).toBeVisible();
|
||||
expect(screen.getByRole("option", { name: /1\. 压力曲线/ })).toBeVisible();
|
||||
expect(screen.queryByRole("option", { name: /^2\. 阀门列表/ })).not.toBeInTheDocument();
|
||||
await user.keyboard("{Escape}");
|
||||
await user.click(screen.getByRole("button", { name: "上一个动作" }));
|
||||
expect(onSelect).toHaveBeenCalledWith(history[0].id);
|
||||
});
|
||||
|
||||
it("keeps the final historical result selectable when current has been cleared", async () => {
|
||||
const user = userEvent.setup();
|
||||
const history = entries();
|
||||
const onSelect = vi.fn();
|
||||
render(
|
||||
<PresentationHistorySwitcher
|
||||
entries={history}
|
||||
currentEntryId={null}
|
||||
selectedId={null}
|
||||
onSelect={onSelect}
|
||||
/>
|
||||
);
|
||||
await user.click(screen.getByRole("combobox", { name: "切换展示动作" }));
|
||||
expect(screen.getAllByRole("option").map((option) => option.textContent)).toEqual([
|
||||
"当前(最新) · 2 个动作",
|
||||
"2. 阀门列表 · 完成",
|
||||
"1. 压力曲线 · 完成"
|
||||
]);
|
||||
await user.click(screen.getByRole("option", { name: /^2\. 阀门列表/ }));
|
||||
expect(onSelect).toHaveBeenCalledWith(history[1].id);
|
||||
});
|
||||
Reference in New Issue
Block a user