Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ChatHeader.test.ts

84 lines2.5 KB

1import { EnvironmentId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { resolveRenameCommit, shouldShowOpenInPicker } from "./ChatHeader";
5​
6describe("shouldShowOpenInPicker", () => {
7 const primaryEnvironmentId = EnvironmentId.make("environment-primary");
8​
9 it("shows the picker for projects in the primary environment", () => {
10 expect(
11 shouldShowOpenInPicker({
12 activeProjectName: "codething-mvp",
13 activeThreadEnvironmentId: primaryEnvironmentId,
14 primaryEnvironmentId,
15 remoteOpenMode: "local-exec",
16 }),
17 ).toBe(true);
18 });
19​
20 it("shows the picker for remote environments in deep-link mode", () => {
21 expect(
22 shouldShowOpenInPicker({
23 activeProjectName: "codething-mvp",
24 activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
25 primaryEnvironmentId,
26 remoteOpenMode: "remote-links",
27 }),
28 ).toBe(true);
29 });
30​
31 it("shows the picker's unavailable state for remote environments without an SSH route", () => {
32 expect(
33 shouldShowOpenInPicker({
34 activeProjectName: "codething-mvp",
35 activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
36 primaryEnvironmentId: null,
37 remoteOpenMode: "remote-unavailable",
38 }),
39 ).toBe(true);
40 });
41​
42 it("hides the picker for non-primary local backends", () => {
43 expect(
44 shouldShowOpenInPicker({
45 activeProjectName: "codething-mvp",
46 activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
47 primaryEnvironmentId,
48 remoteOpenMode: "local-exec",
49 }),
50 ).toBe(false);
51 });
52​
53 it("hides the picker when there is no active project", () => {
54 expect(
55 shouldShowOpenInPicker({
56 activeProjectName: undefined,
57 activeThreadEnvironmentId: primaryEnvironmentId,
58 primaryEnvironmentId,
59 remoteOpenMode: "remote-links",
60 }),
61 ).toBe(false);
62 });
63});
64​
65describe("resolveRenameCommit", () => {
66 it("commits a trimmed changed title", () => {
67 expect(resolveRenameCommit({ title: " New title ", originalTitle: "Old" })).toEqual({
68 action: "commit",
69 title: "New title",
70 });
71 });
72​
73 it("rejects empty and whitespace-only titles", () => {
74 expect(resolveRenameCommit({ title: " ", originalTitle: "Old" })).toEqual({
75 action: "reject-empty",
76 });
77 });
78​
79 it("no-ops when the trimmed title is unchanged", () => {
80 expect(resolveRenameCommit({ title: " Old ", originalTitle: "Old" })).toEqual({
81 action: "noop",
82 });
83 });
84});