test: consolidate repetitive cases across the suite
This commit is contained in:
1 parent
c406024b59
commit
6eccc2859a
31 files changed
+745
-1315
No files matched your search
@@ -223,10 +223,13 @@ describe("MarkdownTextRenderer", () => {
|
||||
expect(screen.getByText("src/**/*.json").tagName).toBe("CODE");
|
||||
});
|
||||
|
||||
it("does not wrap complete fenced code blocks in an extra pre", () => {
|
||||
it.each([
|
||||
["complete", "\n```"],
|
||||
["streaming", ""],
|
||||
])("renders a %s fenced code block in one shell", (_state, closingFence) => {
|
||||
const { container } = render(
|
||||
<MarkdownTextRenderer highlightCode={false}>
|
||||
{"当前目录:\n\n```text\n/Users/renxubin/.nanobot/workspace\n```"}
|
||||
{"当前目录:\n\n```text\n/Users/renxubin/.nanobot/workspace" + closingFence}
|
||||
</MarkdownTextRenderer>,
|
||||
);
|
||||
|
||||
@@ -248,17 +251,6 @@ describe("MarkdownTextRenderer", () => {
|
||||
expect(container.querySelectorAll("pre")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps streaming unfinished fenced code blocks to a single shell", () => {
|
||||
const { container } = render(
|
||||
<MarkdownTextRenderer highlightCode={false}>
|
||||
{"当前目录:\n\n```text\n/Users/renxubin/.nanobot/workspace"}
|
||||
</MarkdownTextRenderer>,
|
||||
);
|
||||
|
||||
expect(screen.getByText("/Users/renxubin/.nanobot/workspace")).toBeInTheDocument();
|
||||
expect(container.querySelectorAll("pre")).toHaveLength(1);
|
||||
expect(container.querySelector("pre div")).toBeNull();
|
||||
});
|
||||
|
||||
it("renders markdown images as inline previews", () => {
|
||||
render(<MarkdownTextRenderer></MarkdownTextRenderer>);
|
||||
|
||||
@@ -2787,44 +2787,25 @@ describe("useNanobotStream", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps assistant html media as a file attachment", () => {
|
||||
it.each([
|
||||
{ name: "index.html", kind: "file", url: "/api/media/sig/html" },
|
||||
{ name: "growth.svg", kind: "image", url: "/api/media/sig/svg" },
|
||||
])("classifies assistant $name media as $kind", ({ name, kind, url }) => {
|
||||
const fake = fakeClient();
|
||||
const { result } = renderHook(() => useNanobotStream("chat-html-media", EMPTY_MESSAGES), {
|
||||
const { result } = renderHook(() => useNanobotStream("chat-media", EMPTY_MESSAGES), {
|
||||
wrapper: wrap(fake.client),
|
||||
});
|
||||
|
||||
act(() => {
|
||||
fake.emit("chat-html-media", {
|
||||
fake.emit("chat-media", {
|
||||
event: "message",
|
||||
chat_id: "chat-html-media",
|
||||
text: "file ready",
|
||||
media_urls: [{ url: "/api/media/sig/html", name: "index.html" }],
|
||||
chat_id: "chat-media",
|
||||
text: "media ready",
|
||||
media_urls: [{ url, name }],
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.messages[0].media).toEqual([
|
||||
{ kind: "file", url: "/api/media/sig/html", name: "index.html" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("infers assistant svg media as an image attachment", () => {
|
||||
const fake = fakeClient();
|
||||
const { result } = renderHook(() => useNanobotStream("chat-svg-media", EMPTY_MESSAGES), {
|
||||
wrapper: wrap(fake.client),
|
||||
});
|
||||
|
||||
act(() => {
|
||||
fake.emit("chat-svg-media", {
|
||||
event: "message",
|
||||
chat_id: "chat-svg-media",
|
||||
text: "chart ready",
|
||||
media_urls: [{ url: "/api/media/sig/svg", name: "growth.svg" }],
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.messages[0].media).toEqual([
|
||||
{ kind: "image", url: "/api/media/sig/svg", name: "growth.svg" },
|
||||
]);
|
||||
expect(result.current.messages[0].media).toEqual([{ kind, url, name }]);
|
||||
});
|
||||
|
||||
it("corrects explicit image media when the name is a non-image file", () => {
|
||||
|
||||
Reference in new issue
Block a user