|
| 1 | +import { describe, expect, it, vi } from "vite-plus/test"; |
| 2 | + |
| 3 | +import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 4 | + |
| 5 | +import { claimSettleThreadShortcut } from "./settleThreadShortcut"; |
| 6 | + |
| 7 | +const routeThreadRef = { |
| 8 | + environmentId: EnvironmentId.make("environment-id"), |
| 9 | + threadId: ThreadId.make("thread-id"), |
| 10 | +}; |
| 11 | + |
| 12 | +function shortcutEvent(repeat = false) { |
| 13 | + return { |
| 14 | + repeat, |
| 15 | + preventDefault: vi.fn(), |
| 16 | + stopPropagation: vi.fn(), |
| 17 | + }; |
| 18 | +} |
| 19 | + |
| 20 | +describe("settle thread shortcut", () => { |
| 21 | + it("claims the shortcut when there is no route thread", () => { |
| 22 | + const event = shortcutEvent(); |
| 23 | + |
| 24 | + expect(claimSettleThreadShortcut(event, null)).toBeNull(); |
| 25 | + expect(event.preventDefault).toHaveBeenCalledOnce(); |
| 26 | + expect(event.stopPropagation).toHaveBeenCalledOnce(); |
| 27 | + }); |
| 28 | + |
| 29 | + it("returns the route thread for a non-repeated shortcut", () => { |
| 30 | + const event = shortcutEvent(); |
| 31 | + |
| 32 | + expect(claimSettleThreadShortcut(event, routeThreadRef)).toBe(routeThreadRef); |
| 33 | + expect(event.preventDefault).toHaveBeenCalledOnce(); |
| 34 | + expect(event.stopPropagation).toHaveBeenCalledOnce(); |
| 35 | + }); |
| 36 | + |
| 37 | + it("claims repeated shortcuts without returning the route thread", () => { |
| 38 | + const event = shortcutEvent(true); |
| 39 | + |
| 40 | + expect(claimSettleThreadShortcut(event, routeThreadRef)).toBeNull(); |
| 41 | + expect(event.preventDefault).toHaveBeenCalledOnce(); |
| 42 | + expect(event.stopPropagation).toHaveBeenCalledOnce(); |
| 43 | + }); |
| 44 | +}); |
0 commit comments