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

DesktopStartupRecovery.test.ts

70 lines2.2 KB

1import type { DesktopUpdateState } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { createInitialDesktopUpdateState } from "../updates/updateMachine.ts";
5import { resolveStartupRecoveryOffer } from "./DesktopStartupRecovery.ts";
6​
7const updateState = (patch: Partial<DesktopUpdateState>): DesktopUpdateState => ({
8 ...createInitialDesktopUpdateState(
9 "0.1.3",
10 { hostArch: "arm64", appArch: "arm64", runningUnderArm64Translation: false },
11 "latest",
12 ),
13 enabled: true,
14 ...patch,
15});
16​
17describe("resolveStartupRecoveryOffer", () => {
18 it("offers a newer version before going back", () => {
19 expect(
20 resolveStartupRecoveryOffer(
21 updateState({ status: "available", availableVersion: "0.1.4" }),
22 "0.1.2",
23 ),
24 ).toEqual({ _tag: "Update", version: "0.1.4" });
25 });
26​
27 it("offers a retained download after a later check fails", () => {
28 expect(
29 resolveStartupRecoveryOffer(
30 updateState({ status: "error", errorContext: "check", downloadedVersion: "0.1.4" }),
31 null,
32 ),
33 ).toEqual({ _tag: "Update", version: "0.1.4" });
34 });
35​
36 it("waits for the update check before offering to go back", () => {
37 expect(resolveStartupRecoveryOffer(updateState({ status: "checking" }), "0.1.2")).toEqual({
38 _tag: "Checking",
39 });
40 });
41​
42 it("offers the last version that started when no update exists", () => {
43 expect(resolveStartupRecoveryOffer(updateState({ status: "up-to-date" }), "0.1.2")).toEqual({
44 _tag: "Reinstall",
45 version: "0.1.2",
46 });
47 });
48​
49 it("does not offer an update that already failed to apply here", () => {
50 expect(
51 resolveStartupRecoveryOffer(
52 updateState({
53 status: "downloaded",
54 downloadedVersion: "0.1.4",
55 notAppliedVersion: "0.1.4",
56 }),
57 "0.1.2",
58 ),
59 ).toEqual({ _tag: "Reinstall", version: "0.1.2" });
60 });
61​
62 it("falls back to the releases page when this version never started", () => {
63 expect(resolveStartupRecoveryOffer(updateState({ status: "disabled" }), "0.1.3")).toEqual({
64 _tag: "Releases",
65 });
66 expect(resolveStartupRecoveryOffer(updateState({ status: "up-to-date" }), null)).toEqual({
67 _tag: "Releases",
68 });
69 });
70});