ktx/packages/cli/test/setup-banner.test.ts
Andrey Avtomonov 28953eb616
feat(cli): add ktx wordmark banner to setup intro (#290)
Render a lowercase ktx half-block wordmark with the brand-orange gradient
above the `ktx setup` intro on interactive TTYs. The banner degrades
through truecolor, xterm-256, and monochrome, and is skipped on non-TTY,
non-Unicode, or too-narrow terminals.

Extract shared color/Unicode capability detection into io helpers
(shouldUseColorOutput, colorDepthForOutput, unicodeSupported) so the
banner and doctor report route through one implementation.
2026-06-10 14:47:34 +00:00

54 lines
1.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { renderKtxSetupBanner } from '../src/setup-banner.js';
const WIDE = { columns: 120, colorDepth: 1, unicode: true };
describe('renderKtxSetupBanner', () => {
it('renders the wordmark and tagline without ANSI codes when color is off', () => {
const banner = renderKtxSetupBanner(WIDE);
expect(banner).toContain('██');
expect(banner).toContain('context layer for data agents');
expect(banner).not.toContain('\u001b[');
expect(banner.endsWith('\n\n')).toBe(true);
});
it('fits within the reported terminal width', () => {
const banner = renderKtxSetupBanner({ ...WIDE, columns: 40 });
for (const line of banner.split('\n')) {
expect(line.length).toBeLessThanOrEqual(40);
}
expect(banner).not.toBe('');
});
it('uses truecolor gradient codes at 24-bit depth', () => {
const banner = renderKtxSetupBanner({ ...WIDE, colorDepth: 24 });
expect(banner).toContain('\u001b[38;2;249;115;22m');
expect(banner).toContain('\u001b[2mcontext layer for data agents\u001b[22m');
});
it('falls back to xterm-256 codes at 8-bit depth', () => {
const banner = renderKtxSetupBanner({ ...WIDE, colorDepth: 8 });
expect(banner).toContain('\u001b[38;5;208m');
expect(banner).not.toContain('\u001b[38;2;');
});
it('renders monochrome art at 16-color depth', () => {
const banner = renderKtxSetupBanner({ ...WIDE, colorDepth: 4 });
expect(banner).toContain('██');
expect(banner).not.toContain('\u001b[38;');
});
it('returns an empty string when the terminal is too narrow', () => {
expect(renderKtxSetupBanner({ ...WIDE, columns: 24 })).toBe('');
});
it('returns an empty string without Unicode support', () => {
expect(renderKtxSetupBanner({ ...WIDE, unicode: false })).toBe('');
});
});