mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-18 09:52:13 +08:00
* feat(tray): add a per-group latency test The tray's proxy group submenus offered no way to test a group: refreshing the delays shown there meant opening the dashboard and running a test from the proxy page. Add a "Test Latency" entry at the head of each group submenu. It measures the group through the proxy page's own view, so member resolution and provider attribution match the page exactly: provider nodes are health checked on their provider, anything else goes through the proxy delay endpoint, and members the page cannot resolve are skipped. Nested groups are therefore tested through their currently selected node, as the page does. The menu is rebuilt when the run finishes. The test URL follows the page's chain -- the group's own test URL, then the configured default, then the built-in one -- including the page's validity check, so a group with a malformed URL falls back where the page falls back. A group test started from the app rebuilds the tray as well, so the two views do not drift. Co-Authored-By: Claude <noreply@anthropic.com> * fix(tray): keep latency tests and displayed results consistent * fix(tray): isolate latency histories and preserve usable menus * fix(tray): keep settings usable when proxy reads fail * fix(tray): show selected node latency for proxy groups and display timeouts as T/O Co-authored-by: wonfen <eiwonfen@gmail.com> * fix(tray): refresh proxy latency on menu interaction --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: wonfen <eiwonfen@gmail.com>
104 lines
3.4 KiB
TypeScript
104 lines
3.4 KiB
TypeScript
import { afterEach, expect, test, vi } from 'vitest'
|
|
|
|
vi.mock('@/services/cmds', () => ({
|
|
getProfiles: vi.fn(),
|
|
patchProfile: vi.fn().mockResolvedValue(undefined),
|
|
syncTrayProxySelection: vi.fn().mockResolvedValue(undefined),
|
|
}))
|
|
vi.mock('@/services/query-client', () => ({ revalidateQueries: vi.fn() }))
|
|
vi.mock('@/services/notice-service', () => ({ showNotice: { error: vi.fn() } }))
|
|
|
|
import {
|
|
getProfiles,
|
|
patchProfile,
|
|
syncTrayProxySelection,
|
|
} from '@/services/cmds'
|
|
import { revalidateQueries } from '@/services/query-client'
|
|
|
|
import {
|
|
profileTestUrls,
|
|
saveProfileTestUrls,
|
|
commitProfileTestUrl,
|
|
} from './proxy-test-url'
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
test('committed edits retain their profile and merge with fresh saved URLs', async () => {
|
|
vi.mocked(getProfiles).mockResolvedValue({
|
|
current: 'new-profile',
|
|
items: [
|
|
{
|
|
uid: 'old-profile',
|
|
latency_test_urls: { untouched: 'https://example.com/' },
|
|
},
|
|
],
|
|
})
|
|
await commitProfileTestUrl('old-profile', 'A', ' http://localhost/new ')
|
|
expect(patchProfile).toHaveBeenCalledExactlyOnceWith('old-profile', {
|
|
latency_test_urls: {
|
|
untouched: 'https://example.com/',
|
|
A: 'http://localhost/new',
|
|
},
|
|
})
|
|
expect(revalidateQueries).toHaveBeenCalledWith([['getProfiles']])
|
|
expect(syncTrayProxySelection).toHaveBeenCalledOnce()
|
|
})
|
|
|
|
test('migration cannot overwrite a previously saved or cleared override', async () => {
|
|
vi.mocked(getProfiles).mockResolvedValue({
|
|
items: [{ uid: 'p', latency_test_urls: { A: '' } }],
|
|
})
|
|
await saveProfileTestUrls('p', { A: 'http://localhost/stale' }, true)
|
|
expect(patchProfile).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('pending edits survive a reload and older save acknowledgements', async () => {
|
|
vi.useFakeTimers()
|
|
const profile = {
|
|
uid: 'pending-profile',
|
|
latency_test_urls: { A: 'http://localhost/old' },
|
|
}
|
|
vi.mocked(getProfiles).mockResolvedValue({ items: [profile] })
|
|
let finish!: () => void
|
|
vi.mocked(patchProfile).mockImplementationOnce(
|
|
() =>
|
|
new Promise<void>((resolve) => {
|
|
finish = resolve
|
|
}),
|
|
)
|
|
const first = commitProfileTestUrl(profile.uid, 'A', 'http://localhost/new')
|
|
expect(profileTestUrls(profile).A).toBe('http://localhost/new')
|
|
await vi.advanceTimersByTimeAsync(300)
|
|
expect(profileTestUrls(profile).A).toBe('http://localhost/new')
|
|
const second = commitProfileTestUrl(
|
|
profile.uid,
|
|
'A',
|
|
'http://localhost/newest',
|
|
)
|
|
finish()
|
|
await first
|
|
expect(profileTestUrls(profile).A).toBe('http://localhost/newest')
|
|
await second
|
|
expect(patchProfile).toHaveBeenLastCalledWith(profile.uid, {
|
|
latency_test_urls: { A: 'http://localhost/newest' },
|
|
})
|
|
})
|
|
|
|
test('a failed save preserves the committed input across profile refreshes', async () => {
|
|
const profile = {
|
|
uid: 'failed-profile',
|
|
latency_test_urls: { A: 'http://localhost/old' },
|
|
}
|
|
vi.mocked(getProfiles).mockResolvedValue({ items: [profile] })
|
|
vi.mocked(patchProfile).mockRejectedValueOnce(new Error('save failed'))
|
|
const log = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
await commitProfileTestUrl(profile.uid, 'A', 'http://localhost/new')
|
|
expect(profileTestUrls(profile).A).toBe('http://localhost/new')
|
|
await commitProfileTestUrl(profile.uid, 'A', 'http://localhost/new')
|
|
expect(profileTestUrls(profile).A).toBe('http://localhost/old')
|
|
log.mockRestore()
|
|
})
|