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']); });