diff --git a/src/trx-client/trx-frontend/trx-frontend-http/frontend/tests/tune-links.mjs b/src/trx-client/trx-frontend/trx-frontend-http/frontend/tests/tune-links.mjs index 85ab0535..55546f0b 100644 --- a/src/trx-client/trx-frontend/trx-frontend-http/frontend/tests/tune-links.mjs +++ b/src/trx-client/trx-frontend/trx-frontend-http/frontend/tests/tune-links.mjs @@ -27,6 +27,21 @@ const dial = () => page.evaluate(() => ({ path: window.location.pathname, })); +// Typed, not filled. The app holds back its own refreshes of the frequency +// field from the first keystroke until Enter, so that a state update arriving +// mid-edit does not rewrite what is being typed. `fill()` sets the value +// without a keystroke, leaving the field unguarded: on a slow machine a state +// update could land between the fill and the Enter and put the old frequency +// back, and the Enter would then re-apply the frequency the radio was already +// on. Selecting first arms the guard before a single character changes. +async function tuneByHand(text) { + const field = page.locator("#freq"); + await field.click(); + await field.press("ControlOrMeta+a"); + await field.pressSequentially(text); + await field.press("Enter"); +} + try { await page.setViewportSize({ width: 1500, height: 950 }); @@ -49,8 +64,7 @@ try { // Tuning by hand rewrites the link. This is the part that makes the address // bar shareable at any moment rather than only at load. - await page.locator("#freq").fill("7.040M"); - await page.locator("#freq").press("Enter"); + await tuneByHand("7.040M"); await page.waitForTimeout(1500); const tuned = await dial(); assert.equal(tuned.freqHz, TUNED_HZ, `tuning landed on ${tuned.freqHz} Hz`); @@ -59,8 +73,7 @@ try { // Tuning is not navigation: a swept dial must not bury the back button. const historyLength = await page.evaluate(() => window.history.length); - await page.locator("#freq").fill("7.100M"); - await page.locator("#freq").press("Enter"); + await tuneByHand("7.100M"); await page.waitForTimeout(1200); assert.equal(await page.evaluate(() => window.history.length), historyLength, "tuning pushed a history entry instead of replacing one");