mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-01 05:49:54 +00:00
* fix: Replace reactive feature flags with non-reactive approach - Changed managerUIState from computed to getManagerUIState() function - Ensures fresh computation on each call to avoid timing issues - Updates all consumers to use the new function-based approach - Fixes manager UI state determination issues This change addresses the reactivity issues where feature flags were not updating properly due to Vue's reactive system limitations with external API values. * fix: Add HelpCenter manager state handling and API version switching - Fixed HelpCenter manager extension to check manager state - Fixed 'Manager' command to respect manager state - Added dynamic API prefix switching based on manager state - Added debug logging for manager state determination This ensures legacy manager uses /api/ prefix and new manager uses /api/v2/ prefix * fix: Simplify manager state determination and fix API timing issues - Remove unnecessary extension check from manager state store - Use only feature flags (client and server) for state determination - Default to NEW_UI when server flags not loaded (safer default) - Fix ImportFailInfoBulk to not send empty requests - Resolves initial 404 errors on installed API calls * fix: Correct manager state determination for non-v4 servers - Fix serverSupportsV4=false returning DISABLED instead of LEGACY_UI - Server without v4 support should use legacy manager, not disable it - Clarify condition for server v4 + client non-v4 case * chore: Remove debug console.log statements - Remove all debug logging from manager state store - Remove logging from comfy manager service - Clean up code for production * test: Update manager state store tests to match new logic - Update test expectations for server feature flags undefined case (returns NEW_UI) - Update test expectations for server not supporting v4 case (returns LEGACY_UI) - Tests now correctly reflect the actual behavior of the manager state logic * fix: Remove dynamic API version handling in manager service - Remove getApiBaseURL() function and axios interceptor - Always use /api/v2/ for New Manager (hardcoded) - Add isManagerServiceAvailable() to block service calls when not in NEW_UI state - Simplify API handling as manager packages are now completely separated * refactor: Add helper functions to managerStateStore for better code reuse - Add isManagerEnabled(), isNewManagerUI(), isLegacyManagerUI() helpers - Add shouldShowInstallButton(), shouldShowManagerButtons() for UI logic - Update components to use helper functions where applicable - Add comprehensive tests for new helper functions - Centralize state checking logic to reduce duplication * fix: Ensure SystemStats is loaded before conflict detection - Move conflict detection from App.vue to GraphCanvas.vue - Check manager state before running conflict detection - Ensures SystemStats and feature flags are loaded first - Prevents unnecessary API calls when manager is disabled * docs: Clarify feature flag default behavior in manager state - Add detailed comments explaining why NEW_UI is the default - Clarify that undefined state is temporary during WebSocket connection - Document graceful error handling when server doesn't support v2 API * fix: Ensure consistent manager state handling for legacy commands - Legacy commands now show error toast in NEW_UI mode - Settings fallback for DISABLED mode - Consistent error handling across all manager entry points - Legacy commands only work in LEGACY_UI mode as expected * refactor: centralize manager opening logic into managerStateStore - Create openManager() function in managerStateStore to eliminate duplicate code - Replace 8+ repeated switch statements across different files with single function - Fix inconsistency where legacy command failure in LEGACY_UI mode incorrectly opened new manager - Add support for legacy-only commands that should show error in NEW_UI mode - Ensure all manager entry points behave consistently according to feature flags - Clean up unused imports and fix ESLint errors This addresses Christian's code review feedback about duplicate switch statements and improves maintainability by providing a single source of truth for manager opening logic. * fix: use correct i18n import in managerStateStore - Replace useI18n with direct t import from @/i18n - Fixes issue where error messages showed as numbers (e.g. '26') instead of text - Ensures toast messages display correctly in NEW_UI mode when legacy commands are invoked * feature: initial tab fix * test: Fix managerStateStore test failures by adding missing mocks The test was failing because managerStateStore imports dialogService, which imports ErrorDialogContent.vue that instantiates the app object. This caused api.addEventListener errors in tests. Added proper mocks for: - dialogService - commandStore - toastStore This prevents the problematic import chain and fixes the test failures. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: convert managerStateStore to composable - Move managerStateStore from store to composable pattern - All functions are non-reactive utilities that don't need state management - Follows Pinia guideline: "If it's not reactive, it shouldn't be in a store" - Update all import paths across 8 files - Move and update test file accordingly This change improves architecture consistency as other utility functions in the codebase also use composables rather than stores when reactivity is not required. * refactor: use readonly computed properties instead of getter methods - Convert all getter methods to readonly computed properties - Follows Vue conventions for better performance through caching - Change access pattern from function calls to .value properties - Update all usages across 6 files - Thanks to @DrJKL for the suggestion This improves performance by caching computed values and aligns with Vue's reactive system patterns. * fix: check isManagerEnabled check to GraphCanvas.vue to avoid the side-effects of calling useConflictDetection which include calling useComfyManagerStore * chore: console.log to console.debug * chore: useConflictDetection().initializeConflictDetection() * test: add mockManagerDisabled option to disable manager in Playwright tests - Add mockManagerDisabled parameter to ComfyPage.setup() (defaults to true) - Override api.getServerFeature() to return false for manager feature flag - Prevents manager initialization from interfering with subgraph tests - Individual tests can still enable manager when needed by passing mockManagerDisabled: false * chore: text modified * fix: resolve CI/CD failures by fixing manager initialization timing ## Problem GraphCanvas.vue was initializing conflict detection during component setup, causing side effects in test environment where manager is disabled. This led to 4 Playwright test failures in PR #5317. ## Root Cause - GraphCanvas.vue called useConflictDetection() in setup phase - This triggered store side effects even when manager was disabled - systemStats wasn't ready when checking manager state ## Solution 1. Removed conflict detection initialization from GraphCanvas.vue entirely 2. Refactored systemStatsStore to use VueUse's useAsyncState pattern 3. Added isInitialized check in useManagerState to wait for systemStats 4. Updated useConflictDetection to check manager state internally ## Changes - **GraphCanvas.vue**: Removed all conflict detection code - **systemStatsStore**: Implemented useAsyncState for proper async handling - **useManagerState**: Added isInitialized check before checking manager state - **useConflictDetection**: Added internal manager state validation - **App.vue**: Removed unnecessary fetchSystemStats calls - **Tests**: Updated unit tests for new async behavior ## Test Results All 4 previously failing Playwright tests now pass: - featureFlags.spec.ts (feature flag handling) - subgraph.spec.ts (breadcrumb updates, DOM cleanup) - widget.spec.ts (image changes) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: modified the note * fix: test code modified * fix: when manager is new manager ui, conflict detectetion should work * fix: ensure fetch system stats before determine manager stats & when new ui & call legacy ui, open new manger dialog by default * chore: unnecessary .value deleted & fetch name modified to refetch * fix: ref type .value needed * chore: vue use until pattern for waiting initializing * fix: .value added * fix: useManagerState test to properly mock reactive refs The test was failing because it was mocking systemStats and isInitialized as plain values instead of reactive refs. The actual composable uses storeToRefs which returns refs with .value properties. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: when system stats initialized, use until(systemStatsStore.isInitialized) * fix: test --------- Co-authored-by: Claude <noreply@anthropic.com>
679 lines
21 KiB
TypeScript
679 lines
21 KiB
TypeScript
import { createPinia, setActivePinia } from 'pinia'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { useReleaseStore } from '@/stores/releaseStore'
|
|
|
|
// Mock the dependencies
|
|
vi.mock('@/utils/formatUtil')
|
|
vi.mock('@/utils/envUtil')
|
|
vi.mock('@/services/releaseService')
|
|
vi.mock('@/stores/settingStore')
|
|
vi.mock('@/stores/systemStatsStore')
|
|
vi.mock('@vueuse/core', () => ({
|
|
until: vi.fn(() => Promise.resolve()),
|
|
useStorage: vi.fn(() => ({ value: {} }))
|
|
}))
|
|
|
|
describe('useReleaseStore', () => {
|
|
let store: ReturnType<typeof useReleaseStore>
|
|
let mockReleaseService: any
|
|
let mockSettingStore: any
|
|
let mockSystemStatsStore: any
|
|
|
|
const mockRelease = {
|
|
id: 1,
|
|
project: 'comfyui' as const,
|
|
version: '1.2.0',
|
|
content: 'New features and improvements',
|
|
published_at: '2023-12-01T00:00:00Z',
|
|
attention: 'high' as const
|
|
}
|
|
|
|
beforeEach(async () => {
|
|
setActivePinia(createPinia())
|
|
|
|
// Reset all mocks
|
|
vi.clearAllMocks()
|
|
|
|
// Setup mock services
|
|
mockReleaseService = {
|
|
getReleases: vi.fn(),
|
|
isLoading: { value: false },
|
|
error: { value: null }
|
|
}
|
|
|
|
mockSettingStore = {
|
|
get: vi.fn(),
|
|
set: vi.fn()
|
|
}
|
|
|
|
mockSystemStatsStore = {
|
|
systemStats: {
|
|
system: {
|
|
comfyui_version: '1.0.0'
|
|
}
|
|
},
|
|
isInitialized: true,
|
|
refetchSystemStats: vi.fn(),
|
|
getFormFactor: vi.fn(() => 'git-windows')
|
|
}
|
|
|
|
// Setup mock implementations
|
|
const { useReleaseService } = await import('@/services/releaseService')
|
|
const { useSettingStore } = await import('@/stores/settingStore')
|
|
const { useSystemStatsStore } = await import('@/stores/systemStatsStore')
|
|
const { isElectron } = await import('@/utils/envUtil')
|
|
|
|
vi.mocked(useReleaseService).mockReturnValue(mockReleaseService)
|
|
vi.mocked(useSettingStore).mockReturnValue(mockSettingStore)
|
|
vi.mocked(useSystemStatsStore).mockReturnValue(mockSystemStatsStore)
|
|
vi.mocked(isElectron).mockReturnValue(true)
|
|
|
|
// Default showVersionUpdates to true
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
|
|
return null
|
|
})
|
|
|
|
store = useReleaseStore()
|
|
})
|
|
|
|
describe('initial state', () => {
|
|
it('should initialize with default state', () => {
|
|
expect(store.releases).toEqual([])
|
|
expect(store.isLoading).toBe(false)
|
|
expect(store.error).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('computed properties', () => {
|
|
it('should return most recent release', () => {
|
|
const olderRelease = {
|
|
...mockRelease,
|
|
id: 2,
|
|
version: '1.1.0',
|
|
published_at: '2023-11-01T00:00:00Z'
|
|
}
|
|
|
|
store.releases = [mockRelease, olderRelease]
|
|
expect(store.recentRelease).toEqual(mockRelease)
|
|
})
|
|
|
|
it('should return 3 most recent releases', () => {
|
|
const releases = [
|
|
mockRelease,
|
|
{ ...mockRelease, id: 2, version: '1.1.0' },
|
|
{ ...mockRelease, id: 3, version: '1.0.0' },
|
|
{ ...mockRelease, id: 4, version: '0.9.0' }
|
|
]
|
|
|
|
store.releases = releases
|
|
expect(store.recentReleases).toEqual(releases.slice(0, 3))
|
|
})
|
|
|
|
it('should show update button (shouldShowUpdateButton)', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1) // newer version available
|
|
|
|
store.releases = [mockRelease]
|
|
expect(store.shouldShowUpdateButton).toBe(true)
|
|
})
|
|
|
|
it('should not show update button when no new version', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(-1) // current version is newer
|
|
|
|
store.releases = [mockRelease]
|
|
expect(store.shouldShowUpdateButton).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('showVersionUpdates setting', () => {
|
|
beforeEach(() => {
|
|
store.releases = [mockRelease]
|
|
})
|
|
|
|
describe('when notifications are enabled', () => {
|
|
beforeEach(() => {
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
|
|
return null
|
|
})
|
|
})
|
|
|
|
it('should show toast for medium/high attention releases', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
// Need multiple releases for hasMediumOrHighAttention to work
|
|
const mediumRelease = {
|
|
...mockRelease,
|
|
id: 2,
|
|
attention: 'medium' as const
|
|
}
|
|
store.releases = [mockRelease, mediumRelease]
|
|
|
|
expect(store.shouldShowToast).toBe(true)
|
|
})
|
|
|
|
it('should show red dot for new versions', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
expect(store.shouldShowRedDot).toBe(true)
|
|
})
|
|
|
|
it('should show popup for latest version', async () => {
|
|
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0'
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(0)
|
|
|
|
expect(store.shouldShowPopup).toBe(true)
|
|
})
|
|
|
|
it('should fetch releases during initialization', async () => {
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.initialize()
|
|
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalledWith({
|
|
project: 'comfyui',
|
|
current_version: '1.0.0',
|
|
form_factor: 'git-windows'
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('when notifications are disabled', () => {
|
|
beforeEach(() => {
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return false
|
|
return null
|
|
})
|
|
})
|
|
|
|
it('should not show toast even with new version available', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
expect(store.shouldShowToast).toBe(false)
|
|
})
|
|
|
|
it('should not show red dot even with new version available', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
expect(store.shouldShowRedDot).toBe(false)
|
|
})
|
|
|
|
it('should not show popup even for latest version', async () => {
|
|
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0'
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(0)
|
|
|
|
expect(store.shouldShowPopup).toBe(false)
|
|
})
|
|
|
|
it('should skip fetching releases during initialization', async () => {
|
|
await store.initialize()
|
|
|
|
expect(mockReleaseService.getReleases).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should not fetch releases when calling fetchReleases directly', async () => {
|
|
await store.fetchReleases()
|
|
|
|
expect(mockReleaseService.getReleases).not.toHaveBeenCalled()
|
|
expect(store.isLoading).toBe(false)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('release initialization', () => {
|
|
it('should fetch releases successfully', async () => {
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.initialize()
|
|
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalledWith({
|
|
project: 'comfyui',
|
|
current_version: '1.0.0',
|
|
form_factor: 'git-windows'
|
|
})
|
|
expect(store.releases).toEqual([mockRelease])
|
|
})
|
|
|
|
it('should include form_factor in API call', async () => {
|
|
mockSystemStatsStore.getFormFactor.mockReturnValue('desktop-mac')
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.initialize()
|
|
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalledWith({
|
|
project: 'comfyui',
|
|
current_version: '1.0.0',
|
|
form_factor: 'desktop-mac'
|
|
})
|
|
})
|
|
|
|
it('should skip fetching when --disable-api-nodes is present', async () => {
|
|
mockSystemStatsStore.systemStats.system.argv = ['--disable-api-nodes']
|
|
|
|
await store.initialize()
|
|
|
|
expect(mockReleaseService.getReleases).not.toHaveBeenCalled()
|
|
expect(store.isLoading).toBe(false)
|
|
})
|
|
|
|
it('should skip fetching when --disable-api-nodes is one of multiple args', async () => {
|
|
mockSystemStatsStore.systemStats.system.argv = [
|
|
'--port',
|
|
'8080',
|
|
'--disable-api-nodes',
|
|
'--verbose'
|
|
]
|
|
|
|
await store.initialize()
|
|
|
|
expect(mockReleaseService.getReleases).not.toHaveBeenCalled()
|
|
expect(store.isLoading).toBe(false)
|
|
})
|
|
|
|
it('should fetch normally when --disable-api-nodes is not present', async () => {
|
|
mockSystemStatsStore.systemStats.system.argv = [
|
|
'--port',
|
|
'8080',
|
|
'--verbose'
|
|
]
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.initialize()
|
|
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalled()
|
|
expect(store.releases).toEqual([mockRelease])
|
|
})
|
|
|
|
it('should fetch normally when argv is undefined', async () => {
|
|
mockSystemStatsStore.systemStats.system.argv = undefined
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.initialize()
|
|
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalled()
|
|
expect(store.releases).toEqual([mockRelease])
|
|
})
|
|
|
|
it('should handle API errors gracefully', async () => {
|
|
mockReleaseService.getReleases.mockResolvedValue(null)
|
|
mockReleaseService.error.value = 'API Error'
|
|
|
|
await store.initialize()
|
|
|
|
expect(store.releases).toEqual([])
|
|
expect(store.error).toBe('API Error')
|
|
})
|
|
|
|
it('should handle non-Error objects', async () => {
|
|
mockReleaseService.getReleases.mockRejectedValue('String error')
|
|
|
|
await store.initialize()
|
|
|
|
expect(store.error).toBe('Unknown error occurred')
|
|
})
|
|
|
|
it('should set loading state correctly', async () => {
|
|
let resolvePromise: (value: any) => void
|
|
const promise = new Promise((resolve) => {
|
|
resolvePromise = resolve
|
|
})
|
|
|
|
mockReleaseService.getReleases.mockReturnValue(promise)
|
|
|
|
const initPromise = store.initialize()
|
|
expect(store.isLoading).toBe(true)
|
|
|
|
resolvePromise!([mockRelease])
|
|
await initPromise
|
|
|
|
expect(store.isLoading).toBe(false)
|
|
})
|
|
|
|
it('should fetch system stats if not available', async () => {
|
|
const { until } = await import('@vueuse/core')
|
|
mockSystemStatsStore.systemStats = null
|
|
mockSystemStatsStore.isInitialized = false
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.initialize()
|
|
|
|
expect(until).toHaveBeenCalled()
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should not set loading state when notifications disabled', async () => {
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return false
|
|
return null
|
|
})
|
|
|
|
await store.initialize()
|
|
|
|
expect(store.isLoading).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('--disable-api-nodes argument handling', () => {
|
|
it('should skip fetchReleases when --disable-api-nodes is present', async () => {
|
|
mockSystemStatsStore.systemStats.system.argv = ['--disable-api-nodes']
|
|
|
|
await store.fetchReleases()
|
|
|
|
expect(mockReleaseService.getReleases).not.toHaveBeenCalled()
|
|
expect(store.isLoading).toBe(false)
|
|
})
|
|
|
|
it('should skip fetchReleases when --disable-api-nodes is among other args', async () => {
|
|
mockSystemStatsStore.systemStats.system.argv = [
|
|
'--port',
|
|
'8080',
|
|
'--disable-api-nodes',
|
|
'--verbose'
|
|
]
|
|
|
|
await store.fetchReleases()
|
|
|
|
expect(mockReleaseService.getReleases).not.toHaveBeenCalled()
|
|
expect(store.isLoading).toBe(false)
|
|
})
|
|
|
|
it('should proceed with fetchReleases when --disable-api-nodes is not present', async () => {
|
|
mockSystemStatsStore.systemStats.system.argv = [
|
|
'--port',
|
|
'8080',
|
|
'--verbose'
|
|
]
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.fetchReleases()
|
|
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should proceed with fetchReleases when argv is null', async () => {
|
|
mockSystemStatsStore.systemStats.system.argv = null
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.fetchReleases()
|
|
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should proceed with fetchReleases when system stats are not available', async () => {
|
|
const { until } = await import('@vueuse/core')
|
|
mockSystemStatsStore.systemStats = null
|
|
mockSystemStatsStore.isInitialized = false
|
|
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
|
|
|
|
await store.fetchReleases()
|
|
|
|
expect(until).toHaveBeenCalled()
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
describe('action handlers', () => {
|
|
beforeEach(() => {
|
|
store.releases = [mockRelease]
|
|
})
|
|
|
|
it('should handle skip release', async () => {
|
|
await store.handleSkipRelease('1.2.0')
|
|
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Version',
|
|
'1.2.0'
|
|
)
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Status',
|
|
'skipped'
|
|
)
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Timestamp',
|
|
expect.any(Number)
|
|
)
|
|
})
|
|
|
|
it('should handle show changelog', async () => {
|
|
await store.handleShowChangelog('1.2.0')
|
|
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Version',
|
|
'1.2.0'
|
|
)
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Status',
|
|
'changelog seen'
|
|
)
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Timestamp',
|
|
expect.any(Number)
|
|
)
|
|
})
|
|
|
|
it('should handle whats new seen', async () => {
|
|
await store.handleWhatsNewSeen('1.2.0')
|
|
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Version',
|
|
'1.2.0'
|
|
)
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Status',
|
|
"what's new seen"
|
|
)
|
|
expect(mockSettingStore.set).toHaveBeenCalledWith(
|
|
'Comfy.Release.Timestamp',
|
|
expect.any(Number)
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('popup visibility', () => {
|
|
it('should show toast for medium/high attention releases', async () => {
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Release.Version') return null
|
|
if (key === 'Comfy.Release.Status') return null
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
|
|
return null
|
|
})
|
|
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
const mediumRelease = { ...mockRelease, attention: 'medium' as const }
|
|
store.releases = [
|
|
mockRelease,
|
|
mediumRelease,
|
|
{ ...mockRelease, attention: 'low' as const }
|
|
]
|
|
|
|
expect(store.shouldShowToast).toBe(true)
|
|
})
|
|
|
|
it('should show red dot for new versions', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
|
|
return null
|
|
})
|
|
|
|
store.releases = [mockRelease]
|
|
|
|
expect(store.shouldShowRedDot).toBe(true)
|
|
})
|
|
|
|
it('should show popup for latest version', async () => {
|
|
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0' // Same as release
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
|
|
return null
|
|
})
|
|
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(0) // versions are equal (latest version)
|
|
|
|
store.releases = [mockRelease]
|
|
|
|
expect(store.shouldShowPopup).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle missing system stats gracefully', async () => {
|
|
mockSystemStatsStore.systemStats = null
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return false
|
|
return null
|
|
})
|
|
|
|
await store.initialize()
|
|
|
|
// Should not fetch system stats when notifications disabled
|
|
expect(mockSystemStatsStore.refetchSystemStats).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should handle concurrent fetchReleases calls', async () => {
|
|
mockReleaseService.getReleases.mockImplementation(
|
|
() =>
|
|
new Promise((resolve) =>
|
|
setTimeout(() => resolve([mockRelease]), 100)
|
|
)
|
|
)
|
|
|
|
// Start two concurrent calls
|
|
const promise1 = store.fetchReleases()
|
|
const promise2 = store.fetchReleases()
|
|
|
|
await Promise.all([promise1, promise2])
|
|
|
|
// Should only call API once due to loading check
|
|
expect(mockReleaseService.getReleases).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|
|
|
|
describe('isElectron environment checks', () => {
|
|
beforeEach(() => {
|
|
// Set up a new version available
|
|
store.releases = [mockRelease]
|
|
mockSettingStore.get.mockImplementation((key: string) => {
|
|
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
|
|
return null
|
|
})
|
|
})
|
|
|
|
describe('when running in Electron (desktop)', () => {
|
|
beforeEach(async () => {
|
|
const { isElectron } = await import('@/utils/envUtil')
|
|
vi.mocked(isElectron).mockReturnValue(true)
|
|
})
|
|
|
|
it('should show toast when conditions are met', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
// Need multiple releases for hasMediumOrHighAttention
|
|
const mediumRelease = {
|
|
...mockRelease,
|
|
id: 2,
|
|
attention: 'medium' as const
|
|
}
|
|
store.releases = [mockRelease, mediumRelease]
|
|
|
|
expect(store.shouldShowToast).toBe(true)
|
|
})
|
|
|
|
it('should show red dot when new version available', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
expect(store.shouldShowRedDot).toBe(true)
|
|
})
|
|
|
|
it('should show popup for latest version', async () => {
|
|
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0'
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(0)
|
|
|
|
expect(store.shouldShowPopup).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('when NOT running in Electron (web)', () => {
|
|
beforeEach(async () => {
|
|
const { isElectron } = await import('@/utils/envUtil')
|
|
vi.mocked(isElectron).mockReturnValue(false)
|
|
})
|
|
|
|
it('should NOT show toast even when all other conditions are met', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
// Set up all conditions that would normally show toast
|
|
const mediumRelease = {
|
|
...mockRelease,
|
|
id: 2,
|
|
attention: 'medium' as const
|
|
}
|
|
store.releases = [mockRelease, mediumRelease]
|
|
|
|
expect(store.shouldShowToast).toBe(false)
|
|
})
|
|
|
|
it('should NOT show red dot even when new version available', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
expect(store.shouldShowRedDot).toBe(false)
|
|
})
|
|
|
|
it('should NOT show toast regardless of attention level', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
// Test with high attention releases
|
|
const highRelease = {
|
|
...mockRelease,
|
|
id: 2,
|
|
attention: 'high' as const
|
|
}
|
|
const mediumRelease = {
|
|
...mockRelease,
|
|
id: 3,
|
|
attention: 'medium' as const
|
|
}
|
|
store.releases = [highRelease, mediumRelease]
|
|
|
|
expect(store.shouldShowToast).toBe(false)
|
|
})
|
|
|
|
it('should NOT show red dot even with high attention release', async () => {
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(1)
|
|
|
|
store.releases = [{ ...mockRelease, attention: 'high' as const }]
|
|
|
|
expect(store.shouldShowRedDot).toBe(false)
|
|
})
|
|
|
|
it('should NOT show popup even for latest version', async () => {
|
|
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0'
|
|
const { compareVersions } = await import('@/utils/formatUtil')
|
|
vi.mocked(compareVersions).mockReturnValue(0)
|
|
|
|
expect(store.shouldShowPopup).toBe(false)
|
|
})
|
|
})
|
|
})
|
|
})
|