test(ui): завершить локальную приёмку серверов и мониторинга
This commit is contained in:
1 parent
ddb47a0ee4
commit
3898881d8a
4 files changed
+80
-2
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
// This file runs only via playwright.backend.config.ts; ordinary E2E lock the backend URL.
|
||||
for (const status of [200, 500]) {
|
||||
test(`смена backend: поздний Ping ${status} не меняет новый источник`, async ({ page }) => {
|
||||
let release!: () => void
|
||||
const pending = new Promise<void>(resolve => { release = resolve })
|
||||
const posts: string[] = []
|
||||
await page.route('**/health', route => route.fulfill({ json: { ok: true } }))
|
||||
await page.route('**/api/**', async route => {
|
||||
const request = route.request()
|
||||
const url = new URL(request.url())
|
||||
const isNew = url.port === '8999'
|
||||
if (request.method() === 'POST') {
|
||||
posts.push(url.origin + url.pathname)
|
||||
if (!isNew && url.pathname === '/api/uptime/probes/collect-group') {
|
||||
await pending
|
||||
return route.fulfill({ status, json: status === 200 ? {} : { error: 'Ошибка прежнего backend' } })
|
||||
}
|
||||
}
|
||||
const servers = [{ id: 1, name: isNew ? 'Новый источник' : 'Старый источник', host: '192.0.2.1', type: 'exit-node', enabled: true, country: 'RU', site: 'TEST', status: 'online', wanUplinks: [] }]
|
||||
const probes = [{ id: 'p1', srcServerId: '1', name: isNew ? 'Новая проверка' : 'Старая проверка', target: '192.0.2.10', filter: 'main', rtt: 10, loss: 0, status: 'up', series: [10], enabled: true }]
|
||||
const json = url.pathname === '/api/auth/config' ? { required: false }
|
||||
: url.pathname === '/api/servers' ? servers
|
||||
: url.pathname === '/api/uptime/overview' ? { probes, resources: [] }
|
||||
: url.pathname === '/api/uptime/speed-probes' ? { probes: [] }
|
||||
: url.pathname === '/api/uptime/speed-test/runs' ? { runs: [] }
|
||||
: url.pathname === '/api/evobgp/settings' ? { enabled: false }
|
||||
: {}
|
||||
await route.fulfill({ json })
|
||||
})
|
||||
await page.goto('/uptime?probe=p1')
|
||||
const context = page.getByRole('status', { name: 'Проверка по ссылке' })
|
||||
await expect(context).toContainText('Старая проверка')
|
||||
const started = page.waitForRequest(r => r.url().endsWith('/collect-group'))
|
||||
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(context).toContainText('Новая проверка')
|
||||
const response = page.waitForResponse(r => r.url().includes(':8000/') && r.url().endsWith('/collect-group'))
|
||||
release()
|
||||
await response
|
||||
await expect(context).toContainText('Новая проверка')
|
||||
await expect(page.getByText('Ошибка прежнего backend', { exact: true })).toHaveCount(0)
|
||||
await page.getByRole('button', { name: 'Обновить', exact: true }).click()
|
||||
await expect.poll(() => posts).toEqual([
|
||||
'http://localhost:8000/api/uptime/probes/collect-group',
|
||||
'http://127.0.0.1:8999/api/uptime/probes/collect-group',
|
||||
])
|
||||
await expect(page.getByRole('button', { name: 'Новая проба', exact: true })).toBeEnabled()
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user