'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const MiniLayout = require('../src/miniLayout.js'); const Online = require('../src/online.js'); describe('MiniLayout (t1125)', () => { it('uses sides on a wide desktop and top on a narrow one', () => { const wide = MiniLayout.plan(1280, 900, 2, 70, 8); assert.equal(wide.mode, 'sides', '1280×900 with 2 opponents is sides'); assert.ok(wide.tile >= MiniLayout.MIN_TILE_FOR_SIDES, 'tiles stay large enough'); assert.equal(wide.miniH, 0, 'sides mode does not reserve a top band'); assert.equal(wide.positions.length, 2); const justUnder = MiniLayout.plan(MiniLayout.MIN_VIEWPORT_FOR_SIDES - 1, 900, 2, 70, 8); assert.equal(justUnder.mode, 'top', 'just under 960 px stays on top'); const narrow = MiniLayout.plan(720, 800, 2, 70, 8); assert.equal(narrow.mode, 'top', '720-wide keeps the top row'); assert.ok(narrow.miniH > 0, 'top mode reserves height above the field'); assert.equal(narrow.positions.length, 0); const mobile = MiniLayout.plan(393, 851, 1, 60, 6); assert.equal(mobile.mode, 'top', 'phone stays on the top layout'); }); it('alternates first left, second right, third left, and stacks upward', () => { const plan = MiniLayout.plan(1400, 900, 6, 70, 8); assert.equal(plan.mode, 'sides'); assert.equal(plan.positions.length, 6); const sides = plan.positions.map(p => p.side); assert.deepEqual(sides, ['left', 'right', 'left', 'right', 'left', 'right']); const rows = plan.positions.map(p => p.row); assert.deepEqual(rows, [0, 0, 1, 1, 2, 2]); // Lowest row aligns with (or near) the field bottom; higher rows go up. const lefts = plan.positions.filter(p => p.side === 'left'); assert.ok(lefts[0].y + lefts[0].h <= plan.fieldY + plan.fieldH + 2, 'first row sits at the field bottom'); assert.ok(lefts[1].y < lefts[0].y, 'second row is above the first'); assert.ok(lefts[2].y < lefts[1].y, 'third row is above the second'); // Same x for a column assert.equal(lefts[0].x, lefts[1].x); assert.ok(lefts[0].x + lefts[0].w <= plan.fieldX - MiniLayout.GAP + 0.5); const rights = plan.positions.filter(p => p.side === 'right'); assert.ok(rights[0].x >= plan.fieldX + plan.fieldW + MiniLayout.GAP - 0.5); }); it('shrinks minis so stacked rows stay under the HUD', () => { const plan = MiniLayout.plan(1400, 800, 12, 70, 8); assert.equal(plan.mode, 'sides'); for (const p of plan.positions) { assert.ok(p.y >= 70 + 3, 'mini top stays below the HUD, y=' + p.y); assert.ok(p.canvasH >= 40, 'minis do not shrink below a readable size'); } }); it('solo (n=0) never reserves minis', () => { const plan = MiniLayout.plan(1280, 900, 0, 70, 8); assert.equal(plan.mode, 'top'); assert.equal(plan.miniH, 0); assert.equal(plan.positions.length, 0); }); }); describe('Online flight visuals (t1125)', () => { it('classifies player, enemy, and miss kinds', () => { const orig = Online.playerId; Online.playerId = function () { return 'player'; }; try { assert.equal(Online.flightKind('player', 'bot-1', false), 'player-to-enemy'); assert.equal(Online.flightKind('bot-1', 'player', false), 'enemy-to-player'); assert.equal(Online.flightKind('bot-1', 'bot-2', false), 'enemy-to-enemy'); assert.equal(Online.flightKind('player', null, true), 'player-miss'); assert.equal(Online.flightKind('bot-1', null, true), 'enemy-miss'); assert.equal(Online.flightKind('bot-3', 'player', false), 'enemy-to-player'); } finally { Online.playerId = orig; } }); it('arc is a parabola that peaks at mid-flight above the chord', () => { const start = { x: 0, y: 200 }; const end = { x: 100, y: 200 }; const h = 80; const mid = Online.arcPoint(start, end, 0.5, h); assert.equal(mid.x, 50); // 4*h*t*(1-t) at t=0.5 is h, so y = 200 - 80 assert.equal(mid.y, 120); const a = Online.arcPoint(start, end, 0, h); const b = Online.arcPoint(start, end, 1, h); assert.deepEqual(a, start); assert.deepEqual(b, end); // Symmetric and always above (smaller y) the chord const q1 = Online.arcPoint(start, end, 0.25, h); const q3 = Online.arcPoint(start, end, 0.75, h); assert.equal(q1.y, q3.y); assert.ok(q1.y < 200 && mid.y < q1.y); }); it('arc height scales with distance, clamped', () => { const short = Online.arcHeight({ x: 0, y: 0 }, { x: 10, y: 0 }); const long = Online.arcHeight({ x: 0, y: 0 }, { x: 2000, y: 0 }); assert.equal(short, 48); assert.equal(long, 220); const mid = Online.arcHeight({ x: 0, y: 0 }, { x: 400, y: 0 }); assert.ok(Math.abs(mid - 400 * 0.28) < 1e-9); }); });