Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: James Long <jlongster@users.noreply.github.com> Co-authored-by: 冯基魁 <56265583+fengjikui@users.noreply.github.com> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com>
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { resolveKeybindOption, upsertCommandRegistration } from "./command"
|
|
|
|
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)
|
|
})
|
|
})
|