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.
This commit is contained in:
L4XB
2026-09-25 03:13:18 +02:00
parent 928a295247
commit 36460824ee
+21 -2
View File
@@ -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);
}