From 36460824ee8c4b8164f3526c45e292c856e5db7f Mon Sep 17 00:00:00 2001 From: L4XB Date: Fri, 25 Sep 2026 03:13:18 +0200 Subject: [PATCH] test(control-pane): pin that a late response keeps its hands off newer data Two held refreshes complete in reverse order with different data. The older response arrives last and must not replace what the newer one put on the board. It did before the previous commit. --- tests/lib/control-pane-ui.test.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/lib/control-pane-ui.test.js b/tests/lib/control-pane-ui.test.js index 14809b96b..7e8f73e63 100644 --- a/tests/lib/control-pane-ui.test.js +++ b/tests/lib/control-pane-ui.test.js @@ -40,7 +40,7 @@ class PageDate extends Date { // Runs the page script against a stand-in for the few browser APIs it uses: // elements looked up by selector, fetch, a fixed clock, and a setInterval // whose callback the test fires itself. While `hold` is set, a fetch waits in -// `pending` until the test settles it. +// `pending` until the test settles it, with the page's snapshot or another one. function openPage(snapshot) { const elements = new Map(); const element = selector => { @@ -67,7 +67,7 @@ function openPage(snapshot) { fetch: () => new Promise((resolve, reject) => { const reply = { - succeed: () => resolve({ ok: true, status: 200, statusText: 'OK', json: async () => snapshot }), + succeed: (data = snapshot) => resolve({ ok: true, status: 200, statusText: 'OK', json: async () => data }), fail: () => reject(new TypeError('Failed to fetch')) }; if (page.hold) page.pending.push(reply); @@ -200,6 +200,25 @@ async function runTests() { passed++; else failed++; + if ( + await test('an older response that arrives after a newer one does not replace its data', async () => { + const page = openPage(snapshot); + await settle(); + const answer = query => ({ ...snapshot, knowledge: { ...snapshot.knowledge, query } }); + + page.hold = true; + page.refresh(); + page.refresh(); + page.pending[1].succeed(answer('newer')); + await settle(); + page.pending[0].succeed(answer('older')); + await settle(); + assert.strictEqual(page.element('#query').value, 'newer'); + }) + ) + passed++; + else failed++; + console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); process.exit(failed > 0 ? 1 : 0); }