test(ui): проверить трафик после смены источника данных

This commit is contained in:
Denozordec committed 2026-09-24 21:09:39 +07:00
1 parent 2c2a3ef078
commit ee3dcdacf2
2 files changed
+55

No files matched your search

+49
View File
@@ -54,3 +54,52 @@ for (const status of [200, 500]) {
await expect(page.getByRole('button', { name: 'Новая проба', exact: true })).toBeEnabled()
})
}
test('смена backend: поздний список трафика не заменяет новый источник', async ({ page }) => {
let hold = false
let release!: () => void
const gate = new Promise<void>(resolve => { release = resolve })
const refreshOrigins: string[] = []
await page.route('**/health', route => route.fulfill({ json: { ok: true } }))
await page.route('**/api/**', async route => {
const url = new URL(route.request().url())
const isNew = url.port === '8999'
const server = { id: '1', name: isNew ? 'Новый трафик' : 'Старый трафик', site: 'TEST', country: 'RU', status: 'online', rxNow: 2, txNow: 3, rxPeak: 4, txPeak: 5, rxTotal: 100, txTotal: 200, sessions: 1, rxSeries: [1, 2], txSeries: [2, 3] }
if (url.pathname === '/api/traffic/servers') {
if (hold) {
refreshOrigins.push(url.origin)
if (!isNew) await gate
}
return route.fulfill({ json: { servers: [server] } })
}
const json = url.pathname === '/api/auth/config' ? { required: false }
: url.pathname === '/api/traffic/servers/1' ? { server }
: url.pathname.endsWith('/interfaces') || url.pathname === '/api/traffic/bound-interfaces' ? { interfaces: [] }
: url.pathname === '/api/traffic/users' ? { users: [] }
: url.pathname === '/api/servers' ? [] : {}
if (url.pathname.endsWith('/live')) return route.fulfill({ status: 503, json: {} })
return route.fulfill({ json })
})
await page.goto('/traffic')
await expect(page.getByRole('heading', { name: 'Старый трафик', exact: true })).toBeVisible()
hold = true
const started = page.waitForRequest(r => r.url().includes(':8000/api/traffic/servers?'))
await page.getByRole('button', { name: 'Обновить', exact: true }).click()
await started
await page.locator('a[href="/settings"]').first().click()
const backend = page.getByPlaceholder('http://localhost:8000', { exact: true })
await backend.fill('http://127.0.0.1:8999')
await backend.press('Enter')
await page.goBack()
await expect(page.getByRole('heading', { name: 'Новый трафик', exact: true })).toBeVisible()
const late = page.waitForResponse(r => r.url().includes(':8000/api/traffic/servers?'))
release()
await late
await expect(page.getByRole('heading', { name: 'Новый трафик', exact: true })).toBeVisible()
await expect(page.getByRole('button').filter({ hasText: 'Старый трафик' })).toHaveCount(0)
const beforeRefresh = refreshOrigins.length
const fresh = page.waitForResponse(r => r.url().includes(':8999/api/traffic/servers?'))
await page.getByRole('button', { name: 'Обновить', exact: true }).click()
await fresh
expect(refreshOrigins.slice(beforeRefresh)).toEqual(['http://127.0.0.1:8999'])
})