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

desktopUpdate.logic.test.ts

95 lines2.7 KB

1import { describe, expect, it } from "vite-plus/test";
2import type { DesktopUpdateState } from "@t3tools/contracts";
3​
4import {
5 canCheckForUpdate,
6 getDesktopUpdateButtonTooltip,
7 getDesktopUpdateReleaseHistoryUrl,
8 getDesktopUpdateReleaseUrl,
9 resolveDesktopUpdateButtonAction,
10} from "./desktopUpdate.logic";
11​
12const 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​
31describe("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("prefers a newly available release over a stale downloaded version", () => {
46 const state: DesktopUpdateState = {
47 ...baseState,
48 status: "available",
49 availableVersion: "1.2.0",
50 downloadedVersion: "1.1.0",
51 };
52 expect(resolveDesktopUpdateButtonAction(state)).toBe("download");
53 });
54​
55 it("hides the install action while checking for a newer release", () => {
56 const state: DesktopUpdateState = {
57 ...baseState,
58 status: "checking",
59 availableVersion: "1.1.0",
60 downloadedVersion: "1.1.0",
61 downloadPercent: 100,
62 };
63 expect(resolveDesktopUpdateButtonAction(state)).toBe("none");
64 });
65});
66​
67describe("desktop update UI helpers", () => {
68 it.each([
69 "owner/repo/extra",
70 "owner#notes/repo",
71 "owner/repo#notes",
72 "owner?tab=notes/repo",
73 "owner/repo?tab=notes",
74 ])("falls back to upstream for an invalid configured repository: %s", (repository) => {
75 expect(getDesktopUpdateReleaseHistoryUrl(repository)).toBe(
76 "https://github.com/pingdotgg/t3code/releases",
77 );
78 expect(getDesktopUpdateReleaseUrl("1.2.3", repository)).toBe(
79 "https://github.com/pingdotgg/t3code/releases/tag/v1.2.3",
80 );
81 });
82});
83​
84describe("canCheckForUpdate", () => {
85 it("returns true once an update has been downloaded so newer releases can be found", () => {
86 expect(
87 canCheckForUpdate({
88 ...baseState,
89 status: "downloaded",
90 availableVersion: "1.1.0",
91 downloadedVersion: "1.1.0",
92 }),
93 ).toBe(true);
94 });
95});