| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { resolveAnnotationSubmission } from "./AnnotationKeyboard.ts"; |
| 4 | |
| 5 | const 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 | |
| 16 | describe("resolveAnnotationSubmission", () => { |
| 17 | it("attaches on Enter and sends on Cmd/Ctrl+Enter", () => { |
| 18 | expect(resolveAnnotationSubmission(keyboardEvent(), true)).toBe("attach"); |
| 19 | expect(resolveAnnotationSubmission(keyboardEvent({ metaKey: true }), true)).toBe("send"); |
| 20 | expect(resolveAnnotationSubmission(keyboardEvent({ ctrlKey: true }), true)).toBe("send"); |
| 21 | }); |
| 22 | |
| 23 | it("leaves Shift+Enter and composition events available for editing", () => { |
| 24 | expect(resolveAnnotationSubmission(keyboardEvent({ shiftKey: true }), true)).toBeNull(); |
| 25 | expect(resolveAnnotationSubmission(keyboardEvent({ isComposing: true }), true)).toBeNull(); |
| 26 | expect(resolveAnnotationSubmission(keyboardEvent({ key: " " }), true)).toBeNull(); |
| 27 | }); |
| 28 | |
| 29 | it("keeps attach available while the send shortcut follows permission changes", () => { |
| 30 | const send = keyboardEvent({ ctrlKey: true }); |
| 31 | expect(resolveAnnotationSubmission(send, false)).toBeNull(); |
| 32 | expect(resolveAnnotationSubmission(keyboardEvent(), false)).toBe("attach"); |
| 33 | expect(resolveAnnotationSubmission(send, true)).toBe("send"); |
| 34 | expect(resolveAnnotationSubmission(send, false)).toBeNull(); |
| 35 | expect(resolveAnnotationSubmission(keyboardEvent({ metaKey: true }), false)).toBeNull(); |
| 36 | }); |
| 37 | }); |