mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-08 17:26:41 +08:00
fix: refresh update status after manual check
This commit is contained in:
@@ -4,6 +4,7 @@ import api from '@/api'
|
||||
import type { ScheduleInfo } from '@/api/types'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useBackground } from '@/composables/useBackground'
|
||||
import { useSystemUpdateStatus } from '@/composables/useSystemUpdateStatus'
|
||||
import {
|
||||
getScheduleName,
|
||||
getScheduleNextRunText,
|
||||
@@ -18,6 +19,7 @@ import { getSchedulerVisual } from '@/utils/schedulerVisual'
|
||||
// 国际化
|
||||
const { t } = useI18n()
|
||||
const { useDataRefresh } = useBackground()
|
||||
const { loadStatus: loadSystemUpdateStatus } = useSystemUpdateStatus()
|
||||
|
||||
// 提示框
|
||||
const $toast = useToast()
|
||||
@@ -79,7 +81,7 @@ function getMobileSchedulerStatusText(scheduler: ScheduleInfo) {
|
||||
return getDisplayedSchedulerStatusText(scheduler)
|
||||
}
|
||||
|
||||
/** 执行指定定时服务,并在请求成功后的短延迟刷新列表。 */
|
||||
/** 执行指定定时服务,并在统一更新检查完成后立即同步全局升级提示。 */
|
||||
async function runCommand(id: string) {
|
||||
try {
|
||||
await api.get('system/runscheduler', {
|
||||
@@ -87,6 +89,7 @@ async function runCommand(id: string) {
|
||||
jobid: id,
|
||||
},
|
||||
})
|
||||
if (id === 'system_update_check') await loadSystemUpdateStatus()
|
||||
$toast.success(t('setting.scheduler.executeSuccess'))
|
||||
setTimeout(() => {
|
||||
loadSchedulerList()
|
||||
|
||||
@@ -19,6 +19,7 @@ const mocks = vi.hoisted(() => ({
|
||||
apiGet: vi.fn(),
|
||||
apiRequests: [] as Promise<unknown>[],
|
||||
removeBackgroundTimer: vi.fn(),
|
||||
loadSystemUpdateStatus: vi.fn(),
|
||||
timerRegistrations: [] as TimerRegistration[],
|
||||
toastSuccess: vi.fn(),
|
||||
}))
|
||||
@@ -58,6 +59,10 @@ vi.mock('vue-toastification', () => ({
|
||||
useToast: () => ({ success: mocks.toastSuccess }),
|
||||
}))
|
||||
|
||||
vi.mock('@/composables/useSystemUpdateStatus', () => ({
|
||||
useSystemUpdateStatus: () => ({ loadStatus: mocks.loadSystemUpdateStatus }),
|
||||
}))
|
||||
|
||||
function deferred<T>() {
|
||||
let reject!: (reason?: unknown) => void
|
||||
let resolve!: (value: T | PromiseLike<T>) => void
|
||||
@@ -105,6 +110,7 @@ describe('ServiceView', () => {
|
||||
beforeEach(() => {
|
||||
mocks.apiGet.mockReset()
|
||||
mocks.apiRequests.length = 0
|
||||
mocks.loadSystemUpdateStatus.mockReset()
|
||||
mocks.removeBackgroundTimer.mockReset()
|
||||
mocks.timerRegistrations.length = 0
|
||||
mocks.toastSuccess.mockReset()
|
||||
@@ -255,6 +261,7 @@ describe('ServiceView', () => {
|
||||
})
|
||||
expect(mocks.toastSuccess).toHaveBeenCalledOnce()
|
||||
expect(mocks.toastSuccess).toHaveBeenCalledWith('定时作业执行请求提交成功!')
|
||||
expect(mocks.loadSystemUpdateStatus).not.toHaveBeenCalled()
|
||||
|
||||
await vi.advanceTimersByTimeAsync(999)
|
||||
expect(listReads).toBe(1)
|
||||
@@ -262,6 +269,24 @@ describe('ServiceView', () => {
|
||||
expect(listReads).toBe(2)
|
||||
})
|
||||
|
||||
it('refreshes the shared update status immediately after the system update check completes', async () => {
|
||||
mocks.apiGet.mockImplementation((endpoint: string) => {
|
||||
if (endpoint === 'dashboard/schedule') {
|
||||
return [schedule({ id: 'system_update_check', name: '检查系统更新' })]
|
||||
}
|
||||
if (endpoint === 'system/runscheduler') return null
|
||||
throw new Error(`Unexpected GET ${endpoint}`)
|
||||
})
|
||||
await renderServiceView()
|
||||
expect(await screen.findAllByText('检查系统更新')).toHaveLength(2)
|
||||
|
||||
await fireEvent.click(executionButtons()[0])
|
||||
await flushMicrotasks()
|
||||
|
||||
expect(mocks.loadSystemUpdateStatus).toHaveBeenCalledOnce()
|
||||
expect(mocks.toastSuccess).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it.each([
|
||||
[
|
||||
'业务失败',
|
||||
|
||||
Reference in New Issue
Block a user