opsdash-app/opsdash/test/useVersionOverlay.test.ts
blade34242 01552e2138
All checks were successful
Nextcloud Server Tests / matrix-config (push) Successful in 19s
Build And Publish Appstore Package / build_and_publish (push) Successful in 3m28s
Nextcloud Server Tests / Nextcloud stable31 / PHP 8.2 (stable31, 8.2) (push) Successful in 19m13s
Nextcloud Server Tests / version-consistency (push) Successful in 21s
Nextcloud Server Tests / Nextcloud stable31 / PHP 8.3 (stable31, 8.3) (push) Successful in 18m25s
Nextcloud Server Tests / Nextcloud stable34 / PHP 8.2 (stable34, 8.2) (push) Successful in 17m8s
Nextcloud Server Tests / Nextcloud stable34 / PHP 8.3 (stable34, 8.3) (push) Successful in 16m23s
Nextcloud Server Tests / Nextcloud stable35 / PHP 8.3 (stable35, 8.3) (push) Successful in 17m24s
Nextcloud Server Tests / Nextcloud stable35 / PHP 8.4 (stable35, 8.4) (push) Successful in 16m42s
Nextcloud Server Tests / Nextcloud stable35 / PHP 8.5 (stable35, 8.5) (push) Successful in 17m34s
Nextcloud Server Tests / Nextcloud stable32 / PHP 8.2 (stable32, 8.2) (push) Successful in 17m26s
Nextcloud Server Tests / Nextcloud stable32 / PHP 8.3 (stable32, 8.3) (push) Successful in 16m45s
Nextcloud Server Tests / Nextcloud stable33 / PHP 8.2 (stable33, 8.2) (push) Successful in 17m2s
Nextcloud Server Tests / Nextcloud stable33 / PHP 8.3 (stable33, 8.3) (push) Successful in 16m36s
Release 0.8.5 with Nextcloud 35 support
2026-10-22 11:00:00 +07:00

115 lines
3.7 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { computed, nextTick, ref } from 'vue'
import { useVersionOverlay } from '../composables/useVersionOverlay'
import type { OnboardingState } from '../composables/useDashboard'
describe('useVersionOverlay', () => {
it('opens the current release automatically when it has not been seen', async () => {
const onboardingState = ref<OnboardingState | null>({
completed: true,
version: 1,
strategy: 'total_only',
completed_at: '2026-04-01T00:00:00Z',
releaseNotesSeenVersion: '0.7.4',
})
const overlay = useVersionOverlay({
appVersion: ref('0.7.5'),
onboardingState,
hasInitialLoad: ref(true),
isBlocked: computed(() => false),
route: vi.fn().mockReturnValue('/persist'),
postJson: vi.fn().mockResolvedValue({}),
notifyError: vi.fn(),
})
await nextTick()
expect(overlay.isOpen.value).toBe(true)
expect(overlay.activeEntry.value?.version).toBe('0.7.5')
expect(overlay.entries.value.map((entry) => entry.version)).toEqual(['0.8.5', '0.8.3', '0.8.2', '0.8.1', '0.8.0', '0.7.6', '0.7.5', '0.7.4'])
})
it('marks the current version as seen when the current release closes', async () => {
const onboardingState = ref<OnboardingState | null>({
completed: true,
version: 1,
strategy: 'total_only',
completed_at: '2026-04-01T00:00:00Z',
releaseNotesSeenVersion: '0.7.4',
})
const route = vi.fn().mockReturnValue('/persist')
const postJson = vi.fn().mockResolvedValue({})
const overlay = useVersionOverlay({
appVersion: ref('0.7.5'),
onboardingState,
hasInitialLoad: ref(true),
isBlocked: computed(() => false),
route,
postJson,
notifyError: vi.fn(),
})
await nextTick()
await overlay.closeOverlay()
expect(route).toHaveBeenCalledWith('persist')
expect(postJson).toHaveBeenCalledWith('/persist', {
onboarding: expect.objectContaining({
releaseNotesSeenVersion: '0.7.5',
}),
})
expect(onboardingState.value).toMatchObject({
releaseNotesSeenVersion: '0.7.5',
})
expect(overlay.isOpen.value).toBe(false)
})
it('closes immediately while the seen version is still being saved', async () => {
let finishSave!: (value: unknown) => void
const postJson = vi.fn(() => new Promise(resolve => { finishSave = resolve }))
const overlay = useVersionOverlay({
appVersion: ref('0.8.5'),
onboardingState: ref(null),
hasInitialLoad: ref(true),
isBlocked: computed(() => false),
route: () => '/persist',
postJson,
notifyError: vi.fn(),
})
await nextTick()
expect(overlay.isOpen.value).toBe(true)
const saving = overlay.closeOverlay()
expect(overlay.isOpen.value).toBe(false)
finishSave({})
await saving
expect(overlay.isOpen.value).toBe(false)
})
it('does not mark the current version as seen when browsing an older entry', async () => {
const onboardingState = ref<OnboardingState | null>({
completed: true,
version: 1,
strategy: 'total_only',
completed_at: '2026-04-01T00:00:00Z',
releaseNotesSeenVersion: '',
})
const postJson = vi.fn().mockResolvedValue({})
const overlay = useVersionOverlay({
appVersion: ref('0.7.5'),
onboardingState,
hasInitialLoad: ref(true),
isBlocked: computed(() => false),
route: vi.fn().mockReturnValue('/persist'),
postJson,
notifyError: vi.fn(),
})
await nextTick()
overlay.openVersion('0.7.4')
await overlay.closeOverlay()
expect(postJson).not.toHaveBeenCalled()
expect(onboardingState.value?.releaseNotesSeenVersion).toBe('')
})
})