mirror of
https://github.com/hanzoai/dev-desktop.git
synced 2026-11-22 00:14:30 +00:00
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import { expect } from "e2e";
|
|
import * as Effect from "effect/Effect";
|
|
import * as FileSystem from "effect/FileSystem";
|
|
import * as Path from "effect/Path";
|
|
|
|
import { HANZO_HOME } from "../e2e.config.ts";
|
|
import { runPromise, test, WEB } from "./hanzo.ts";
|
|
|
|
// A saved rule that binds Enter to the command palette only while the right panel is closed.
|
|
const panelConditionedEnter = Effect.gen(function* () {
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const keybindingsPath = (yield* Path.Path).join(HANZO_HOME, "userdata/keybindings.json");
|
|
const original = (yield* fs.exists(keybindingsPath))
|
|
? yield* fs.readFileString(keybindingsPath)
|
|
: null;
|
|
return {
|
|
save: fs.writeFileString(
|
|
keybindingsPath,
|
|
'[{ "key": "enter", "command": "commandPalette.toggle", "when": "!rightPanelOpen" }]\n',
|
|
),
|
|
restore:
|
|
original === null
|
|
? fs.remove(keybindingsPath, { force: true })
|
|
: fs.writeFileString(keybindingsPath, original),
|
|
};
|
|
});
|
|
|
|
test(
|
|
"Enter sends from the composer while the right panel is open and a rule binds it when closed",
|
|
WEB,
|
|
async ({ hanzo, app, screen }) => {
|
|
const keybindings = await runPromise(panelConditionedEnter);
|
|
try {
|
|
await runPromise(keybindings.save);
|
|
const project = await hanzo.project("demo");
|
|
const thread = await hanzo.thread({ project, title: "Panel work", messages: ["Start"] });
|
|
|
|
// The settings list shows the rule once the server has loaded the saved file.
|
|
await hanzo.open("/settings/keybindings");
|
|
await screen
|
|
.getByRole("button", "Edit shortcut for Command Palette: Toggle: Enter")
|
|
.waitFor();
|
|
|
|
await hanzo.open(thread);
|
|
await screen.getByRole("button", "Toggle right panel").tap();
|
|
await screen.getByRole("button", { name: "Toggle right panel", pressed: true }).waitFor();
|
|
|
|
const composer = screen.getByTestId("composer-editor");
|
|
await composer.tap();
|
|
await composer.pressSequentially("Hello with the panel open");
|
|
await composer.press("Enter");
|
|
await app.screenshot("after-enter");
|
|
await expect(composer).toHaveText("");
|
|
await expect(screen.getByText("Hello with the panel open")).toBeVisible();
|
|
} finally {
|
|
await runPromise(keybindings.restore);
|
|
}
|
|
},
|
|
);
|