Files
vue-tui/packages/runtime-tests/integration/layout/flex-justify-content.test.tsx
T
Yunfei He 22ecbe0f80 test: port Ink layout tests (157 passing, 21 known failures)
Translates flex, direction, wrap, align, justify, gap, padding,
margin, width-height, position, display, and overflow tests from
Ink. Adds trimLines mode and trailing-newline strip to test helper.
Fixes Box type for alignContent (space-between/around/evenly) and
alignSelf (stretch/baseline).

21 tests fail due to behavioral differences (overflow clipping,
percentage dimensions, relative position offsets, align-content
space-* variants). These represent real gaps to investigate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 21:24:31 +08:00

161 lines
4.7 KiB
TypeScript

import { defineComponent } from "vue";
import { expect, test } from "vite-plus/test";
import { render } from "@vue-tui/testing";
import { Box, Text } from "@vue-tui/runtime";
import chalk from "chalk";
test("row - align text to center", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="row" justifyContent="center" width={10}>
<Text>Test</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe(" Test");
});
test("row - align multiple text nodes to center", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="row" justifyContent="center" width={10}>
<Text>A</Text>
<Text>B</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe(" AB");
});
test("row - align text to right", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="row" justifyContent="flex-end" width={10}>
<Text>Test</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe(" Test");
});
test("row - align multiple text nodes to right", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="row" justifyContent="flex-end" width={10}>
<Text>A</Text>
<Text>B</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe(" AB");
});
test("row - align two text nodes on the edges", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="row" justifyContent="space-between" width={4}>
<Text>A</Text>
<Text>B</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe("A B");
});
test("row - space evenly two text nodes", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="row" justifyContent="space-evenly" width={10}>
<Text>A</Text>
<Text>B</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe(" A B");
});
// Yoga has a bug, where first child in a container with space-around doesn't have
// the correct X coordinate and measure function is used on that child node
test.skip("row - align two text nodes with equal space around them — known Yoga issue", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="row" justifyContent="space-around" width={5}>
<Text>A</Text>
<Text>B</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe(" A B");
});
test("row - align colored text node when text is squashed", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="row" justifyContent="flex-end" width={5}>
<Text color="green">X</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe(` ${chalk.green("X")}`);
});
test("column - align text to center", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="column" justifyContent="center" height={3}>
<Text>Test</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe("\nTest\n");
});
test("column - align text to bottom", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="column" justifyContent="flex-end" height={3}>
<Text>Test</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe("\n\nTest");
});
test("column - align two text nodes on the edges", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="column" justifyContent="space-between" height={4}>
<Text>A</Text>
<Text>B</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe("A\n\n\nB");
});
// Yoga has a bug, where first child in a container with space-around doesn't have
// the correct X coordinate and measure function is used on that child node
test.skip("column - align two text nodes with equal space around them — known Yoga issue", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box flexDirection="column" justifyContent="space-around" height={5}>
<Text>A</Text>
<Text>B</Text>
</Box>
)),
{ columns: 100 },
);
expect(lastFrame({ trimLines: true })).toBe("\nA\n\nB\n");
});