fix(ui): отклонять повреждённые данные live-потока
This commit is contained in:
1 parent
094c812c37
commit
a03909e504
3 files changed
+40
-11
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { test, expect, type Page } from '@playwright/test'
|
||||
|
||||
async function setup(page: Page) {
|
||||
const control = { hold: '', fail: false, failList: false, release: () => {} }
|
||||
const control = { hold: '', fail: false, failList: false, invalidSample: undefined as unknown, mergeSample: false, release: () => {} }
|
||||
const gate = new Promise<void>(resolve => { control.release = resolve })
|
||||
const card = { id: '1', name: 'Экспортёр тест', subtitle: '', site: 'TEST', country: 'RU', status: 'online', rxNow: 2, txNow: 3, sessions: 1, rxSeries: [1, 2], txSeries: [2, 3], bytes: 200 }
|
||||
const data = { bpsNow: 1000000, bytes: 200, packets: 2, conversations: 1, uniqueSrc: 1, uniqueDst: 1, topProto: 'TCP', rxSeries: [1], txSeries: [2], applications: [], protocols: [], sources: [], destinations: [], interfaces: [], conversationsList: [], ifaces: [], live: false }
|
||||
@@ -14,7 +14,7 @@ async function setup(page: Page) {
|
||||
if (control.fail) return route.fulfill({ status: 500, json: { error: 'Срез временно недоступен' } })
|
||||
return route.fulfill({ json: { ...data, topCategory: 'Категория ' + range } })
|
||||
}
|
||||
if (path === '/api/traffic/flow/live') return route.fulfill({ contentType: 'text/event-stream', body: 'event: sample\ndata: ' + JSON.stringify({ ...data, live: true }) + '\n\n' })
|
||||
if (path === '/api/traffic/flow/live') return route.fulfill({ contentType: 'text/event-stream', body: 'event: sample\ndata: ' + JSON.stringify({ ...data, live: true }) + '\n\n' + (control.invalidSample === undefined ? '' : 'event: sample\ndata: ' + JSON.stringify(control.mergeSample ? { ...data, ...(control.invalidSample as object) } : control.invalidSample) + '\n\n') })
|
||||
if (path === '/api/traffic/flow/exporters' && control.failList) return route.fulfill({ status: 403, json: { error: 'Нет доступа к экспортёрам' } })
|
||||
const json = path === '/api/auth/config' ? { required: false }
|
||||
: path === '/api/traffic/flow/exporters' ? { exporters: [card] }
|
||||
@@ -123,3 +123,25 @@ for (const width of [320, 390, 1440]) {
|
||||
await page.screenshot({ path: `test-results/flow-monthly-${width}.png`, fullPage: true })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
for (const [name, invalid, merge] of [
|
||||
['неполный объект', { uniqueSrc: 1, destinations: [] }, false],
|
||||
['отрицательная скорость', { bpsNow: -1 }, true],
|
||||
['null', null, false],
|
||||
['неверная строка таблицы', { destinations: [null] }, true],
|
||||
['отрицательная серия', { rxSeries: [-1] }, true],
|
||||
] as const) {
|
||||
test('Flow: повреждённый sample — ' + name, async ({ page }) => {
|
||||
const control = await setup(page)
|
||||
await page.getByRole("button", { name: "15м", exact: true }).click()
|
||||
await expect(page.getByText("Категория 15m", { exact: true }).filter({ visible: true })).toBeVisible()
|
||||
control.invalidSample = invalid
|
||||
control.mergeSample = merge
|
||||
await page.getByRole('button', { name: '5м', exact: true }).click()
|
||||
await expect(page.getByText('Некорректные данные live-потока', { exact: true })).toBeVisible()
|
||||
await expect(page.getByText('Последние данные · live недоступен', { exact: true }).filter({ visible: true })).toHaveCount(2)
|
||||
await expect(page.getByLabel('Скорость потоков')).toContainText('1.00 Мбит/с')
|
||||
await expect(page.getByText('live', { exact: true })).toHaveCount(0)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user