Files
harbor-net/test/web/failover-feature-contract.test.js
T
dokril 1ee453b3b6
Build and Deploy Gateway / build-and-push (push) Successful in 26s
Build and Deploy Gateway / deploy (push) Successful in 7s
Add failover setting step controls
2026-08-20 01:55:50 +03:00

74 lines
6.5 KiB
JavaScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
const root = path.resolve(import.meta.dirname, '../..');
const page = fs.readFileSync(path.join(root, 'src/web/components/ClientOverviewPage.tsx'), 'utf8');
const feature = fs.readFileSync(path.join(root, 'src/web/features/failover/FailoverFeature.tsx'), 'utf8');
const styles = fs.readFileSync(path.join(root, 'src/web/styles/features/failover.css'), 'utf8');
test('reserve is a Gateway-only drawer immediately after subscriptions', () => {
assert.match(page, /<SubscriptionToggle[\s\S]*\{isGateway && <FailoverToggle[\s\S]*<InstructionsToggle/);
assert.match(page, /\{isGateway && hasSubscription && <FailoverPanel/);
assert.match(page, /DRAWER_ORDER = \['subscription', 'failover'/);
assert.match(feature, /label="Резерв"/);
assert.match(feature, /Уже открытые соединения Harbor не закрывает/);
});
test('failover settings use Harbor switches, a two-column channel table and plain-language controls', () => {
assert.match(feature, /client-failover-heading[\s\S]*<h2>Резервный канал<\/h2>[\s\S]*<HarborSwitch/);
assert.match(feature, /role="switch"[\s\S]*aria-checked=\{checked\}/);
assert.doesNotMatch(feature, /type="checkbox"|<select/);
assert.match(feature, /\['primary', 'reserve'\][\s\S]*client-failover-\$\{channel\}-options[\s\S]*updateTarget\(channel, optionId\)/);
assert.match(feature, /channelLabel[\s\S]*profile\.trim\(\) === server\.trim\(\)[\s\S]*`\$\{profile} · \$\{server}`/);
assert.match(feature, /client-failover-channels[\s\S]*<article className="client-failover-channel"[\s\S]*<h3>\{channel === 'primary' \? 'Основной' : 'Резервный'}/);
assert.match(feature, /snapshot\.reason === 'checking-channels'[\s\S]*Проверяется \{checkingRole === 'primary' \? 'основной' : 'резервный'} канал/);
assert.match(feature, /ArrowDown[\s\S]*Home[\s\S]*End[\s\S]*Escape/);
assert.match(feature, /role="listbox"[\s\S]*role="option"/);
assert.match(feature, /Проверка доступности[\s\S]*открывает эти адреса через оба канала/);
assert.match(feature, /before="Ждать ответ не дольше"[\s\S]*min=\{2}[\s\S]*max=\{30}/);
assert.match(feature, /Проверять каналы каждые[\s\S]*Считать основной недоступным после[\s\S]*Вернуться на основной после/);
assert.match(feature, /Не переключать во время активной работы[\s\S]*Переключать после[\s\S]*без активной передачи данных[\s\S]*Считать работу активной при скорости от/);
assert.match(feature, /Когда переключать канал[\s\S]*сначала подтверждает сбой[\s\S]*Защита от частых переключений[\s\S]*остаётся на резервном/);
assert.match(feature, /client-failover-number-input[\s\S]*Math\.max\(2, String\(value\)\.length \+ 0\.6\)/);
assert.match(feature, /client-failover-number-steps[\s\S]*уменьшить на[\s\S]*увеличить на/);
assert.match(feature, /before="Ждать ответ не дольше"[\s\S]*step=\{1\}/);
assert.doesNotMatch(feature, /advancedOpen|advancedClosing|toggleAdvanced|aria-controls="client-failover-advanced-options"/);
assert.match(feature, /label="Добавить проверку"/);
assert.match(feature, /Новый HTTPS-сервис…/);
assert.match(feature, /Убрать проверку:/);
assert.match(feature, /client-failover-remove-lid/);
assert.match(feature, /finishRemoveCheck/);
assert.match(feature, /startViewTransition/);
assert.match(feature, /onInput=\{pulseNumber\}/);
assert.doesNotMatch(feature, /<details|<summary|Нет данных|текущий канал вне настроенной пары/);
assert.doesNotMatch(page, /Текущий канал вне резервной пары/);
assert.match(page, /Резерв применится после перезапуска VPN/);
assert.match(feature, /Приостановить автоматику[\s\S]*Проверить основной и резервный[\s\S]*Переключить новые соединения на/);
assert.match(feature, /beforeunload/);
assert.match(styles, /\.client-failover-switch\[aria-checked='true'\][\s\S]*translateX\(22px\)/);
assert.match(styles, /\.client-failover-heading \{[^}]*justify-content:\s*space-between[^}]*}/);
assert.doesNotMatch(styles, /\.client-failover-heading \{[^}]*padding-right/);
assert.match(styles, /\.client-failover-channels \{[^}]*grid-template-columns:\s*repeat\(2, minmax\(0, 1fr\)\)/);
assert.match(styles, /@media \(max-width: 560px\)[\s\S]*\.client-failover-channels \{ grid-template-columns:\s*minmax\(0, 1fr\)/);
assert.match(styles, /\.client-failover-picker-list[\s\S]*opacity:\s*0[\s\S]*\.client-failover-picker\.is-open[\s\S]*opacity:\s*1/);
assert.match(styles, /failover-service-out 300ms[\s\S]*@media \(prefers-reduced-motion: reduce\)/);
assert.match(styles, /\.client-failover-number-setting \{[^}]*display:\s*flex[^}]*flex-wrap:\s*wrap/);
assert.match(styles, /\.client-failover-number-setting input \{[^}]*border:\s*0[^}]*text-align:\s*center[^}]*appearance:\s*textfield/);
assert.match(styles, /input::\-webkit-inner-spin-button[\s\S]*input::\-webkit-outer-spin-button[^}]*\-webkit-appearance:\s*none/);
assert.match(styles, /\.client-failover-number-steps \{[^}]*display:\s*inline-flex/);
assert.doesNotMatch(styles, /client-failover-advanced|failover-advanced-in|failover-advanced-out/);
});
test('runtime status keeps fixed geometry and explains active traffic without motion dependence', () => {
assert.match(feature, /Ждём завершения активной работы/);
assert.match(feature, /Активный трафик ·[\s\S]*transmittingConnections/);
assert.match(feature, /activity\?\.blockers\.slice\(0, 2\)\.map/);
assert.match(feature, /Ещё \{activity\.blockers\.length - 2\}/);
assert.match(feature, /Нестабилен ·[\s\S]*Следующее решение не раньше чем через/);
assert.match(feature, /switchRole && snapshot\.enabled && snapshot\.activation === 'active'/);
assert.match(styles, /\.client-failover-runtime \{[^}]*min-height:\s*132px/);
assert.match(styles, /@media \(prefers-reduced-motion: reduce\)[\s\S]*transition:\s*none/);
});