|
| 1 | +import { useStdout } from 'ink'; |
1 | 2 | import { render } from 'ink-testing-library'; |
2 | 3 |
|
3 | 4 | import { UI } from '../../constants'; |
4 | 5 | import { Markdown } from './Markdown'; |
5 | 6 |
|
| 7 | +const { mockColumns } = vi.hoisted(() => ({ |
| 8 | + mockColumns: { |
| 9 | + value: 100, |
| 10 | + }, |
| 11 | +})); |
| 12 | + |
| 13 | +vi.mock('ink', async () => ({ |
| 14 | + ...(await vi.importActual('ink')), |
| 15 | + useStdout: vi.fn(() => ({ |
| 16 | + stdout: { |
| 17 | + columns: mockColumns.value, |
| 18 | + }, |
| 19 | + })), |
| 20 | +})); |
| 21 | + |
| 22 | +function setTerminalWidth(columns: number) { |
| 23 | + mockColumns.value = columns; |
| 24 | +} |
| 25 | + |
| 26 | +function stripAnsi(value: string | undefined) { |
| 27 | + return value?.replaceAll(new RegExp(String.raw`\u001B\[[0-9;]*m`, 'g'), ''); |
| 28 | +} |
| 29 | + |
6 | 30 | describe('Markdown', () => { |
| 31 | + beforeEach(() => { |
| 32 | + setTerminalWidth(100); |
| 33 | + vi.mocked(useStdout).mockClear(); |
| 34 | + }); |
| 35 | + |
7 | 36 | it('renders markdown content', () => { |
8 | 37 | const { lastFrame } = render(<Markdown content="# Hello" />); |
9 | 38 | expect(lastFrame()).toContain('Hello'); |
@@ -79,4 +108,18 @@ describe('Markdown', () => { |
79 | 108 | const { lastFrame } = render(<Markdown content="$dx \\, dt$" />); |
80 | 109 | expect(lastFrame()).not.toContain('\\,'); |
81 | 110 | }); |
| 111 | + |
| 112 | + it('reflows wrapped markdown lists before Ink wraps ANSI output', () => { |
| 113 | + setTerminalWidth(40); |
| 114 | + |
| 115 | + const content = |
| 116 | + '4. **Restructure the "Usage" section** to clearly separate **Interactive TUI** from **CLI Commands**.'; |
| 117 | + |
| 118 | + const { lastFrame } = render(<Markdown content={content} />); |
| 119 | + const frame = stripAnsi(lastFrame()) ?? ''; |
| 120 | + |
| 121 | + expect(frame).toContain('CLI'); |
| 122 | + expect(frame).toContain('Commands'); |
| 123 | + expect(frame).not.toContain('**'); |
| 124 | + }); |
82 | 125 | }); |
0 commit comments