import { describe, expect, it } from 'vitest'; import { derivePalette, inputAreaRows, PALETTE_MAX_ROWS } from '../src/commands/palette.js'; describe('derivePalette', () => { it('非斜杠输入不显示面板', () => { expect(derivePalette('hello').paletteVisible).toBe(false); expect(derivePalette(' hello').paletteVisible).toBe(false); }); it('斜杠输入显示面板并按首 token 过滤', () => { const d = derivePalette('/pu'); expect(d.paletteVisible).toBe(true); expect(d.items.map((i) => i.name)).toEqual(['push', 'pull']); }); it('带参数时过滤文本只取第一个 token', () => { const d = derivePalette('/push a b'); expect(d.filterText).toBe('push'); expect(d.hasExactMatch).toBe(true); expect(d.exactAdb?.name).toBe('push'); }); it('内置命令也算精确匹配', () => { expect(derivePalette('/devices').hasExactMatch).toBe(true); }); }); describe('inputAreaRows(帧高度预算,防止整帧超过终端行数)', () => { it('普通输入:输入行 + 常驻提示行 = 2 行', () => { expect(inputAreaRows('')).toBe(2); expect(inputAreaRows('adb push')).toBe(2); }); it('单个 / 显示全部命令:补全上限 + 输入行 + 提示行', () => { expect(inputAreaRows('/')).toBe(PALETTE_MAX_ROWS + 2); }); it('过滤后条目数减少时同步收缩', () => { expect(inputAreaRows('/pu')).toBe(4); // push + pull + 输入行 + 提示行 }); it('精确匹配 adb 命令时增加用法行', () => { expect(inputAreaRows('/push')).toBe(4); // 1 条目 + 用法行 + 输入行 + 提示行 expect(inputAreaRows('/push a b')).toBe(3); // 顶层列表隐藏,仅保留用法行 + 输入行 + 提示行 }); it('无参数命令(root/remount)不增加用法行', () => { expect(inputAreaRows('/root')).toBe(3); // 1 条目 + 输入行 + 提示行 }); it('无匹配命令时显示占位 1 行', () => { expect(inputAreaRows('/zzz')).toBe(3); // 无匹配命令 + 输入行 + 提示行 }); });