|
|
@@ -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],
|
|
|
+ ])
|
|
|
+})
|