Open History to see the last commit
1import { describe, expect, it, vi } from "vite-plus/test";
2
3vi.mock("expo-haptics", () => ({ selectionAsync: vi.fn() }));
4vi.mock("../../state/threads", () => ({ environmentThreadDetails: {} }));
5
6import { shouldTickStreamHaptic } from "./threadStreamHaptics";
7
8const mark = (id: string, textLength: number) => ({ id, textLength });
9
10describe("shouldTickStreamHaptic", () => {
11 it("ticks for a new stream even inside the throttle window", () => {
12 expect(
13 shouldTickStreamHaptic({
14 previous: mark("a", 40),
15 latest: mark("b", 1),
16 lastTickAt: 0,
17 now: 10,
18 }),
19 ).toBe(true);
20 expect(
21 shouldTickStreamHaptic({ previous: null, latest: mark("a", 1), lastTickAt: 0, now: 10 }),
22 ).toBe(true);
23 });
24
25 it("throttles growth of the same stream", () => {
26 const growth = { previous: mark("a", 10), latest: mark("a", 20), lastTickAt: 1_000 };
27 expect(shouldTickStreamHaptic({ ...growth, now: 1_200 })).toBe(false);
28 expect(shouldTickStreamHaptic({ ...growth, now: 1_320 })).toBe(true);
29 });
30
31 it("stays quiet when nothing streams or the text did not grow", () => {
32 expect(
33 shouldTickStreamHaptic({ previous: mark("a", 10), latest: null, lastTickAt: 0, now: 5_000 }),
34 ).toBe(false);
35 expect(
36 shouldTickStreamHaptic({
37 previous: mark("a", 10),
38 latest: mark("a", 10),
39 lastTickAt: 0,
40 now: 5_000,
41 }),
42 ).toBe(false);
43 });
44});