Skip to content
48 changes: 48 additions & 0 deletions src/platform/updates/common/releaseStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { compare } from 'semver'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'

import type { EntryPath } from '@/platform/onboarding/onboardingTours'
import type { ReleaseNote } from '@/platform/updates/common/releaseService'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useReleaseStore } from '@/platform/updates/common/releaseStore'
Expand Down Expand Up @@ -100,6 +101,15 @@ vi.mock('@vueuse/core', () => ({
createSharedComposable: vi.fn((fn) => fn)
}))

const mocks = vi.hoisted(() => ({
tour: { activeTour: null as EntryPath | null }
}))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
vi.mock('@/platform/onboarding/onboardingTourStore', async () => {
const { reactive } = await import('vue')
mocks.tour = reactive(mocks.tour)
return { useOnboardingTourStore: () => mocks.tour }
})

describe('useReleaseStore', () => {
const mockRelease = {
id: 1,
Expand All @@ -113,6 +123,7 @@ describe('useReleaseStore', () => {
beforeEach(() => {
mockSystemStatsState.reset()
mockData.isCloud = false
mocks.tour.activeTour = null
})

describe('initial state', () => {
Expand Down Expand Up @@ -639,6 +650,43 @@ describe('useReleaseStore', () => {

expect(store.shouldShowPopup).toBe(true)
})

it('withholds the popup while the first-run tour is on screen', () => {
const store = useReleaseStore()
const systemStatsStore = useSystemStatsStore()
const settingStore = useSettingStore()
systemStatsStore.systemStats!.system.comfyui_version = '1.2.0'
vi.mocked(settingStore.get).mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
return null
})
vi.mocked(compare).mockReturnValue(0)

store.releases = [mockRelease]

mocks.tour.activeTour = 'firstRun'
expect(store.shouldShowPopup).toBe(false)

mocks.tour.activeTour = null
expect(store.shouldShowPopup).toBe(true)
})

it('shows the popup during a tour it does not overlap', () => {
const store = useReleaseStore()
const systemStatsStore = useSystemStatsStore()
const settingStore = useSettingStore()
systemStatsStore.systemStats!.system.comfyui_version = '1.2.0'
vi.mocked(settingStore.get).mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
return null
})
vi.mocked(compare).mockReturnValue(0)

store.releases = [mockRelease]
mocks.tour.activeTour = 'appMode'

expect(store.shouldShowPopup).toBe(true)
})
})

describe('edge cases', () => {
Expand Down
7 changes: 7 additions & 0 deletions src/platform/updates/common/releaseStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { compare, valid } from 'semver'
import { computed, ref } from 'vue'

import { isCloud, isDesktop } from '@/platform/distribution/types'
import { useOnboardingTourStore } from '@/platform/onboarding/onboardingTourStore'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useSystemStatsStore } from '@/stores/systemStatsStore'
import { stringToLocale } from '@/utils/formatUtil'
Expand All @@ -22,6 +23,7 @@ export const useReleaseStore = defineStore('release', () => {
const releaseService = useReleaseService()
const systemStatsStore = useSystemStatsStore()
const settingStore = useSettingStore()
const onboardingTourStore = useOnboardingTourStore()

const currentVersion = computed(
() => systemStatsStore?.systemStats?.system?.comfyui_version ?? ''
Expand Down Expand Up @@ -168,6 +170,11 @@ export const useReleaseStore = defineStore('release', () => {
})

const shouldShowPopup = computed(() => {
// Deferred, not dropped: the tour ends and this re-evaluates.
if (onboardingTourStore.activeTour === 'firstRun') {
Comment thread
christian-byrne marked this conversation as resolved.
return false
}

if (!isDesktop && !isCloud) {
return false
}
Expand Down
Loading