DFiP_Budget_planing/perf/e2e/tests/svod2-metrics.test.ts
Andrey Epifancev 9272ea2527 perf: правки финального ревью фазы 3 (I-4, I-5, M-11, M-13, M-14, T15.2, T17.1, T17.3)
Селектор строк данных свода 2 исключает скелетоны MRT, settle ждёт 0 скелетонов;
first_rows_ms через waitForFunction(raf); счётчики загрузки не пишутся в запись фильтра;
scale_compare различает view/search; api_split не считает строки для facets;
README: порядок до/после и новые метрики.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 00:46:05 +04:00

82 lines
2.6 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
ByteCounter,
placeholderShare,
isSvod2SearchUrl,
svod2RespRe,
countPagesRequested,
filterResultMs,
memoryPoints,
SVOD2_DATA_ROW_SELECTOR,
SVOD2_PLACEHOLDER_SELECTOR,
} from '../lib/svod2.ts';
test('ByteCounter: sheet=max, total=sum, first=sum до markFirstRows', () => {
const c = new ByteCounter();
c.add('a', 10);
c.add('b', 30);
c.markFirstRows();
c.add('c', 20);
assert.equal(c.sheet, 30);
assert.equal(c.total, 60);
assert.equal(c.first, 40);
});
test('ByteCounter: чанки одного запроса суммируются для sheet', () => {
const c = new ByteCounter();
c.add('a', 10);
c.add('a', 15);
assert.equal(c.sheet, 25);
assert.equal(c.total, 25);
});
test('placeholderShare', () => {
assert.equal(placeholderShare([true, false, false, false]), 0.25);
assert.equal(placeholderShare([]), 0);
});
test('isSvod2SearchUrl', () => {
assert.equal(isSvod2SearchUrl('http://h/api/v1/svod/2/GO/2026?view=compact&search=1'), true);
assert.equal(isSvod2SearchUrl('http://h/api/v1/svod/2/GO/2026?view=compact'), false);
assert.equal(isSvod2SearchUrl('http://h/api/v1/svod/1/GO/2026?search=1'), false);
});
test('svod2RespRe', () => {
const re = svod2RespRe('GO');
assert.ok(re.test('http://h/api/v1/svod/2/GO/2026?offset=0'));
assert.ok(re.test('http://h/api/v1/svod/2/GO/2026/facets'));
assert.ok(!re.test('http://h/api/v1/svod/2/RF/2026'));
});
test('countPagesRequested', () => {
assert.equal(
countPagesRequested([
'http://h/api/v1/svod/2/GO/2026?offset=0&limit=100',
'http://h/api/v1/svod/2/GO/2026?limit=100&offset=100',
'http://h/api/v1/svod/2/GO/2026/facets',
]),
2,
);
});
test('селекторы', () => {
assert.equal(SVOD2_DATA_ROW_SELECTOR, 'tbody tr:not([data-svod2-placeholder]):not(:has(.MuiSkeleton-root))');
assert.equal(SVOD2_PLACEHOLDER_SELECTOR, 'tbody tr[data-svod2-placeholder]');
});
test('filterResultMs: нет запроса поиска - только стабилизация', () => {
assert.equal(filterResultMs(1000, 1700, null), 700);
assert.equal(filterResultMs(1000, 1700, 1200), 700);
assert.equal(filterResultMs(1000, 1700, 1900), 900);
});
test('memoryPoints: по умолчанию go, rf, final', () => {
assert.deepEqual(memoryPoints({}), ['go', 'rf', 'final']);
assert.deepEqual(memoryPoints({ PERF_SVOD2_MEM_SCROLL: '0' }), ['go', 'rf', 'final']);
});
test('memoryPoints: PERF_SVOD2_MEM_SCROLL=1 добавляет rf_scrolled', () => {
assert.deepEqual(memoryPoints({ PERF_SVOD2_MEM_SCROLL: '1' }), ['go', 'rf', 'rf_scrolled', 'final']);
});