Files
dawnline/web/tests/map.test.ts
T
Aemeath 972e522518
Build packages / Version (push) Waiting to run
Dawnline 0.5.0
- Where people connect from is a globe map now: live arcs from each
  person to the server, grey ones for the last 24 h, 7 or 30 days, avatars
  instead of dots, the server's own marker, and a light map in light mode;
  it zooms to fit the people shown and follows them as they come and go
- Markers that overlap move apart with a pointer to their spot; people
  next to the server fold into a count on it; a click zooms in and opens a
  floating card (never clipped by the map), closing flies back
- The person page maps where they connected from, older places fading;
  the device panel lists its places in order, and connections from the LAN
  or through the router's own address stay off the maps ("LAN" in grey)
- Setup and new servers check the UDP port (taken by another program, a
  forward or another server) and the subnet (three numbers + .x, a private
  range not in use) as you type; the default port is 4500
- The personal portal can share the server's port number (TCP beside UDP);
  its port is checked against forwards and other services
- A new server comes up at once: the kernel module is loaded and the
  network restarted when OpenWrt doesn't know AmneziaWG yet
- A turned-off server is a state of its own: no "tunnel down" or DNS
  warnings, "Turned off" in yellow, a white Turn on, and people on it are
  not shown as paused
- Pause everyone is removed: turning a server off does the same (a router
  left paused keeps its servers off after the update)
- People: a stopped person's card fades and says why across its bottom,
  with the one action that lifts it (Resume, +10 GB, Extend 1 month);
  people held by a limit or end date sort below the others, paused last
- The person page shows the state as text ("Paused") with a Resume
  button, also while their server is off
- The portal tells a paused or ended person just that, even with the
  server off, and lets them change nothing until the admin lifts it (the
  router refuses too); its notices look like Overview's
- Automatic MTU: with the field empty the tunnel, computers and routers
  get 1380 minus AmneziaWG S4 (1368 on Maximum), phones and tablets 1280;
  a typed MTU still caps phones and tablets at 1280, and servers on the
  old default 1380 move to automatic (phones and tablets get "Update
  config", their old files keep working)
- Only procd's agent runs: a second copy (started by hand or left over)
  refuses to start or is ended within 5 minutes, so no more stray paused
  and resumed events; a device that leaves the tunnel is offline at once
- The installer picks the newest release (it took the lowest), DNS
  lookups can't hang, and tooltips and floating cards close on scroll and
  on leaving the page
2026-10-17 01:03:23 +03:00

136 lines
3.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { arc, devicePlaces, separate, type MapData } from '../src/admin/map';
describe('arc (mapcn buildArcCoordinates)', () => {
it('runs from one point to the other in 64 steps', () => {
const pts = arc([-0.1276, 51.5074], [-74.006, 40.7128]);
expect(pts).toHaveLength(65);
expect(pts[0]).toEqual([-0.1276, 51.5074]);
expect(pts[64][0]).toBeCloseTo(-74.006);
expect(pts[64][1]).toBeCloseTo(40.7128);
});
it('bends to the left of travel by a fifth of the distance', () => {
// Due east 10°: the control point sits 2° north of the middle, the curve's peak half of that.
const mid = arc([0, 0], [10, 0])[32];
expect(mid[0]).toBeCloseTo(5);
expect(mid[1]).toBeCloseTo(1);
});
it('takes the short way across the antimeridian', () => {
const pts = arc([139.69, 35.69], [-122.42, 37.77]);
expect(pts[pts.length - 1][0]).toBeCloseTo(237.58);
expect(Math.max(...pts.map((p) => Math.abs(p[0] - 139.69)))).toBeLessThan(100);
});
it('is a single point pair when both ends meet', () => {
expect(arc([10, 10], [10, 10])).toEqual([
[10, 10],
[10, 10],
]);
});
});
describe('devicePlaces', () => {
const pt = (city: string, ts: number, online = false, device = 'lap') => ({
person: 'my',
device,
ip: `ip-${city}-${ts}`,
ts,
online,
lat: 0,
lon: 0,
city,
country: '',
cc: 'RU',
asn: 0,
org: '',
});
const now = 100 * 86400;
const data = (points: ReturnType<typeof pt>[]): MapData => ({
geo: { enabled: true, home: null, points } as unknown as MapData['geo'],
people: [],
now,
person: 'my',
device: 'lap',
});
it('puts the live place first and numbers the rest newest first, one per city', () => {
const list = devicePlaces(
data([
pt('Kazan', now - 25 * 86400),
pt('Moscow', now - 7 * 86400),
pt('Moscow', now - 9 * 86400),
pt('Sochi', now - 86400),
pt('Krasnodar', now, true),
pt('Berlin', now - 86400, false, 'phone'),
]),
'30d',
);
expect(list.map((x) => [x.city, x.n])).toEqual([
['Krasnodar', 0],
['Sochi', 1],
['Moscow', 2],
['Kazan', 3],
]);
});
it('keeps to the period', () => {
expect(devicePlaces(data([pt('Kazan', now - 25 * 86400), pt('Sochi', now - 86400)]), '7d').map((x) => x.city)).toEqual(['Sochi']);
});
});
describe('separate', () => {
it('leaves markers that do not touch alone', () => {
expect(
separate([
{ x: 0, y: 0, r: 10 },
{ x: 100, y: 0, r: 10 },
]),
).toEqual([
[0, 0],
[0, 0],
]);
});
it('moves only the free one away from a fixed one, just clear', () => {
const [s, p] = separate([
{ x: 0, y: 0, r: 20, fixed: true },
{ x: 30, y: 0, r: 14 },
]);
expect(s).toEqual([0, 0]);
expect(p[0]).toBeCloseTo(20 + 14 + 6 - 30);
expect(p[1]).toBeCloseTo(0);
});
it('fades to nothing as markers part (no jump)', () => {
const at = (x: number) =>
separate([
{ x: 0, y: 0, r: 20, fixed: true },
{ x, y: 0, r: 14 },
])[1][0];
expect(at(39)).toBeCloseTo(1);
expect(at(39.9)).toBeCloseTo(0.1);
expect(at(40)).toBe(0);
});
it('splits two free markers half each and parts ones on the same spot', () => {
const [a, b] = separate(
[
{ x: 0, y: 0, r: 10 },
{ x: 10, y: 0, r: 10 },
],
0,
);
expect(a[0]).toBeCloseTo(-5);
expect(b[0]).toBeCloseTo(5);
const same = separate(
[
{ x: 0, y: 0, r: 10 },
{ x: 0, y: 0, r: 10 },
{ x: 0, y: 0, r: 10 },
],
0,
);
for (let i = 0; i < 3; i++)
for (let j = i + 1; j < 3; j++) expect(Math.hypot(same[i][0] - same[j][0], same[i][1] - same[j][1])).toBeGreaterThan(19);
});
});