/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/app/src/context/command.test.ts
55 строк
2 KB
Aarav Sareen
feat(app): cmd+k menu shows sessions on home page (#36686)
16 июл 2026, 12:51
Не верифицирован
16 июл 2026, 12:51
958e08e
Код
Авторство
О чём код?
import { describe, expect, test } from "bun:test" import { commandPaletteOptions, resolveKeybindOption, upsertCommandRegistration, type CommandOption } from "./command" const paletteOptions: CommandOption[] = [ { id: "settings.open", title: "Open settings" }, { id: "session.undo", title: "Undo" }, { id: "file.open", title: "Open file" }, { id: "hidden", title: "Hidden", hidden: true }, { id: "disabled", title: "Disabled", disabled: true }, ] describe("commandPaletteOptions", () => { test("keeps visible enabled commands", () => { expect(commandPaletteOptions(paletteOptions).map((option) => option.id)).toEqual(["settings.open", "session.undo"]) }) }) describe("upsertCommandRegistration", () => { test("replaces keyed registrations", () => { const one = () => [{ id: "one", title: "One" }] const two = () => [{ id: "two", title: "Two" }] const next = upsertCommandRegistration([{ key: "layout", options: one }], { key: "layout", options: two }) expect(next).toHaveLength(1) expect(next[0]?.options).toBe(two) }) test("keeps unkeyed registrations additive", () => { const one = () => [{ id: "one", title: "One" }] const two = () => [{ id: "two", title: "Two" }] const next = upsertCommandRegistration([{ options: one }], { options: two }) expect(next).toHaveLength(2) expect(next[0]?.options).toBe(two) expect(next[1]?.options).toBe(one) }) }) describe("resolveKeybindOption", () => { test("prefers a matching contextual command over the global fallback", () => { const fallback = { id: "tab.close", title: "Close tab" } const contextual = { id: "terminal.close", title: "Close terminal", when: () => true } expect(resolveKeybindOption([fallback, contextual], new KeyboardEvent("keydown"))).toBe(contextual) }) test("uses the global fallback outside the command context", () => { const fallback = { id: "tab.close", title: "Close tab" } const contextual = { id: "terminal.close", title: "Close terminal", when: () => false } expect(resolveKeybindOption([fallback, contextual], new KeyboardEvent("keydown"))).toBe(fallback) }) })