test(ui): проверить ожидание первого сообщения SSE

This commit is contained in:
Denozordec committed 2026-09-28 16:49:56 +07:00
1 parent 88a8b5f02f
commit 7a01e8d545
6 files changed
+55 -8

No files matched your search

+18 -2
View File
@@ -1,7 +1,7 @@
import { installOpenLiveStream, resumeLiveStream, sendLiveHeartbeat } from "./live-stream-fixture"
import { test, expect } from '@playwright/test'
for (const variant of ['closed', 'invalid', 'http-error', 'silent'] as const) {
for (const variant of ['closed', 'invalid', 'http-error', 'silent', 'awaiting'] as const) {
test(`Трафик: SSE ${variant} не выдаёт старое измерение за live`, async ({ page }) => {
const server = { id: '1', name: 'Тестовый сервер', site: 'TEST', country: 'RU', status: 'online', rxNow: 2, txNow: 3, rxPeak: 5, txPeak: 6, rxTotal: 100, txTotal: 200, sessions: 1, rxSeries: [1, 2], txSeries: [2, 3] }
await page.route('**/health', route => route.fulfill({ json: { ok: true } }))
@@ -23,12 +23,28 @@ for (const variant of ['closed', 'invalid', 'http-error', 'silent'] as const) {
: path === '/api/servers' ? [] : {}
return route.fulfill({ json })
})
if (variant === 'silent') await installOpenLiveStream(page, '/api/traffic/servers/1/live', { rxMbps: 17, txMbps: 19, at: '2026-09-23T12:00:00Z' })
if (variant === 'silent' || variant === 'awaiting') await installOpenLiveStream(page, '/api/traffic/servers/1/live', { rxMbps: 17, txMbps: 19, at: '2026-09-23T12:00:00Z' }, variant !== 'awaiting')
const received = new Date('2026-09-28T06:00:00Z')
await page.clock.setFixedTime(received)
await page.goto('/traffic')
const summary = page.getByLabel('Скорость выбранного сервера')
await expect(summary).toBeVisible()
if (variant === 'awaiting') {
const measurement = page.getByLabel('Последнее измерение сервера')
await expect(summary.getByText('История · ожидание live', { exact: true }).filter({ visible: true })).toHaveCount(2)
await expect(measurement).toHaveCount(0)
await expect(summary).not.toContainText('17.0')
await page.clock.fastForward(10_000)
await sendLiveHeartbeat(page)
await page.clock.fastForward(5_001)
await expect(summary.getByText('История · live недоступен', { exact: true }).filter({ visible: true })).toHaveCount(2)
await expect(measurement).toHaveCount(0)
await resumeLiveStream(page)
await expect(summary.getByText('live', { exact: true }).filter({ visible: true })).toHaveCount(2)
await expect(summary).toContainText('17.0')
await expect(measurement).toBeVisible()
return
}
if (variant === 'silent') {
await expect(summary.getByText('live', { exact: true }).filter({ visible: true })).toHaveCount(2)
const stamp = await page.getByLabel('Последнее измерение сервера').locator('time').first().getAttribute('datetime')