47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import {
|
|
connectionAction,
|
|
formatConnectionDuration,
|
|
localProxyUrls,
|
|
subscriptionDomain,
|
|
} from '../../src/web/utils/clientControls.js';
|
|
|
|
test('connection button chooses the only valid client action', () => {
|
|
assert.deepEqual(connectionAction({ connected: true }), { type: 'stop' });
|
|
assert.deepEqual(connectionAction({ selectedTag: 'nl-amsterdam' }), {
|
|
type: 'apply',
|
|
selectedTag: 'nl-amsterdam',
|
|
});
|
|
assert.deepEqual(connectionAction({ configExists: true }), { type: 'restart' });
|
|
assert.equal(connectionAction({}), null);
|
|
});
|
|
|
|
test('connection duration is derived from the backend start time', () => {
|
|
const startedAt = '2026-07-10T10:00:00.000Z';
|
|
const now = Date.parse('2026-07-11T12:03:04.900Z');
|
|
|
|
assert.equal(formatConnectionDuration(startedAt, now), '26:03:04');
|
|
assert.equal(formatConnectionDuration(null, now), '00:00:00');
|
|
});
|
|
|
|
test('saved subscription is reduced to its public domain', () => {
|
|
assert.equal(subscriptionDomain('sub.example.com/…'), 'sub.example.com');
|
|
assert.equal(subscriptionDomain(''), '');
|
|
});
|
|
|
|
test('local proxy exposes both supported URLs', () => {
|
|
assert.deepEqual(localProxyUrls(18080), {
|
|
socks5: 'socks5://127.0.0.1:18080',
|
|
http: 'http://127.0.0.1:18080',
|
|
});
|
|
});
|
|
|
|
test('local proxy defaults to the macOS client port', () => {
|
|
assert.deepEqual(localProxyUrls(), {
|
|
socks5: 'socks5://127.0.0.1:8082',
|
|
http: 'http://127.0.0.1:8082',
|
|
});
|
|
});
|