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