mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { renderDiffDocument } from "./render.js";
|
|
|
|
describe("renderDiffDocument", () => {
|
|
it("renders before/after input into a complete viewer document", async () => {
|
|
const rendered = await renderDiffDocument(
|
|
{
|
|
kind: "before_after",
|
|
before: "const value = 1;\n",
|
|
after: "const value = 2;\n",
|
|
path: "src/example.ts",
|
|
},
|
|
{
|
|
layout: "unified",
|
|
expandUnchanged: false,
|
|
theme: "light",
|
|
},
|
|
);
|
|
|
|
expect(rendered.title).toBe("src/example.ts");
|
|
expect(rendered.fileCount).toBe(1);
|
|
expect(rendered.html).toContain("data-openclaw-diff-root");
|
|
expect(rendered.html).toContain("src/example.ts");
|
|
expect(rendered.html).toContain("/plugins/diffs/assets/viewer.js");
|
|
expect(rendered.html).not.toContain("fonts.googleapis.com");
|
|
});
|
|
|
|
it("renders multi-file patch input", async () => {
|
|
const patch = [
|
|
"diff --git a/a.ts b/a.ts",
|
|
"--- a/a.ts",
|
|
"+++ b/a.ts",
|
|
"@@ -1 +1 @@",
|
|
"-const a = 1;",
|
|
"+const a = 2;",
|
|
"diff --git a/b.ts b/b.ts",
|
|
"--- a/b.ts",
|
|
"+++ b/b.ts",
|
|
"@@ -1 +1 @@",
|
|
"-const b = 1;",
|
|
"+const b = 2;",
|
|
].join("\n");
|
|
|
|
const rendered = await renderDiffDocument(
|
|
{
|
|
kind: "patch",
|
|
patch,
|
|
title: "Workspace patch",
|
|
},
|
|
{
|
|
layout: "split",
|
|
expandUnchanged: true,
|
|
theme: "dark",
|
|
},
|
|
);
|
|
|
|
expect(rendered.title).toBe("Workspace patch");
|
|
expect(rendered.fileCount).toBe(2);
|
|
expect(rendered.html).toContain("Workspace patch");
|
|
});
|
|
});
|