mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Keep the news layer inside its day and its memory bounds
From review of the news layer: - An event's other sides older than 24 hours (or undated) are no longer listed, and a report dated more than 15 minutes ahead is outside the window, as in the regional brief. - Picture cards are one canvas per event in a bounded cache (24), repainted in place when the age changes, with each card's picture dropped with it; the age in the key had made a new canvas every minute. - The feed list drops reports that leave the window and is capped at 600. - "In view" is filtered from the reports the layer already holds; it reads the feed only with minor news on, once per refresh, never per pan. - Infinite scroll restarts after a filter change or a failed read. - The two filter selects stack, so "Significant and above" is not cut off. - The timeout tests hold the event loop until aborted, so they pass on Node 22 as well.
This commit is contained in:
1 parent
138cc77a11
commit
e95ae7b80c
11 files changed
+560
-90
No files matched your search
@@ -37,8 +37,20 @@ const big = report('big', {
|
||||
status: 'both-sides',
|
||||
lastAt: '2026-10-28T09:50:00.000Z',
|
||||
sides: [
|
||||
{ side: 'UA', title: 'a', url: 'https://a.test/', publisher: 'A' },
|
||||
{ side: 'RU', title: 'b', url: 'https://b.test/', publisher: 'B' },
|
||||
{
|
||||
side: 'UA',
|
||||
title: 'a',
|
||||
url: 'https://a.test/',
|
||||
publisher: 'A',
|
||||
publishedAt: '2026-10-28T09:00:00.000Z',
|
||||
},
|
||||
{
|
||||
side: 'RU',
|
||||
title: 'b',
|
||||
url: 'https://b.test/',
|
||||
publisher: 'B',
|
||||
publishedAt: '2026-10-28T09:40:00.000Z',
|
||||
},
|
||||
],
|
||||
image: { url: 'https://a.test/p.jpg', publisher: 'A' },
|
||||
},
|
||||
@@ -221,3 +233,46 @@ test('filters, In view and empty or failed reads', () => {
|
||||
);
|
||||
news.destroy();
|
||||
});
|
||||
|
||||
test('scrolling to the end asks once per page, again after a filter change or a failed read', () => {
|
||||
const { news, calls } = fixture();
|
||||
const body = document.getElementById('news-panel-body');
|
||||
// A scroller at its bottom.
|
||||
Object.defineProperty(body, 'scrollHeight', {
|
||||
value: 1000,
|
||||
configurable: true,
|
||||
});
|
||||
Object.defineProperty(body, 'clientHeight', {
|
||||
value: 400,
|
||||
configurable: true,
|
||||
});
|
||||
body.scrollTop = 600;
|
||||
const loadMores = () => calls.filter(([, p]) => p.loadMore === true).length;
|
||||
const scroll = () => body.dispatchEvent(new Event('scroll'));
|
||||
news.update(view());
|
||||
scroll();
|
||||
scroll();
|
||||
assert.equal(loadMores(), 1);
|
||||
// The page came back with nothing new (as many items): no second request.
|
||||
news.update(view());
|
||||
scroll();
|
||||
assert.equal(loadMores(), 1);
|
||||
// Another hotspot, the same number of rows: the new list can be read on.
|
||||
const hotspot = normalizeFilters({ hotspot: 'ua-ru-war' }, [
|
||||
{ id: 'ua-ru-war' },
|
||||
]);
|
||||
news.update(view({ filters: hotspot }));
|
||||
scroll();
|
||||
assert.equal(loadMores(), 2);
|
||||
// The read fails: the next scroll tries again.
|
||||
news.update(view({ filters: hotspot, error: 'News feed unavailable' }));
|
||||
scroll();
|
||||
assert.equal(loadMores(), 3);
|
||||
// While loading, or with no older page, nothing is asked.
|
||||
news.update(view({ filters: hotspot, loading: true }));
|
||||
scroll();
|
||||
news.update(view({ filters: hotspot, hasMore: false }));
|
||||
scroll();
|
||||
assert.equal(loadMores(), 3);
|
||||
news.destroy();
|
||||
});
|
||||
Reference in new issue
Block a user