|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { createTestUI } from '../../../packages/ui/test/ui.ts'; |
| 3 | +import { createApp } from './app.ts'; |
| 4 | + |
| 5 | +const panel = [ |
| 6 | + '┌──────────────────────┐', |
| 7 | + '│ @clack/ui │', |
| 8 | + '│ │', |
| 9 | + '│ status ● ready │', |
| 10 | + '│ version 0.0.0 │', |
| 11 | + '│ render @bomb.sh/tty │', |
| 12 | + '└──────────────────────┘', |
| 13 | +]; |
| 14 | + |
| 15 | +describe('basic example', () => { |
| 16 | + it('renders the original panel with styled labels and inherited value colors', async () => { |
| 17 | + await using ui = await createTestUI({ cols: 32, rows: 9 }); |
| 18 | + const { document, terminal } = ui; |
| 19 | + document.documentElement!.appendChild(createApp(document)); |
| 20 | + |
| 21 | + await expect |
| 22 | + .poll(() => terminal.screen.getLines().map((line) => line.trimEnd()), { timeout: 2000 }) |
| 23 | + .toEqual([...panel, '', '']); |
| 24 | + |
| 25 | + const runs = [ |
| 26 | + { row: 1, col: 2, content: '@clack/ui', color: { r: 0, g: 255, b: 255 } }, |
| 27 | + { row: 3, col: 2, content: 'status ', color: { r: 128, g: 128, b: 128 } }, |
| 28 | + { row: 3, col: 10, content: '● ready', color: { r: 0, g: 128, b: 0 } }, |
| 29 | + { row: 4, col: 2, content: 'version', color: { r: 128, g: 128, b: 128 } }, |
| 30 | + { row: 4, col: 10, content: '0.0.0', color: { r: 255, g: 255, b: 255 } }, |
| 31 | + { row: 5, col: 2, content: 'render ', color: { r: 128, g: 128, b: 128 } }, |
| 32 | + { row: 5, col: 10, content: '@bomb.sh/tty', color: { r: 255, g: 255, b: 255 } }, |
| 33 | + ]; |
| 34 | + for (const run of runs) { |
| 35 | + for (const [offset, char] of [...run.content].entries()) { |
| 36 | + const cell = terminal.getCell(run.row, run.col + offset); |
| 37 | + expect(cell.char).toBe(char); |
| 38 | + expect(cell.fg).toMatchObject(run.color); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + for (const [row, line] of panel.entries()) { |
| 43 | + for (const [col, char] of [...line].entries()) { |
| 44 | + if ('┌┐└┘─│'.includes(char)) { |
| 45 | + expect(terminal.getCell(row, col).fg).toMatchObject({ r: 0, g: 0, b: 255 }); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + }); |
| 50 | +}); |
0 commit comments