|
|
|
|
@ -141,24 +141,54 @@ function assertQuiet(test) {
|
|
|
|
|
assert.equal(test.nodes.list.replacements, renders, 'Server generation timestamps alone do not redraw content.');
|
|
|
|
|
assert.equal(test.nodes.scroll.scrollWrites, scrollWrites, 'Unchanged data must not move the scroll position.');
|
|
|
|
|
await test.click('close'); await test.advance(90000); assert.equal(test.requests.length, 2);
|
|
|
|
|
await test.click('open'); assert.equal(test.requests.length, 2, 'Reopening a loaded drawer uses its snapshot.');
|
|
|
|
|
await test.advance(30000); assert.equal(test.requests.length, 3);
|
|
|
|
|
const snapshot = test.nodes.list.textContent; const readTime = test.nodes['read-time'].textContent;
|
|
|
|
|
await test.click('open'); assert.equal(test.requests.length, 3, 'Reopening immediately revalidates the existing snapshot.');
|
|
|
|
|
assert.equal(test.nodes.list.textContent, snapshot); assert.equal(test.nodes['read-time'].textContent, readTime);
|
|
|
|
|
assert.equal(test.nodes.refresh.disabled, false); assert.equal(test.nodes.list.getAttribute('aria-busy'), 'false'); assertQuiet(test);
|
|
|
|
|
await test.click('open'); await test.click('refresh');
|
|
|
|
|
assert.equal(test.requests.length, 3, 'Repeated clicks while refresh is pending do not create concurrent requests.');
|
|
|
|
|
await test.advance(5000); await test.respond(page([unsafe]));
|
|
|
|
|
assert.equal(test.nodes['read-time'].textContent, '读取于 06:30:55');
|
|
|
|
|
assert.equal(test.nodes.list.replacements, renders); assert.equal(test.nodes.scroll.scrollWrites, scrollWrites); assertQuiet(test);
|
|
|
|
|
await test.advance(29999); assert.equal(test.requests.length, 3, 'Polling resumes thirty seconds after completion, not opening.');
|
|
|
|
|
await test.advance(1); assert.equal(test.requests.length, 4);
|
|
|
|
|
await test.respond(page([announcement(1, { body: '已更新' })]));
|
|
|
|
|
assert.match(test.nodes.list.textContent, /已更新/); assert.equal(test.nodes.scroll.scrollTop, 173); assertQuiet(test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty responses are valid snapshots, not a reason to refetch on every opening.
|
|
|
|
|
// Empty responses remain visible snapshots while reopening silently revalidates them.
|
|
|
|
|
{
|
|
|
|
|
const test = fixture(); await test.click('open'); await test.respond(page([]));
|
|
|
|
|
assert.match(test.nodes.list.textContent, /暂无已发布/); assertQuiet(test);
|
|
|
|
|
await test.click('close'); await test.click('open'); assert.equal(test.requests.length, 1);
|
|
|
|
|
await test.advance(30000); await test.respond(page([])); assert.equal(test.requests.length, 2); assertQuiet(test);
|
|
|
|
|
const renders = test.nodes.list.replacements;
|
|
|
|
|
await test.click('close'); await test.click('open'); assert.equal(test.requests.length, 2);
|
|
|
|
|
assert.match(test.nodes.list.textContent, /暂无已发布/); assert.equal(test.nodes.refresh.disabled, false); assertQuiet(test);
|
|
|
|
|
await test.respond(page([])); assert.equal(test.nodes.list.replacements, renders); assertQuiet(test);
|
|
|
|
|
await test.advance(30000); await test.respond(page([announcement(1)]));
|
|
|
|
|
assert.equal(articles(test).length, 1);
|
|
|
|
|
await test.advance(30000); await test.respond(page([]));
|
|
|
|
|
assert.equal(articles(test).length, 0); assert.match(test.nodes.list.textContent, /暂无已发布/); assertQuiet(test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A fast close aborts an opening refresh; reopening can complete before its late response.
|
|
|
|
|
{
|
|
|
|
|
const test = fixture(); await test.click('open'); await test.respond(page([announcement(1)]));
|
|
|
|
|
const readTime = test.nodes['read-time'].textContent;
|
|
|
|
|
await test.click('close'); await test.click('open'); assert.equal(test.requests.length, 2);
|
|
|
|
|
const cancelled = test.requests.at(-1); await test.click('close');
|
|
|
|
|
assert.equal(cancelled.options.signal.aborted, true);
|
|
|
|
|
await test.advance(1000); await test.click('open'); assert.equal(test.requests.length, 3);
|
|
|
|
|
assert.equal(test.nodes['read-time'].textContent, readTime); assertQuiet(test);
|
|
|
|
|
await test.respond(page([announcement(2)]), 200, test.requests.at(-1));
|
|
|
|
|
assert.equal(articles(test)[0].dataset.announcementId, '2');
|
|
|
|
|
assert.equal(test.nodes['read-time'].textContent, '读取于 06:27:21');
|
|
|
|
|
const renders = test.nodes.list.replacements;
|
|
|
|
|
await test.advance(1000); await test.respond(page([announcement(3)]), 200, cancelled);
|
|
|
|
|
assert.equal(articles(test)[0].dataset.announcementId, '2');
|
|
|
|
|
assert.equal(test.nodes['read-time'].textContent, '读取于 06:27:21');
|
|
|
|
|
assert.equal(test.nodes.list.replacements, renders); assertQuiet(test);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Only a complete successful read updates the independent timestamp, never status text.
|
|
|
|
|
{
|
|
|
|
|
const test = fixture(); const readTime = test.nodes['read-time'];
|
|
|
|
|
@ -284,12 +314,12 @@ function assertQuiet(test) {
|
|
|
|
|
const closeRequest = test.requests.at(-1); await test.click('close');
|
|
|
|
|
assert.equal(closeRequest.options.signal.aborted, true);
|
|
|
|
|
await test.advance(90000); assert.equal(test.requests.length, 4);
|
|
|
|
|
await test.click('open');
|
|
|
|
|
await test.click('open'); assert.equal(test.requests.length, 5);
|
|
|
|
|
// It is open again when the old response arrives, so the serial/abort guard
|
|
|
|
|
// (not merely dialog.open) must reject that response.
|
|
|
|
|
await test.respond(page([announcement(3)]), 200, closeRequest);
|
|
|
|
|
assert.equal(articles(test)[0].dataset.announcementId, '2');
|
|
|
|
|
await test.advance(30000);
|
|
|
|
|
await test.advance(1000);
|
|
|
|
|
const pagehideRequest = test.requests.at(-1); await test.lifecycle('pagehide');
|
|
|
|
|
assert.equal(pagehideRequest.options.signal.aborted, true);
|
|
|
|
|
await test.respond(page([announcement(4)]), 200, pagehideRequest);
|
|
|
|
|
|