@@ -1,4 +1,5 @@
11 import { describe, expect, test } from "bun:test";
2+import { measureContentHeight } from "./index.js";
23 import { layout, type LayoutNode, type Rect } from "./layout.js";
34 import { VStack, HStack } from "./primitives/stacks.js";
45 import { Text } from "./primitives/text.js";
@@ -1247,4 +1248,89 @@ describe("layout", () => {
12471248 expect(result.children[1]!.rect.y).toBe(3);
12481249 });
12491250 });
1251+
1252+ describe("measureContentHeight", () => {
1253+ test("wrapped Text returns the visual line count for the provided width", () => {
1254+ // Arrange
1255+ const node = Text("foo bar baz", { wrap: "word" });
1256+
1257+ // Act
1258+ const height = measureContentHeight(node, { width: 6 });
1259+
1260+ // Assert
1261+ expect(height).toBe(3);
1262+ });
1263+
1264+ test("padded VStack accounts for its own padding when measuring children", () => {
1265+ // Arrange
1266+ const node = VStack({ padding: { x: 1, y: 1 }, gap: 1 }, [
1267+ Text("foo bar", { wrap: "word" }),
1268+ Text("baz"),
1269+ ]);
1270+
1271+ // Act
1272+ const height = measureContentHeight(node, { width: 8 });
1273+
1274+ // Assert
1275+ expect(height).toBe(6);
1276+ });
1277+
1278+ test("wrapping HStack returns the sum of row heights plus row gaps", () => {
1279+ // Arrange
1280+ const node = HStack({ flexWrap: "wrap", gap: 1 }, [
1281+ VStack({ width: 5, height: 2 }, []),
1282+ VStack({ width: 5, height: 3 }, []),
1283+ VStack({ width: 5, height: 4 }, []),
1284+ ]);
1285+
1286+ // Act
1287+ const height = measureContentHeight(node, { width: 11 });
1288+
1289+ // Assert
1290+ expect(height).toBe(8);
1291+ });
1292+
1293+ test("TextInput returns wrapped content height including its own padding", () => {
1294+ // Arrange
1295+ const node = TextInput({
1296+ padding: { x: 1, y: 1 },
1297+ value: "foo bar baz",
1298+ onChange: () => {},
1299+ });
1300+
1301+ // Act
1302+ const height = measureContentHeight(node, { width: 8 });
1303+
1304+ // Assert
1305+ expect(height).toBe(5);
1306+ });
1307+
1308+ test("explicit root height does not limit the measured content height", () => {
1309+ // Arrange
1310+ const node = VStack({ height: 1 }, [
1311+ Text("line 1"),
1312+ Text("line 2"),
1313+ Text("line 3"),
1314+ ]);
1315+
1316+ // Act
1317+ const height = measureContentHeight(node, { width: 10 });
1318+
1319+ // Assert
1320+ expect(height).toBe(3);
1321+ });
1322+
1323+ test("caller-provided width overrides the measured root width prop", () => {
1324+ // Arrange
1325+ const node = VStack({ width: 10 }, [
1326+ Text("foo bar baz", { wrap: "word" }),
1327+ ]);
1328+
1329+ // Act
1330+ const height = measureContentHeight(node, { width: 100 });
1331+
1332+ // Assert
1333+ expect(height).toBe(1);
1334+ });
1335+ });
12501336 });