-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathChatView.logic.test.ts
More file actions
141 lines (127 loc) · 4.07 KB
/
Copy pathChatView.logic.test.ts
File metadata and controls
141 lines (127 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { ProjectId, ThreadId } from "@okcode/contracts";
import { describe, expect, it } from "vitest";
import {
buildAutoSelectedWorktreeBaseBranchToastCopy,
buildLocalDraftThread,
buildExpiredTerminalContextToastCopy,
deriveComposerSendState,
} from "./ChatView.logic";
describe("deriveComposerSendState", () => {
it("treats expired terminal pills as non-sendable content", () => {
const state = deriveComposerSendState({
prompt: "\uFFFC",
attachmentCount: 0,
terminalContexts: [
{
id: "ctx-expired",
threadId: ThreadId.makeUnsafe("thread-1"),
terminalId: "default",
terminalLabel: "Terminal 1",
lineStart: 4,
lineEnd: 4,
text: "",
createdAt: "2026-03-17T12:52:29.000Z",
},
],
});
expect(state.trimmedPrompt).toBe("");
expect(state.sendableTerminalContexts).toEqual([]);
expect(state.expiredTerminalContextCount).toBe(1);
expect(state.hasSendableContent).toBe(false);
});
it("keeps text sendable while excluding expired terminal pills", () => {
const state = deriveComposerSendState({
prompt: `yoo \uFFFC waddup`,
attachmentCount: 0,
terminalContexts: [
{
id: "ctx-expired",
threadId: ThreadId.makeUnsafe("thread-1"),
terminalId: "default",
terminalLabel: "Terminal 1",
lineStart: 4,
lineEnd: 4,
text: "",
createdAt: "2026-03-17T12:52:29.000Z",
},
],
});
expect(state.trimmedPrompt).toBe("yoo waddup");
expect(state.expiredTerminalContextCount).toBe(1);
expect(state.hasSendableContent).toBe(true);
});
it("treats file attachments as sendable content", () => {
const state = deriveComposerSendState({
prompt: "",
attachmentCount: 1,
terminalContexts: [],
});
expect(state.hasSendableContent).toBe(true);
});
});
describe("buildExpiredTerminalContextToastCopy", () => {
it("formats clear empty-state guidance", () => {
expect(buildExpiredTerminalContextToastCopy(1, "empty")).toEqual({
title: "Expired terminal context won't be sent",
description: "Remove it or re-add it to include terminal output.",
});
});
it("formats omission guidance for sent messages", () => {
expect(buildExpiredTerminalContextToastCopy(2, "omitted")).toEqual({
title: "Expired terminal contexts omitted from message",
description: "Re-add it if you want that terminal output included.",
});
});
});
describe("buildAutoSelectedWorktreeBaseBranchToastCopy", () => {
it("explains the branch fallback clearly", () => {
expect(
buildAutoSelectedWorktreeBaseBranchToastCopy({
requestedBranch: "main",
selectedBranch: "master",
}),
).toEqual({
title: "Using master instead of main",
description:
"The requested base branch main was unavailable, so OK Code created this worktree from master.",
});
});
});
describe("buildLocalDraftThread", () => {
it("uses a persisted draft title when present", () => {
const thread = buildLocalDraftThread(
ThreadId.makeUnsafe("thread-draft"),
{
projectId: ProjectId.makeUnsafe("project-1"),
createdAt: "2026-03-17T12:52:29.000Z",
title: "Investigate flaky CI",
runtimeMode: "full-access",
interactionMode: "chat",
branch: null,
worktreePath: null,
envMode: "local",
},
"gpt-5.4",
null,
);
expect(thread.title).toBe("Investigate flaky CI");
});
it("falls back to the default title when the draft title is empty", () => {
const thread = buildLocalDraftThread(
ThreadId.makeUnsafe("thread-draft-empty"),
{
projectId: ProjectId.makeUnsafe("project-1"),
createdAt: "2026-03-17T12:52:29.000Z",
title: " ",
runtimeMode: "full-access",
interactionMode: "chat",
branch: null,
worktreePath: null,
envMode: "local",
},
"gpt-5.4",
null,
);
expect(thread.title).toBe("New thread");
});
});