- TypeScript + Vite (vite-plugin-monkey) userscript - Groq API integration with whisper-large-v3 - Tap-to-toggle recording with noise suppression - Contenteditable text insertion for OpenCode web - Ctrl+Space keyboard shortcut (desktop) - Custom Whisper prompt for software development context - Recording timer, toast notifications, auto-submit option - 44 unit tests, 100% line coverage - Biome linter, Knip, Vitest, CI/CD pipeline - Bilingual README (EN/RU) with compatibility table
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import { afterEach, describe, expect, it } from "vitest";
|
|
import { setupKeyboardShortcut } from "../src/keyboard.js";
|
|
|
|
describe("setupKeyboardShortcut", () => {
|
|
let cleanup: (() => void) | null = null;
|
|
|
|
afterEach(() => {
|
|
if (cleanup) {
|
|
cleanup();
|
|
cleanup = null;
|
|
}
|
|
});
|
|
|
|
it("should call callback on ctrl+space", () => {
|
|
let called = false;
|
|
cleanup = setupKeyboardShortcut(() => {
|
|
called = true;
|
|
});
|
|
|
|
document.dispatchEvent(new KeyboardEvent("keydown", { key: " ", ctrlKey: true }));
|
|
|
|
expect(called).toBe(true);
|
|
});
|
|
|
|
it("should not call callback on space without ctrl", () => {
|
|
let called = false;
|
|
cleanup = setupKeyboardShortcut(() => {
|
|
called = true;
|
|
});
|
|
|
|
document.dispatchEvent(new KeyboardEvent("keydown", { key: " " }));
|
|
|
|
expect(called).toBe(false);
|
|
});
|
|
|
|
it("should not call callback on ctrl+other key", () => {
|
|
let called = false;
|
|
cleanup = setupKeyboardShortcut(() => {
|
|
called = true;
|
|
});
|
|
|
|
document.dispatchEvent(new KeyboardEvent("keydown", { key: "a", ctrlKey: true }));
|
|
|
|
expect(called).toBe(false);
|
|
});
|
|
|
|
it("should cleanup listener on dispose", () => {
|
|
let called = false;
|
|
const dispose = setupKeyboardShortcut(() => {
|
|
called = true;
|
|
});
|
|
|
|
dispose();
|
|
|
|
document.dispatchEvent(new KeyboardEvent("keydown", { key: " ", ctrlKey: true }));
|
|
|
|
expect(called).toBe(false);
|
|
});
|
|
|
|
it("should prevent default on match", () => {
|
|
let prevented = false;
|
|
cleanup = setupKeyboardShortcut(() => {});
|
|
|
|
const event = new KeyboardEvent("keydown", {
|
|
key: " ",
|
|
ctrlKey: true,
|
|
cancelable: true,
|
|
});
|
|
event.preventDefault = () => {
|
|
prevented = true;
|
|
};
|
|
|
|
document.dispatchEvent(event);
|
|
expect(prevented).toBe(true);
|
|
});
|
|
});
|