repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by bugabinga
extensions/ui/__tests__/rendering.test.ts
RawFile outline
- ui code and diff rendering line 9
- renders plaintext code immediately line 10
- keeps Shiki lazy and optional line 19
- summarizes diffs and emits Pierre lazy loader line 24
- coalesces streaming message updates by stream id line 35
- clears empty extension status instead of showing method names line 42
- does not locally echo submitted prompts line 48
- keeps internal runtime chatter out of the main stream line 55
import { describe, expect, it } from "vitest";
import { renderAppJs } from "../web/app.js";
import {
renderCodeBlockComponentJs,
renderPlainCodeBlock,
} from "../web/components/code-block.js";
import { diffSummary, renderDiffViewJs } from "../web/components/diff-view.js";
describe("ui code and diff rendering", () => {
it("renders plaintext code immediately", () => {
expect(renderPlainCodeBlock("ts", "const x = 1;")).toContain(
"const x = 1;",
);
expect(renderPlainCodeBlock("ts", "const x = 1;")).toContain(
'data-language="ts"',
);
});
it("keeps Shiki lazy and optional", () => {
expect(renderCodeBlockComponentJs()).toContain("import('shiki')");
expect(renderCodeBlockComponentJs()).toContain("textContent");
});
it("summarizes diffs and emits Pierre lazy loader", () => {
expect(diffSummary("--- a/a.ts\n+++ b/a.ts\n+add\n-del\n context")).toEqual(
{
files: 1,
additions: 1,
deletions: 1,
},
);
expect(renderDiffViewJs()).toContain("import('pierre')");
});
it("coalesces streaming message updates by stream id", () => {
const js = renderAppJs();
expect(js).toContain("event.streamId");
expect(js).toContain("replaceWith(row)");
expect(js).toContain("finalizeStreamingRows()");
});
it("clears empty extension status instead of showing method names", () => {
const js = renderAppJs();
expect(js).toContain("statusItems.delete(String(key))");
expect(js).not.toContain("key + ': ' + 'setStatus'");
});
it("does not locally echo submitted prompts", () => {
const js = renderAppJs();
expect(js).not.toContain(
"Number.MAX_SAFE_INTEGER, at: Date.now(), type: 'message', role: 'user'",
);
});
it("keeps internal runtime chatter out of the main stream", () => {
const js = renderAppJs();
expect(js).toContain("isStreamEvent(event)");
expect(js).toContain("event.type === 'message'");
expect(js).toContain("event.type === 'ui_request'");
expect(js).not.toContain("JSON.stringify(event)");
});
});