|
1 | 1 | import type { DesktopUpdateChannel, DesktopUpdateState } from "@t3tools/contracts"; |
2 | 2 | import { describe, expect, it } from "vite-plus/test"; |
3 | 3 |
|
4 | | -import { localUpdaterStaysPut, prepareLocalTrackSwitch } from "./updateTrackSwitch.logic"; |
| 4 | +import { |
| 5 | + localUpdaterStaysPut, |
| 6 | + nothingToMove, |
| 7 | + prepareLocalTrackSwitch, |
| 8 | +} from "./updateTrackSwitch.logic"; |
5 | 9 |
|
6 | 10 | const STABLE = "0.1.3"; |
7 | 11 |
|
@@ -75,6 +79,67 @@ describe("prepareLocalTrackSwitch", () => { |
75 | 79 | }); |
76 | 80 | }); |
77 | 81 |
|
| 82 | +describe("nothingToMove", () => { |
| 83 | + const skippedRemote = { |
| 84 | + skipped: "its server predates database checks; update it on Nightly first", |
| 85 | + }; |
| 86 | + const stableSwitch = { |
| 87 | + label: "Stable", |
| 88 | + channel: "latest" as const, |
| 89 | + savedChannel: "latest" as const, |
| 90 | + switchesLocal: false, |
| 91 | + crossesLocal: false, |
| 92 | + rows: [skippedRemote], |
| 93 | + hasTargets: false, |
| 94 | + }; |
| 95 | + |
| 96 | + it("disables a switch that would neither move a machine nor save a track", () => { |
| 97 | + expect(nothingToMove(stableSwitch)).toEqual({ |
| 98 | + note: null, |
| 99 | + disabledReason: "No machine can switch to Stable now.", |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + it("says a switch only saves the track when no machine moves", () => { |
| 104 | + const onlySaves = { note: "No machine can switch to Stable now. This only saves the track." }; |
| 105 | + expect(nothingToMove({ ...stableSwitch, savedChannel: "nightly" })).toEqual({ |
| 106 | + ...onlySaves, |
| 107 | + disabledReason: null, |
| 108 | + }); |
| 109 | + // Before the desktop reports its saved track, confirming may still need to save it. |
| 110 | + expect(nothingToMove({ ...stableSwitch, savedChannel: null })).toEqual({ |
| 111 | + ...onlySaves, |
| 112 | + disabledReason: null, |
| 113 | + }); |
| 114 | + // A desktop host already on the track still gets its saved track changed. |
| 115 | + expect(nothingToMove({ ...stableSwitch, hasTargets: true })).toEqual({ |
| 116 | + ...onlySaves, |
| 117 | + disabledReason: null, |
| 118 | + }); |
| 119 | + // With its updater off, this app stays on the other track. |
| 120 | + expect( |
| 121 | + nothingToMove({ ...stableSwitch, rows: [], crossesLocal: true, savedChannel: "nightly" }), |
| 122 | + ).toEqual({ |
| 123 | + ...onlySaves, |
| 124 | + disabledReason: null, |
| 125 | + }); |
| 126 | + expect(nothingToMove({ ...stableSwitch, rows: [], savedChannel: "nightly" })).toEqual({ |
| 127 | + note: "Every connected machine is already on Stable. This only saves the track.", |
| 128 | + disabledReason: null, |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | + it("stays out of a switch that moves a machine", () => { |
| 133 | + const none = { note: null, disabledReason: null }; |
| 134 | + expect(nothingToMove({ ...stableSwitch, switchesLocal: true, crossesLocal: true })).toEqual( |
| 135 | + none, |
| 136 | + ); |
| 137 | + expect(nothingToMove({ ...stableSwitch, rows: [skippedRemote, { skipped: null }] })).toEqual( |
| 138 | + none, |
| 139 | + ); |
| 140 | + }); |
| 141 | +}); |
| 142 | + |
78 | 143 | describe("localUpdaterStaysPut", () => { |
79 | 144 | it("moves an app whose updater is off only because its policy rules out nightly", () => { |
80 | 145 | const blocked = { enabled: false, channelBlockedByPolicy: true as const }; |
|
0 commit comments