Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AnnotationKeyboard.test.ts

28 lines1.0 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { resolveAnnotationSubmission } from "./AnnotationKeyboard.ts";
4​
5const keyboardEvent = (
6 overrides: Partial<Parameters<typeof resolveAnnotationSubmission>[0]> = {},
7) => ({
8 key: "Enter",
9 metaKey: false,
10 ctrlKey: false,
11 shiftKey: false,
12 isComposing: false,
13 ...overrides,
14});
15​
16describe("resolveAnnotationSubmission", () => {
17 it("attaches on Enter and sends on Cmd/Ctrl+Enter", () => {
18 expect(resolveAnnotationSubmission(keyboardEvent())).toBe("attach");
19 expect(resolveAnnotationSubmission(keyboardEvent({ metaKey: true }))).toBe("send");
20 expect(resolveAnnotationSubmission(keyboardEvent({ ctrlKey: true }))).toBe("send");
21 });
22​
23 it("leaves Shift+Enter and composition events available for editing", () => {
24 expect(resolveAnnotationSubmission(keyboardEvent({ shiftKey: true }))).toBeNull();
25 expect(resolveAnnotationSubmission(keyboardEvent({ isComposing: true }))).toBeNull();
26 expect(resolveAnnotationSubmission(keyboardEvent({ key: " " }))).toBeNull();
27 });
28});