@@ -5,6 +5,7 @@ import { useReleaseStore } from '@/stores/releaseStore'
55
66// Mock the dependencies
77vi . mock ( '@/utils/formatUtil' )
8+ vi . mock ( '@/utils/envUtil' )
89vi . mock ( '@/services/releaseService' )
910vi . mock ( '@/stores/settingStore' )
1011vi . mock ( '@/stores/systemStatsStore' )
@@ -56,10 +57,12 @@ describe('useReleaseStore', () => {
5657 const { useReleaseService } = await import ( '@/services/releaseService' )
5758 const { useSettingStore } = await import ( '@/stores/settingStore' )
5859 const { useSystemStatsStore } = await import ( '@/stores/systemStatsStore' )
60+ const { isElectron } = await import ( '@/utils/envUtil' )
5961
6062 vi . mocked ( useReleaseService ) . mockReturnValue ( mockReleaseService )
6163 vi . mocked ( useSettingStore ) . mockReturnValue ( mockSettingStore )
6264 vi . mocked ( useSystemStatsStore ) . mockReturnValue ( mockSystemStatsStore )
65+ vi . mocked ( isElectron ) . mockReturnValue ( true )
6366
6467 // Default showVersionUpdates to true
6568 mockSettingStore . get . mockImplementation ( ( key : string ) => {
@@ -444,4 +447,118 @@ describe('useReleaseStore', () => {
444447 expect ( mockReleaseService . getReleases ) . toHaveBeenCalledTimes ( 1 )
445448 } )
446449 } )
450+
451+ describe ( 'isElectron environment checks' , ( ) => {
452+ beforeEach ( ( ) => {
453+ // Set up a new version available
454+ store . releases = [ mockRelease ]
455+ mockSettingStore . get . mockImplementation ( ( key : string ) => {
456+ if ( key === 'Comfy.Notification.ShowVersionUpdates' ) return true
457+ return null
458+ } )
459+ } )
460+
461+ describe ( 'when running in Electron (desktop)' , ( ) => {
462+ beforeEach ( async ( ) => {
463+ const { isElectron } = await import ( '@/utils/envUtil' )
464+ vi . mocked ( isElectron ) . mockReturnValue ( true )
465+ } )
466+
467+ it ( 'should show toast when conditions are met' , async ( ) => {
468+ const { compareVersions } = await import ( '@/utils/formatUtil' )
469+ vi . mocked ( compareVersions ) . mockReturnValue ( 1 )
470+
471+ // Need multiple releases for hasMediumOrHighAttention
472+ const mediumRelease = {
473+ ...mockRelease ,
474+ id : 2 ,
475+ attention : 'medium' as const
476+ }
477+ store . releases = [ mockRelease , mediumRelease ]
478+
479+ expect ( store . shouldShowToast ) . toBe ( true )
480+ } )
481+
482+ it ( 'should show red dot when new version available' , async ( ) => {
483+ const { compareVersions } = await import ( '@/utils/formatUtil' )
484+ vi . mocked ( compareVersions ) . mockReturnValue ( 1 )
485+
486+ expect ( store . shouldShowRedDot ) . toBe ( true )
487+ } )
488+
489+ it ( 'should show popup for latest version' , async ( ) => {
490+ mockSystemStatsStore . systemStats . system . comfyui_version = '1.2.0'
491+ const { compareVersions } = await import ( '@/utils/formatUtil' )
492+ vi . mocked ( compareVersions ) . mockReturnValue ( 0 )
493+
494+ expect ( store . shouldShowPopup ) . toBe ( true )
495+ } )
496+ } )
497+
498+ describe ( 'when NOT running in Electron (web)' , ( ) => {
499+ beforeEach ( async ( ) => {
500+ const { isElectron } = await import ( '@/utils/envUtil' )
501+ vi . mocked ( isElectron ) . mockReturnValue ( false )
502+ } )
503+
504+ it ( 'should NOT show toast even when all other conditions are met' , async ( ) => {
505+ const { compareVersions } = await import ( '@/utils/formatUtil' )
506+ vi . mocked ( compareVersions ) . mockReturnValue ( 1 )
507+
508+ // Set up all conditions that would normally show toast
509+ const mediumRelease = {
510+ ...mockRelease ,
511+ id : 2 ,
512+ attention : 'medium' as const
513+ }
514+ store . releases = [ mockRelease , mediumRelease ]
515+
516+ expect ( store . shouldShowToast ) . toBe ( false )
517+ } )
518+
519+ it ( 'should NOT show red dot even when new version available' , async ( ) => {
520+ const { compareVersions } = await import ( '@/utils/formatUtil' )
521+ vi . mocked ( compareVersions ) . mockReturnValue ( 1 )
522+
523+ expect ( store . shouldShowRedDot ) . toBe ( false )
524+ } )
525+
526+ it ( 'should NOT show toast regardless of attention level' , async ( ) => {
527+ const { compareVersions } = await import ( '@/utils/formatUtil' )
528+ vi . mocked ( compareVersions ) . mockReturnValue ( 1 )
529+
530+ // Test with high attention releases
531+ const highRelease = {
532+ ...mockRelease ,
533+ id : 2 ,
534+ attention : 'high' as const
535+ }
536+ const mediumRelease = {
537+ ...mockRelease ,
538+ id : 3 ,
539+ attention : 'medium' as const
540+ }
541+ store . releases = [ highRelease , mediumRelease ]
542+
543+ expect ( store . shouldShowToast ) . toBe ( false )
544+ } )
545+
546+ it ( 'should NOT show red dot even with high attention release' , async ( ) => {
547+ const { compareVersions } = await import ( '@/utils/formatUtil' )
548+ vi . mocked ( compareVersions ) . mockReturnValue ( 1 )
549+
550+ store . releases = [ { ...mockRelease , attention : 'high' as const } ]
551+
552+ expect ( store . shouldShowRedDot ) . toBe ( false )
553+ } )
554+
555+ it ( 'should NOT show popup even for latest version' , async ( ) => {
556+ mockSystemStatsStore . systemStats . system . comfyui_version = '1.2.0'
557+ const { compareVersions } = await import ( '@/utils/formatUtil' )
558+ vi . mocked ( compareVersions ) . mockReturnValue ( 0 )
559+
560+ expect ( store . shouldShowPopup ) . toBe ( false )
561+ } )
562+ } )
563+ } )
447564} )
0 commit comments