Skip to content

Commit c3b65fc

Browse files
committed
test(core): use testRenderer harness for newline wrap regressions
1 parent afd1449 commit c3b65fc

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

packages/core/src/renderer/__tests__/renderer.text.test.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {
1111
parseCommandHeaders,
1212
parseInternedStrings,
1313
} from "../../__tests__/drawlistDecode.js";
14-
import { type VNode, createDrawlistBuilder } from "../../index.js";
14+
import { type VNode, createDrawlistBuilder, ui } from "../../index.js";
1515
import { layout } from "../../layout/layout.js";
1616
import { commitVNodeTree } from "../../runtime/commit.js";
1717
import { createInstanceIdAllocator } from "../../runtime/instance.js";
18+
import { createTestRenderer } from "../../testing/renderer.js";
1819
import { renderToDrawlist } from "../renderToDrawlist.js";
1920

2021
const decoder = new TextDecoder();
@@ -296,41 +297,44 @@ function expectBlob(frame: ParsedFrame, blobIndex: number): TextRunBlob {
296297
return blob;
297298
}
298299

299-
function drawTextsByY(frame: ParsedFrame): readonly DrawTextCommand[] {
300-
return Object.freeze([...frame.drawTexts].sort((a, b) => a.y - b.y || a.x - b.x));
301-
}
302-
303300
describe("renderer text - wrap newline handling", () => {
304301
test("wrap=true renders explicit newline lines on separate rows", () => {
305-
const frame = parseFrame(
306-
renderBytes(textVNode("First line\nSecond line", { wrap: true }), { cols: 20, rows: 4 }),
302+
const renderer = createTestRenderer({ viewport: { cols: 20, rows: 4 } });
303+
const frame = renderer.render(
304+
ui.text("First line\nSecond line", {
305+
id: "wrapped",
306+
wrap: true,
307+
}),
307308
);
308-
const draws = drawTextsByY(frame).filter((cmd) => cmd.text.length > 0);
309+
const lines = frame.toText().split("\n");
309310

310-
assert.equal(draws.length, 2);
311-
const first = draws[0];
312-
const second = draws[1];
313-
assert.ok(first !== undefined);
314-
assert.ok(second !== undefined);
315-
assert.equal(first.y, 0);
316-
assert.equal(first.text, "First line");
317-
assert.equal(second.y, 1);
318-
assert.equal(second.text, "Second line");
311+
assert.equal(lines[0]?.includes("First line"), true);
312+
assert.equal(lines[1]?.includes("Second line"), true);
313+
314+
const wrapped = frame.findById("wrapped");
315+
assert.notEqual(wrapped, null);
316+
assert.equal(wrapped?.rect.y, 0);
317+
assert.ok((wrapped?.rect.h ?? 0) >= 2);
319318
});
320319

321320
test("wrap=true preserves blank lines from double newlines", () => {
322-
const frame = parseFrame(renderBytes(textVNode("Alpha\n\nOmega", { wrap: true }), { cols: 20, rows: 6 }));
323-
const draws = drawTextsByY(frame).filter((cmd) => cmd.text.length > 0);
321+
const renderer = createTestRenderer({ viewport: { cols: 20, rows: 6 } });
322+
const frame = renderer.render(
323+
ui.text("Alpha\n\nOmega", {
324+
id: "wrapped-blank",
325+
wrap: true,
326+
}),
327+
);
328+
const lines = frame.toText().split("\n");
324329

325-
assert.equal(draws.length, 2);
326-
const first = draws[0];
327-
const second = draws[1];
328-
assert.ok(first !== undefined);
329-
assert.ok(second !== undefined);
330-
assert.equal(first.y, 0);
331-
assert.equal(first.text, "Alpha");
332-
assert.equal(second.y, 2);
333-
assert.equal(second.text, "Omega");
330+
assert.equal(lines[0]?.includes("Alpha"), true);
331+
assert.equal((lines[1] ?? "").trim(), "");
332+
assert.equal(lines[2]?.includes("Omega"), true);
333+
334+
const wrapped = frame.findById("wrapped-blank");
335+
assert.notEqual(wrapped, null);
336+
assert.equal(wrapped?.rect.y, 0);
337+
assert.ok((wrapped?.rect.h ?? 0) >= 3);
334338
});
335339
});
336340

0 commit comments

Comments
 (0)