import { describe, expect, test } from 'claude-code/testing' import { bandLines, fit, lineWidth } from '../hud/format' import type { HudData } from '../hud/format' import { fitCompanion } from './band' import type { View } from './core' const DATA: HudData = { model: 'claude-opus-5-5[1m]', cwd: '/home/dev/work/luopan', home: '/home/dev', git: { branch: 'issue-3', dirty: 1, ahead: 0, behind: 0 }, usage: { fiveHour: { percent: 42 }, sevenDay: { percent: 71 }, ctxPercent: 31 }, sys: { cpu: 23 }, tzOffsetMin: 480, } const VIEW: View = { core: { id: 'miko', name: '月見ミコ', facts: {} as never, neuroticism: 50, baseline: { p: 0, a: 0, d: 0 } }, mood: { p: 0.5, a: 0, d: -0.5 }, label: '放鬆', kaomoji: '(´ᴗ`)', affinity: 0.35, stage: '熟悉', todos: 2, } const text = (v: View, cols: number, compact = false, bubble?: string) => fitCompanion(v, cols, compact, bubble).map(s => s.text).join('') describe('角色行', () => { test('寬版顯示顏文字、名字、心情、PAD 條、階段、待辦、氣泡', () => { expect(text(VIEW, 200, false, '早安')).toBe('(´ᴗ`) 月見ミコ 放鬆 · P▰▰▱ A▰▰▱ D▰▱▱ · 熟悉 · ☐2 · 💬 早安') }) test('緊湊模式只剩「顏文字 名字 心情」', () => { expect(text(VIEW, 200, true)).toBe('(´ᴗ`) 月見ミコ 放鬆') }) test('寬度不足時依序捨棄氣泡、待辦、PAD、階段,不換行', () => { const full = text(VIEW, 200, false, '早安') let prev = full.length for (const cols of [60, 50, 40, 34, 28, 22]) { const t = text(VIEW, cols, false, '早安') expect(t.includes('\n')).toBe(false) expect(t.length <= prev).toBe(true) prev = t.length } expect(text(VIEW, 40, false, '早安')).not.toContain('早安') expect(text(VIEW, 36, false, '早安')).not.toContain('☐') expect(text(VIEW, 30, false, '早安')).not.toContain('PAD') expect(text(VIEW, 22, false, '早安')).toBe('(´ᴗ`) 月見ミコ 放鬆') expect(lineWidth(fitCompanion(VIEW, 24))).toBeLessThanOrEqual(24) }) test('沒有待辦時不顯示待辦數', () => { expect(text({ ...VIEW, todos: 0 }, 200)).not.toContain('☐') }) }) describe('band', () => { test('沒有角色時只有第一行,且與現況逐字相同', () => { for (const cols of [200, 100, 60]) { const lines = bandLines(DATA, cols, false, null) expect(lines.length).toBe(1) expect(lines[0]).toEqual(fit(DATA, cols, false)) } }) test('有角色時第一行不變,第二行是角色行', () => { const lines = bandLines(DATA, 120, false, fitCompanion(VIEW, 120)) expect(lines.length).toBe(2) expect(lines[0]).toEqual(fit(DATA, 120, false)) }) })