fix(webui): avoid empty inline TeX tokens
This commit is contained in:
1 parent
810802e016
commit
870dc2466f
4 files changed
+333
-9
No files matched your search
@@ -2,6 +2,7 @@ import { render, waitFor } from "@testing-library/react";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { MarkdownText } from "@/components/MarkdownText";
|
||||
import mixedMath from "@/tests/fixtures/markdown-math-mixed.md?raw";
|
||||
|
||||
it("retains a rendered TeX formula when an assistant response completes in streaming layout", async () => {
|
||||
const source = String.raw`Before
|
||||
@@ -31,3 +32,38 @@ After`;
|
||||
expect(container).toHaveTextContent("Before");
|
||||
expect(container).toHaveTextContent("After");
|
||||
});
|
||||
|
||||
it("renders a mixed math response through streaming prefixes and completion", async () => {
|
||||
const { container, rerender } = render(
|
||||
<MarkdownText streaming preserveStreamingLayout>{""}</MarkdownText>,
|
||||
);
|
||||
// Load the lazy renderer before exercising updates through its error boundary.
|
||||
rerender(<MarkdownText streaming preserveStreamingLayout>{"# Ready"}</MarkdownText>);
|
||||
await waitFor(() => expect(container.querySelector("h1")).toHaveTextContent("Ready"), {
|
||||
timeout: 10_000,
|
||||
});
|
||||
|
||||
const commandInList = String.raw`\[
|
||||
x=1
|
||||
\]
|
||||
|
||||
- \(\alpha+\beta=\gamma\)`;
|
||||
for (let end = 1; end <= commandInList.length; end++) {
|
||||
rerender(
|
||||
<MarkdownText streaming preserveStreamingLayout>{commandInList.slice(0, end)}</MarkdownText>,
|
||||
);
|
||||
}
|
||||
expect(container.querySelectorAll(".katex")).toHaveLength(2);
|
||||
|
||||
rerender(<MarkdownText streaming preserveStreamingLayout>{mixedMath}</MarkdownText>);
|
||||
expect(container.querySelectorAll("h1")).toHaveLength(20);
|
||||
expect(container.querySelectorAll(".katex")).toHaveLength(34);
|
||||
expect(container.querySelector(".katex-error")).toBeNull();
|
||||
|
||||
rerender(<MarkdownText preserveStreamingLayout>{mixedMath}</MarkdownText>);
|
||||
expect(container.querySelectorAll("h1")).toHaveLength(20);
|
||||
expect(container.querySelectorAll(".katex")).toHaveLength(34);
|
||||
expect(container.querySelector(".katex-error")).toBeNull();
|
||||
expect(container.querySelectorAll("table")).toHaveLength(1);
|
||||
expect(container.querySelector("blockquote")).toBeInTheDocument();
|
||||
}, 30_000);
|
||||
Reference in new issue
Block a user