@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 123 lines 3.8 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2 import type { DesktopUpdateState } from "@t3tools/contracts";
3
4 import {
5 canCheckForUpdate,
6 getDesktopUpdateButtonTooltip,
7 getDesktopUpdateReleaseHistoryUrl,
8 getDesktopUpdateReleaseUrl,
9 resolveDesktopUpdateButtonAction,
10 } from "./desktopUpdate.logic";
11
12 const baseState: DesktopUpdateState = {
13 enabled: true,
14 status: "idle",
15 channel: "latest",
16 currentVersion: "1.0.0",
17 hostArch: "x64",
18 appArch: "x64",
19 runningUnderArm64Translation: false,
20 availableVersion: null,
21 downloadedVersion: null,
22 releaseNotes: [],
23 omittedReleaseCount: 0,
24 downloadPercent: null,
25 checkedAt: null,
26 message: null,
27 errorContext: null,
28 canRetry: false,
29 };
30
31 describe("desktop update button state", () => {
32 it("keeps retry action available after a download error", () => {
33 const state: DesktopUpdateState = {
34 ...baseState,
35 status: "error",
36 availableVersion: "1.1.0",
37 message: "network timeout",
38 errorContext: "download",
39 canRetry: true,
40 };
41 expect(resolveDesktopUpdateButtonAction(state)).toBe("download");
42 expect(getDesktopUpdateButtonTooltip(state)).toContain("Click to retry");
43 });
44
45 it("shows the download failure after returning to available", () => {
46 const state: DesktopUpdateState = {
47 ...baseState,
48 status: "available",
49 availableVersion: "1.1.0",
50 message: "network timeout",
51 errorContext: "download",
52 canRetry: true,
53 };
54 expect(resolveDesktopUpdateButtonAction(state)).toBe("download");
55 expect(getDesktopUpdateButtonTooltip(state)).toBe("Download failed for 1.1.0. Click to retry.");
56 expect(getDesktopUpdateButtonTooltip({ ...state, notAppliedVersion: "1.1.0" })).toBe(
57 "Update 1.1.0 did not apply. Click to retry.",
58 );
59 });
60
61 it("never calls a build on the other track up to date", () => {
62 // A Stable build whose switch to Nightly did not finish; the updater discards every release.
63 const state: DesktopUpdateState = {
64 ...baseState,
65 status: "up-to-date",
66 channel: "nightly",
67 currentVersion: "0.1.5",
68 checkedAt: "2026-11-18T00:00:00.000Z",
69 };
70 expect(getDesktopUpdateButtonTooltip(state)).not.toBe("Up to date");
71 expect(
72 getDesktopUpdateButtonTooltip({ ...state, currentVersion: "0.1.6-nightly.20261118.1" }),
73 ).toBe("Up to date");
74 });
75
76 it("prefers a newly available release over a stale downloaded version", () => {
77 const state: DesktopUpdateState = {
78 ...baseState,
79 status: "available",
80 availableVersion: "1.2.0",
81 downloadedVersion: "1.1.0",
82 };
83 expect(resolveDesktopUpdateButtonAction(state)).toBe("download");
84 });
85
86 it("hides the install action while checking for a newer release", () => {
87 const state: DesktopUpdateState = {
88 ...baseState,
89 status: "checking",
90 availableVersion: "1.1.0",
91 downloadedVersion: "1.1.0",
92 downloadPercent: 100,
93 };
94 expect(resolveDesktopUpdateButtonAction(state)).toBe("none");
95 });
96 });
97
98 describe("desktop update UI helpers", () => {
99 it.each(["owner/repo/extra", "owner#notes/repo", "owner/repo?tab=notes"])(
100 "falls back to upstream for an invalid configured repository: %s",
101 (repository) => {
102 expect(getDesktopUpdateReleaseHistoryUrl(repository)).toBe(
103 "https://github.com/pingdotgg/t3code/releases",
104 );
105 expect(getDesktopUpdateReleaseUrl("1.2.3", repository)).toBe(
106 "https://github.com/pingdotgg/t3code/releases/tag/v1.2.3",
107 );
108 },
109 );
110 });
111
112 describe("canCheckForUpdate", () => {
113 it("returns true once an update has been downloaded so newer releases can be found", () => {
114 expect(
115 canCheckForUpdate({
116 ...baseState,
117 status: "downloaded",
118 availableVersion: "1.1.0",
119 downloadedVersion: "1.1.0",
120 }),
121 ).toBe(true);
122 });
123 });