fix(ui): выбирать календарный месяц отчёта потоков

This commit is contained in:
Denozordec committed 2026-09-28 16:54:17 +07:00
1 parent 7a01e8d545
commit 7dd377d7c3
6 files changed
+76 -13

No files matched your search

+40 -4
View File
@@ -9,6 +9,7 @@ async function setup(page: Page) {
await page.route('**/health', r => r.fulfill({ json: { ok: true } }))
await page.route('**/api/**', async route => {
const url = new URL(route.request().url()), path = url.pathname, range = url.searchParams.get('range')
if (path === '/api/traffic/flow/monthly' && control.hold === url.searchParams.get('month')) await gate
if (path === '/api/traffic/flow/monthly') return route.fulfill({ json: { month: url.searchParams.get('month'), bytes: 1500, countries: [{ id: 'RU', label: 'Россия', bytes: 1500, packets: 1, bps: 0, percent: 100 }], services: [], asns: [] } })
if (path === '/api/traffic/flow/analytics') {
if (control.hold === range || (control.holdIface && url.searchParams.get('iface') === control.holdIface)) await gate
@@ -85,7 +86,7 @@ test('Flow: завершённый SSE не помечает последние
test('Flow: месяц показывает только доступные агрегаты и не применяется к клиенту', async ({ page }) => {
await setup(page)
const monthlyRequest = page.waitForRequest(r => r.url().includes('/flow/monthly?'))
await page.getByRole('button', { name: 'Текущий месяц', exact: true }).click()
await page.getByRole('button', { name: 'Месяц', exact: true }).click()
const url = new URL((await monthlyRequest).url())
expect(url.searchParams.get('serverId')).toBe('1')
expect(url.searchParams.get('month')).toMatch(/^\d{4}-\d{2}$/)
@@ -103,7 +104,7 @@ test('Flow: месяц показывает только доступные аг
expect(new URL((await clientRequest).url()).searchParams.get('range')).toBe('1h')
await expect(page.getByLabel('Скорость потоков')).toBeVisible()
await expect(report).toHaveCount(0)
await expect(page.getByRole('button', { name: 'Текущий месяц', exact: true })).toHaveCount(0)
await expect(page.getByRole('button', { name: 'Месяц', exact: true })).toHaveCount(0)
await expect(page.getByRole('switch', { name: 'Без дублей' })).toBeEnabled()
})
@@ -113,10 +114,10 @@ for (const width of [320, 390, 1440]) {
await setup(page)
for (const monthly of [false, true]) {
if (monthly) {
await page.getByRole('button', { name: 'Текущий месяц', exact: true }).click()
await page.getByRole('button', { name: 'Месяц', exact: true }).click()
await expect(page.getByRole('region', { name: 'Месячный отчёт' })).toBeVisible()
}
const button = page.getByRole('button', { name: 'Текущий месяц', exact: true })
const button = page.getByRole('button', { name: 'Месяц', exact: true })
const box = await button.boundingBox()
expect(box).not.toBeNull()
expect(box!.x).toBeGreaterThanOrEqual(0)
@@ -365,3 +366,38 @@ test('Flow: ожидание первого sample использует исто
await expect(receipt).toContainText('Получено (live-поток)')
await expect(receipt.locator('time')).not.toHaveAttribute('datetime', stamp!)
})
test('Flow: выбор месяца игнорирует поздний отчёт и блокирует пустое значение', async ({ page }) => {
const control = await setup(page)
await page.getByRole('button', { name: 'Месяц', exact: true }).click()
const field = page.getByLabel('Месяц отчёта (UTC)', { exact: true })
const report = page.getByRole('region', { name: 'Месячный отчёт' })
await expect(report).toBeVisible()
control.hold = '2026-08'
const old = page.waitForRequest(r => r.url().includes('/flow/monthly?') && r.url().includes('month=2026-08'))
await field.fill('2026-08')
await old
await expect(report).toHaveCount(0)
await field.fill('2026-07')
await expect(report).toContainText('2026-07 (UTC)')
const late = page.waitForResponse(r => r.url().includes('/flow/monthly?') && r.url().includes('month=2026-08'))
control.release()
await late
await expect(report).toContainText('2026-07 (UTC)')
const requests: string[] = []
page.on('request', r => { if (r.url().includes('/flow/monthly?')) requests.push(r.url()) })
await field.fill('')
await expect(field).toHaveAttribute('aria-invalid', 'true')
await expect(page.getByRole('alert').filter({ hasText: 'Выберите существующий месяц' })).toBeVisible()
await expect(report).toHaveCount(0)
await field.fill('2100-01')
await expect(field).toHaveAttribute('aria-invalid', 'true')
expect(requests).toHaveLength(0)
await field.fill('2026-07')
await expect(report).toContainText('2026-07 (UTC)')
await expect(field).toHaveAttribute('aria-invalid', 'false')
await field.focus()
await expect(field).toBeFocused()
await expect(page.getByRole('button', { name: 'Месяц', exact: true })).toHaveAttribute('aria-pressed', 'true')
})