fix(simulation): normalize named key presses (#37523)
This commit is contained in:
parent
677526d72e
commit
3fc06accbd
2 changed files with 49 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { expect, test } from "bun:test"
|
||||
import { matches } from "../src/frontend/actions"
|
||||
import { Effect } from "effect"
|
||||
import { execute, type Harness, matches } from "../src/frontend/actions"
|
||||
|
||||
test("matches literal screen text", () => {
|
||||
const harness = { screen: () => "OpenCode [ready].*" }
|
||||
|
|
@ -9,3 +10,32 @@ test("matches literal screen text", () => {
|
|||
expect(matches(harness, "OpenCode.*ready")).toBe(false)
|
||||
expect(matches(harness, "opencode")).toBe(false)
|
||||
})
|
||||
|
||||
test("normalizes named keys for OpenTUI", async () => {
|
||||
const pressed: Array<readonly [string, object | undefined]> = []
|
||||
const harness = {
|
||||
renderer: {
|
||||
root: { getChildren: () => [] },
|
||||
currentFocusedRenderable: undefined,
|
||||
currentFocusedEditor: undefined,
|
||||
},
|
||||
mockInput: {
|
||||
pressKey: (key: string, modifiers?: object) => pressed.push([key, modifiers]),
|
||||
},
|
||||
renderOnce: async () => {},
|
||||
} as unknown as Harness
|
||||
|
||||
await Effect.runPromise(
|
||||
execute(harness, {
|
||||
type: "ui.press",
|
||||
key: "escape",
|
||||
modifiers: { ctrl: true },
|
||||
}),
|
||||
)
|
||||
await Effect.runPromise(execute(harness, { type: "ui.press", key: "x" }))
|
||||
|
||||
expect(pressed).toEqual([
|
||||
["ESCAPE", { ctrl: true }],
|
||||
["x", undefined],
|
||||
])
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue