Open History to see the last commit
1import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { requestThreadUnpinConfirmation, ThreadArchiveBlockedError } from "./useThreadActions";
5
6describe("ThreadArchiveBlockedError", () => {
7 it("keeps the blocked thread context with the fixed message", () => {
8 const error = new ThreadArchiveBlockedError({
9 environmentId: EnvironmentId.make("environment-1"),
10 threadId: ThreadId.make("thread-1"),
11 });
12
13 expect(error).toMatchObject({
14 environmentId: "environment-1",
15 threadId: "thread-1",
16 });
17 expect(error.message).toBe("Cannot archive a running thread.");
18 });
19});
20
21describe("requestThreadUnpinConfirmation", () => {
22 it("skips the dialog when confirmation is disabled", async () => {
23 let callCount = 0;
24 const result = await requestThreadUnpinConfirmation({
25 enabled: false,
26 title: "Pinned thread",
27 confirm: async () => {
28 callCount += 1;
29 return false;
30 },
31 });
32
33 expect(result).toMatchObject({ _tag: "Success", value: true });
34 expect(callCount).toBe(0);
35 });
36
37 it("degrades gracefully when dialogs are unavailable", async () => {
38 const result = await requestThreadUnpinConfirmation({
39 enabled: true,
40 title: "Pinned thread",
41 confirm: null,
42 });
43
44 expect(result).toMatchObject({ _tag: "Success", value: true });
45 });
46
47 it("uses the thread title and returns the user's decision", async () => {
48 let message = "";
49 const result = await requestThreadUnpinConfirmation({
50 enabled: true,
51 title: "Release prep",
52 confirm: async (nextMessage) => {
53 message = nextMessage;
54 return false;
55 },
56 });
57
58 expect(message).toBe(
59 'Unpin thread "Release prep"?\nThis will move the thread out of your pinned section.',
60 );
61 expect(result).toMatchObject({ _tag: "Success", value: false });
62 });
63
64 it("keeps dialog failures observable", async () => {
65 const result = await requestThreadUnpinConfirmation({
66 enabled: true,
67 title: "Pinned thread",
68 confirm: () => Promise.reject(new Error("dialog unavailable")),
69 });
70
71 expect(result._tag).toBe("Failure");
72 });
73});