11// @vitest -environment jsdom
22
3- import { cleanup , render , screen } from '@testing-library/react' ;
4- import { afterEach , describe , expect , it , vi } from 'vitest' ;
3+ import type { UpdaterState } from '@linkcode/ipc' ;
4+ import { cleanup , fireEvent , render , screen } from '@testing-library/react' ;
5+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
56import { AboutTab } from '../about-tab' ;
67
8+ const mocks = vi . hoisted ( ( ) => ( {
9+ useUpdaterState : vi . fn ( ) ,
10+ checkForUpdates : vi . fn ( ) ,
11+ installUpdate : vi . fn ( ) ,
12+ } ) ) ;
13+
714vi . mock ( '../../ipc' , ( ) => ( {
815 systemBridge : {
916 app : {
10- checkForUpdates : vi . fn ( ) ,
17+ checkForUpdates : mocks . checkForUpdates ,
18+ installUpdate : mocks . installUpdate ,
1119 version : vi . fn ( ( ) => Promise . resolve ( '0.15.0' ) ) ,
1220 } ,
1321 } ,
1422} ) ) ;
1523
1624vi . mock ( '../../updater' , ( ) => ( {
17- useUpdaterState : ( ) => ( {
18- status : 'downloading' ,
19- version : '0.16.0' ,
20- progress : 42.4 ,
21- } ) ,
25+ useUpdaterState : mocks . useUpdaterState ,
2226} ) ) ;
2327
2428vi . mock ( 'use-intl' , ( ) => ( {
2529 useTranslations ( ) {
2630 const messages : Record < string , string > = {
2731 version : 'Version' ,
2832 checkForUpdates : 'Check for updates' ,
33+ restartToInstall : 'Restart to update' ,
2934 'status.downloading' : 'Downloading update…' ,
35+ 'status.downloaded' : 'Update ready — restart to install.' ,
3036 } ;
3137 return ( key : string ) => messages [ key ] ?? key ;
3238 } ,
3339} ) ) ;
3440
3541describe ( 'AboutTab' , ( ) => {
42+ beforeEach ( ( ) => {
43+ vi . clearAllMocks ( ) ;
44+ mocks . useUpdaterState . mockReturnValue ( {
45+ status : 'downloading' ,
46+ version : '0.16.0' ,
47+ progress : 42.4 ,
48+ } satisfies UpdaterState ) ;
49+ } ) ;
50+
3651 afterEach ( cleanup ) ;
3752
3853 it ( 'shows accessible update download progress' , async ( ) => {
@@ -43,4 +58,20 @@ describe('AboutTab', () => {
4358 expect ( progress . getAttribute ( 'aria-valuenow' ) ) . toBe ( '42' ) ;
4459 expect ( screen . getByText ( '42%' ) ) . toBeTruthy ( ) ;
4560 } ) ;
61+
62+ // Main refuses a re-check while an update sits downloaded, so the check button must not be offered.
63+ it ( 'offers the install instead of a check once the update is downloaded' , ( ) => {
64+ mocks . useUpdaterState . mockReturnValue ( {
65+ status : 'downloaded' ,
66+ version : '0.16.0' ,
67+ progress : null ,
68+ } satisfies UpdaterState ) ;
69+ render ( < AboutTab /> ) ;
70+
71+ expect ( screen . queryByRole ( 'button' , { name : 'Check for updates' } ) ) . toBeNull ( ) ;
72+
73+ fireEvent . click ( screen . getByRole ( 'button' , { name : 'Restart to update' } ) ) ;
74+ expect ( mocks . installUpdate ) . toHaveBeenCalledOnce ( ) ;
75+ expect ( mocks . checkForUpdates ) . not . toHaveBeenCalled ( ) ;
76+ } ) ;
4677} ) ;
0 commit comments