Refactor VPN proxy client implementation
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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/instructions/InstructionsFeature.tsx'), 'utf8');
|
||||
const boundary = fs.readFileSync(path.join(root, 'src/web/features/instructions/index.ts'), 'utf8');
|
||||
const blocks = fs.readFileSync(path.join(root, 'src/web/features/instructions/instructionBlocks.ts'), 'utf8');
|
||||
const prometheus = fs.readFileSync(path.join(root, 'src/web/features/instructions/prometheus.ts'), 'utf8');
|
||||
|
||||
test('instructions feature is the sole owner behind one public boundary', () => {
|
||||
assert.equal(fs.existsSync(path.join(root, 'src/web/instructions.js')), false);
|
||||
assert.equal(fs.existsSync(path.join(root, 'src/web/prometheus.js')), false);
|
||||
assert.match(boundary, /InstructionsPanel,[\s\S]*InstructionsToggle,[\s\S]*useInstructionsFeature/);
|
||||
assert.doesNotMatch(boundary, /instructionBlocks|prometheusScrapeConfig|grafanaDashboardJson/);
|
||||
assert.equal((page.match(/useInstructionsFeature\(/g) || []).length, 1);
|
||||
assert.equal((page.match(/<InstructionsToggle/g) || []).length, 1);
|
||||
assert.equal((page.match(/<InstructionsPanel/g) || []).length, 1);
|
||||
assert.match(page, /from '..\/features\/instructions\/index\.js'/);
|
||||
assert.doesNotMatch(page, /InstructionStep|InstructionBlock|instructionBlocks|openInstructionId|instructionsPanelRef|instructionsToggleRef|instructionsCloseRef|setInstructionsOpen|client-instruction-block/);
|
||||
assert.doesNotMatch(feature, /from ['"][^'"]*\/api(?:\/|\.js)|SubscriptionFeature|RoutingFeature|DevicesFeature|DiagnosticsFeature/);
|
||||
});
|
||||
|
||||
test('unconditional controller and conditional panel preserve lifecycle and reset boundaries', () => {
|
||||
assert.match(page, /const instructionsFeature = useInstructionsFeature\([\s\S]*const diagnosticsAvailable/);
|
||||
assert.match(page, /\{\(isGateway \|\| \(hasSubscription && subscriptionContentReady\)\) && <InstructionsPanel/);
|
||||
assert.match(page, /if \(!hasSubscription\) \{[\s\S]*if \(!isGateway\) \{[\s\S]*instructionsFeature\.close\(\)/);
|
||||
assert.doesNotMatch(page, /if \(!instructionsAvailable\)|instructionsAvailable/);
|
||||
assert.match(feature, /const \[openInstructionId, setOpenInstructionId\] = useState\(''\)/);
|
||||
assert.match(feature, /function InstructionBlock[\s\S]*const \[copyFeedback, setCopyFeedback\] = useState/);
|
||||
assert.match(feature, /clearTimeout\(copyTimer\.current\)[\s\S]*setTimeout\(\(\) => setCopyFeedback\(null\), 800\)/);
|
||||
assert.match(feature, /requestAnimationFrame\(\(\) => closeRef\.current\?\.focus\(\)\)[\s\S]*panelRef\.current\?\.contains[\s\S]*toggleRef\.current\?\.focus\(\)/);
|
||||
assert.match(feature, /addEventListener\('pointerdown', closeOutside\)/);
|
||||
assert.match(feature, /flushSync[\s\S]*prefers-reduced-motion: reduce[\s\S]*document\.startViewTransition\(update\)/);
|
||||
});
|
||||
|
||||
test('private content helpers preserve guide, copy and monitoring contracts', () => {
|
||||
assert.match(page, /const gatewayAddress = isGateway \? window\.location\.hostname : '127\.0\.0\.1'/);
|
||||
assert.match(page, /const controlHost = window\.location\.host \|\| `\$\{gatewayAddress\}:3456`/);
|
||||
assert.match(page, /port: state\?\.clientRuntime\?\.proxyPort \|\| \(isGateway \? 8080 : 8082\)/);
|
||||
assert.match(blocks, /\.\.\.\(isGateway \? \[\{/);
|
||||
assert.match(blocks, /id: 'router'[\s\S]*id: 'prometheus'/);
|
||||
assert.match(blocks, /prometheusScrapeConfig\(controlHost\)[\s\S]*label: 'Grafana dashboard'/);
|
||||
assert.match(prometheus, /\.\.\/\.\.\/\.\.\/\.\.\/monitoring\/grafana\/harbor-gateway\.json/);
|
||||
assert.match(prometheus, /scrape_interval: 30s[\s\S]*scrape_timeout: 3s[\s\S]*metrics_path: \/metrics/);
|
||||
assert.match(feature, /target="_blank" rel="noreferrer"/);
|
||||
assert.match(feature, /client-copy-label">Скопировать/);
|
||||
});
|
||||
Reference in New Issue
Block a user