mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-03 05:22:09 +08:00
fix(service): adopt IPC 2.7.3 and correct dev fallback handling
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { useState } from 'react'
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { RunState } from '@/services/cmds'
|
||||
import { useQuery } from '@/services/query-client'
|
||||
|
||||
import { ServiceMigrationDialog } from './service-migration-dialog'
|
||||
|
||||
vi.mock('react', () => ({ useState: vi.fn() }))
|
||||
vi.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({ t: (key: string) => key }),
|
||||
}))
|
||||
vi.mock('@mui/material', () => ({ Alert: 'div' }))
|
||||
vi.mock('@/components/base', () => ({ BaseDialog: 'dialog' }))
|
||||
vi.mock('@/hooks/use-visibility', () => ({ useVisibility: () => true }))
|
||||
vi.mock('@/hooks/use-system-state', () => ({ runStateQueryKey: ['state'] }))
|
||||
vi.mock('@/services/cmds', () => ({ getRuntimeState: vi.fn() }))
|
||||
vi.mock('@/services/notice-service', () => ({ showNotice: {} }))
|
||||
vi.mock('@/services/query-client', () => ({
|
||||
useQuery: vi.fn(),
|
||||
setCacheData: vi.fn(),
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
vi.mocked(useState)
|
||||
.mockReturnValueOnce([false, vi.fn()])
|
||||
.mockReturnValueOnce([false, vi.fn()])
|
||||
.mockReturnValueOnce([true, vi.fn()])
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ service: 'ready', mode: 'NotRunning' },
|
||||
{ service: 'unknown', mode: 'NotRunning' },
|
||||
{ service: 'unavailable', mode: 'Service' },
|
||||
{ service: 'unavailable', mode: 'NotRunning', opInFlight: true },
|
||||
{ service: 'unavailable', mode: 'NotRunning', pendingAction: 'reinstall' },
|
||||
] satisfies Partial<RunState>[])(
|
||||
'does not offer Sidecar continuation from %j',
|
||||
(state) => {
|
||||
vi.mocked(useQuery).mockReturnValue({ data: state } as ReturnType<
|
||||
typeof useQuery
|
||||
>)
|
||||
const dialog = ServiceMigrationDialog()
|
||||
expect(dialog.props.open).toBe(true)
|
||||
expect(dialog.props.disableCancel).toBe(true)
|
||||
},
|
||||
)
|
||||
|
||||
it.each([
|
||||
{ service: 'notInstalled', mode: 'NotRunning' },
|
||||
{ service: 'versionMismatch', mode: 'NotRunning' },
|
||||
{ service: 'unavailable', mode: 'NotRunning' },
|
||||
{ service: 'notInstalled', mode: 'Sidecar', pendingAction: 'install' },
|
||||
] satisfies Partial<RunState>[])(
|
||||
'offers Sidecar continuation from %j',
|
||||
(state) => {
|
||||
vi.mocked(useQuery).mockReturnValue({ data: state } as ReturnType<
|
||||
typeof useQuery
|
||||
>)
|
||||
expect(ServiceMigrationDialog().props.disableCancel).toBe(false)
|
||||
},
|
||||
)
|
||||
@@ -44,7 +44,24 @@ export const ServiceMigrationDialog = () => {
|
||||
? 'install'
|
||||
: 'reinstall'
|
||||
const open = loading || workflowIncomplete || needsDecision
|
||||
const showCheckingMessage = loading || !needsDecision
|
||||
const checking =
|
||||
loading ||
|
||||
!runState ||
|
||||
runState.opInFlight ||
|
||||
runState.service === 'unknown'
|
||||
const showCheckingMessage = checking || !needsDecision
|
||||
const canContinue = Boolean(
|
||||
runState &&
|
||||
!stateRefreshFailed &&
|
||||
(runState.pendingAction === 'install'
|
||||
? runState.mode === 'NotRunning' || runState.mode === 'Sidecar'
|
||||
: !runState.pendingAction &&
|
||||
!runState.sidecarAllowed &&
|
||||
runState.mode === 'NotRunning' &&
|
||||
(runState.service === 'notInstalled' ||
|
||||
runState.service === 'versionMismatch' ||
|
||||
runState.service === 'unavailable')),
|
||||
)
|
||||
|
||||
// One cache entry to refresh, so there is nothing left to keep coherent by hand.
|
||||
const refreshRunState = async () => {
|
||||
@@ -165,8 +182,8 @@ export const ServiceMigrationDialog = () => {
|
||||
: 'layout.components.serviceMigration.reinstall',
|
||||
)}
|
||||
cancelBtn={t('layout.components.serviceMigration.continueSidecar')}
|
||||
disableOk={loading}
|
||||
disableCancel={loading}
|
||||
disableOk={checking}
|
||||
disableCancel={checking || !canContinue}
|
||||
loading={loading}
|
||||
onOk={() => void handleServiceAction()}
|
||||
onCancel={() => void handleContinue()}
|
||||
|
||||
Reference in New Issue
Block a user