mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-04 21:30:06 +08:00
Route frontend and tray node selections through the same backend flow for selection, persistence, state refresh, and connection cleanup. Read the group's previous selection before switching and preserve the original rule of closing only connections whose chains contain that selection. Run optional cleanup in the background and keep its failures separate from successful selection. Remove redundant frontend effects and unused IPC commands, and refresh the proxy view for every successful switch. Refs:32095daf90Refs:bea0dde074
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { expect, it, vi } from 'vitest'
|
|
|
|
import { switchProxyNode } from '@/services/cmds'
|
|
|
|
import { useProxySelection } from './use-proxy-selection'
|
|
|
|
vi.mock('react', () => ({
|
|
useCallback: (callback: unknown) => callback,
|
|
useRef: (current: unknown) => ({ current }),
|
|
}))
|
|
vi.mock('@/services/cmds', () => ({ switchProxyNode: vi.fn() }))
|
|
vi.mock('@/services/notice-service', () => ({ showNotice: { error: vi.fn() } }))
|
|
vi.mock('@/services/query-client', () => ({ revalidateQueries: vi.fn() }))
|
|
|
|
it('requests independent group selections while another group is pending', async () => {
|
|
let finishFirst!: () => void
|
|
vi.mocked(switchProxyNode)
|
|
.mockImplementationOnce(
|
|
() =>
|
|
new Promise((resolve) => {
|
|
finishFirst = () => resolve(null)
|
|
}),
|
|
)
|
|
.mockResolvedValueOnce(null)
|
|
const first = useProxySelection()
|
|
const second = useProxySelection()
|
|
first.select('Group A', 'Node A')
|
|
second.select('Group B', 'Node B', 'Node B')
|
|
await vi.waitFor(() =>
|
|
expect(switchProxyNode).toHaveBeenCalledWith('Group B', 'Node B', true),
|
|
)
|
|
expect(switchProxyNode).toHaveBeenCalledWith('Group A', 'Node A', false)
|
|
expect(switchProxyNode).toHaveBeenCalledTimes(2)
|
|
finishFirst()
|
|
})
|