Files
Robot-Clash/tests/e2e/helpers.js
Michi a494290548 fix(net): interpolate between snapshots to absorb jitter (P1-6)
netfight eased to the newest snapshot with no buffer, so a jittery
client's robot stalled then jumped. Render ~120 ms in the past between
the two bracketing snapshots instead. Dev params ?netlag/?interp/
?netprobe reproduce it; unit test for the interp math + a Playwright
lag test (tests/e2e/netlag.spec.js).
2026-11-19 19:46:54 +01:00

38 lines
1.6 KiB
JavaScript

/* Shared steps for the browser tests: log in through the real UI, get from the workshop into the lobby. */
'use strict';
const { expect } = require('@playwright/test');
const mode = page => page.locator('body').getAttribute('data-mode');
// open the game in online mode and log in with name + password through the login card
async function login(page, name, pass, query = '') {
await page.goto('/?online' + query);
await page.locator('#oLogin').fill(name);
await page.locator('#oPass').fill(pass);
await page.locator('#oGo').click();
await chooseCountry(page);
await expect(page.locator('body')).toHaveAttribute('data-mode', 'garage');
await expect(page.locator('#hUser')).toContainText(name);
}
// first start asks for a country - take the default
async function chooseCountry(page) {
const go = page.locator('#cfGo');
try { await go.waitFor({ timeout: 4000 }); await go.click(); } catch (e) { /* already chosen */ }
}
async function toLobby(page) {
await page.locator('#bLeague').click();
await expect(page.locator('body')).toHaveAttribute('data-mode', 'lobby');
}
// the header shows big amounts short like Kit.fmt does ("10.8K", "1.20M", "3B")
const UNIT = { K: 1e3, M: 1e6, B: 1e9 };
const parseCredits = text => {
const m = String(text).replace(/[,\s]/g, '').match(/([\d.]+)([KMB]?)/i);
return m ? Math.round(parseFloat(m[1]) * (UNIT[(m[2] || '').toUpperCase()] || 1)) : NaN;
};
const credits = async page => parseCredits(await page.locator('#hMoney').textContent());
module.exports = { mode, login, chooseCountry, toLobby, credits, parseCredits };