@@ -2,12 +2,13 @@ import { describe, expect, it } from "vitest";
22import type { DesktopUpdateActionResult , DesktopUpdateState } from "@t3tools/contracts" ;
33
44import {
5+ canCheckForUpdate ,
56 getArm64IntelBuildWarningDescription ,
67 getDesktopUpdateActionError ,
78 getDesktopUpdateButtonTooltip ,
9+ getDesktopUpdateInstallConfirmationMessage ,
810 isDesktopUpdateButtonDisabled ,
911 resolveDesktopUpdateButtonAction ,
10- shouldHighlightDesktopUpdateError ,
1112 shouldShowArm64IntelBuildWarning ,
1213 shouldShowDesktopUpdateButton ,
1314 shouldToastDesktopUpdateActionResult ,
@@ -69,6 +70,16 @@ describe("desktop update button state", () => {
6970 expect ( getDesktopUpdateButtonTooltip ( state ) ) . toContain ( "Click to retry" ) ;
7071 } ) ;
7172
73+ it ( "prefers install when a downloaded version already exists" , ( ) => {
74+ const state : DesktopUpdateState = {
75+ ...baseState ,
76+ status : "available" ,
77+ availableVersion : "1.1.0" ,
78+ downloadedVersion : "1.1.0" ,
79+ } ;
80+ expect ( resolveDesktopUpdateButtonAction ( state ) ) . toBe ( "install" ) ;
81+ } ) ;
82+
7283 it ( "hides the button for non-actionable check errors" , ( ) => {
7384 const state : DesktopUpdateState = {
7485 ...baseState ,
@@ -169,25 +180,6 @@ describe("desktop update UI helpers", () => {
169180 ) . toBe ( false ) ;
170181 } ) ;
171182
172- it ( "highlights only actionable updater errors" , ( ) => {
173- expect (
174- shouldHighlightDesktopUpdateError ( {
175- ...baseState ,
176- status : "error" ,
177- errorContext : "download" ,
178- canRetry : true ,
179- } ) ,
180- ) . toBe ( true ) ;
181- expect (
182- shouldHighlightDesktopUpdateError ( {
183- ...baseState ,
184- status : "error" ,
185- errorContext : "check" ,
186- canRetry : true ,
187- } ) ,
188- ) . toBe ( false ) ;
189- } ) ;
190-
191183 it ( "shows an Apple Silicon warning for Intel builds under Rosetta" , ( ) => {
192184 const state : DesktopUpdateState = {
193185 ...baseState ,
@@ -213,4 +205,87 @@ describe("desktop update UI helpers", () => {
213205
214206 expect ( getArm64IntelBuildWarningDescription ( state ) ) . toContain ( "Download the available update" ) ;
215207 } ) ;
208+
209+ it ( "includes the downloaded version in the install confirmation copy" , ( ) => {
210+ expect (
211+ getDesktopUpdateInstallConfirmationMessage ( {
212+ availableVersion : "1.1.0" ,
213+ downloadedVersion : "1.1.1" ,
214+ } ) ,
215+ ) . toContain ( "Install update 1.1.1 and restart T3 Code?" ) ;
216+ } ) ;
217+
218+ it ( "falls back to generic install confirmation copy when no version is available" , ( ) => {
219+ expect (
220+ getDesktopUpdateInstallConfirmationMessage ( {
221+ availableVersion : null ,
222+ downloadedVersion : null ,
223+ } ) ,
224+ ) . toContain ( "Install update and restart T3 Code?" ) ;
225+ } ) ;
226+ } ) ;
227+
228+ describe ( "canCheckForUpdate" , ( ) => {
229+ it ( "returns false for null state" , ( ) => {
230+ expect ( canCheckForUpdate ( null ) ) . toBe ( false ) ;
231+ } ) ;
232+
233+ it ( "returns false when updates are disabled" , ( ) => {
234+ expect ( canCheckForUpdate ( { ...baseState , enabled : false , status : "disabled" } ) ) . toBe ( false ) ;
235+ } ) ;
236+
237+ it ( "returns false while checking" , ( ) => {
238+ expect ( canCheckForUpdate ( { ...baseState , status : "checking" } ) ) . toBe ( false ) ;
239+ } ) ;
240+
241+ it ( "returns false while downloading" , ( ) => {
242+ expect ( canCheckForUpdate ( { ...baseState , status : "downloading" , downloadPercent : 50 } ) ) . toBe (
243+ false ,
244+ ) ;
245+ } ) ;
246+
247+ it ( "returns false once an update has been downloaded" , ( ) => {
248+ expect (
249+ canCheckForUpdate ( {
250+ ...baseState ,
251+ status : "downloaded" ,
252+ availableVersion : "1.1.0" ,
253+ downloadedVersion : "1.1.0" ,
254+ } ) ,
255+ ) . toBe ( false ) ;
256+ } ) ;
257+
258+ it ( "returns true when idle" , ( ) => {
259+ expect ( canCheckForUpdate ( { ...baseState , status : "idle" } ) ) . toBe ( true ) ;
260+ } ) ;
261+
262+ it ( "returns true when up-to-date" , ( ) => {
263+ expect ( canCheckForUpdate ( { ...baseState , status : "up-to-date" } ) ) . toBe ( true ) ;
264+ } ) ;
265+
266+ it ( "returns true when an update is available" , ( ) => {
267+ expect (
268+ canCheckForUpdate ( { ...baseState , status : "available" , availableVersion : "1.1.0" } ) ,
269+ ) . toBe ( true ) ;
270+ } ) ;
271+
272+ it ( "returns true on error so the user can retry" , ( ) => {
273+ expect (
274+ canCheckForUpdate ( {
275+ ...baseState ,
276+ status : "error" ,
277+ errorContext : "check" ,
278+ message : "network" ,
279+ } ) ,
280+ ) . toBe ( true ) ;
281+ } ) ;
282+ } ) ;
283+
284+ describe ( "getDesktopUpdateButtonTooltip" , ( ) => {
285+ it ( "returns 'Up to date' for non-actionable states" , ( ) => {
286+ expect ( getDesktopUpdateButtonTooltip ( { ...baseState , status : "idle" } ) ) . toBe ( "Up to date" ) ;
287+ expect ( getDesktopUpdateButtonTooltip ( { ...baseState , status : "up-to-date" } ) ) . toBe (
288+ "Up to date" ,
289+ ) ;
290+ } ) ;
216291} ) ;
0 commit comments