aboutsummaryrefslogtreecommitdiffstats
path: root/frontend-vanilla/src/regression.test.ts
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-17 11:41:50 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-17 11:41:50 -0800
commit3bd52a03323a9983aa7896af4d3fc3668e4c1252 (patch)
tree408065c8f4b21030c2ae3e070447e10fc124be70 /frontend-vanilla/src/regression.test.ts
parentea9ec7f41c0447027b66f52c0c4cd0d5c9777bfa (diff)
downloadneko-3bd52a03323a9983aa7896af4d3fc3668e4c1252.tar.gz
neko-3bd52a03323a9983aa7896af4d3fc3668e4c1252.tar.bz2
neko-3bd52a03323a9983aa7896af4d3fc3668e4c1252.zip
Fix regression: mark-as-read not triggering on window scroll
Diffstat (limited to 'frontend-vanilla/src/regression.test.ts')
-rw-r--r--frontend-vanilla/src/regression.test.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/frontend-vanilla/src/regression.test.ts b/frontend-vanilla/src/regression.test.ts
index 813e4bb..0c10d95 100644
--- a/frontend-vanilla/src/regression.test.ts
+++ b/frontend-vanilla/src/regression.test.ts
@@ -167,6 +167,50 @@ describe('Scroll-to-Read Regression Tests', () => {
// API should NOT be called
expect(apiFetch).not.toHaveBeenCalledWith(expect.stringContaining('/api/item/888'), expect.anything());
});
+
+ it('should mark item as read when WINDOW scrolls (robustness fallback)', async () => {
+ vi.useRealTimers();
+ const mockItem = {
+ _id: 12345,
+ title: 'Window Scroll Item',
+ read: false,
+ url: 'http://example.com/window',
+ publish_date: '2023-01-01'
+ } as any;
+
+ store.setItems([mockItem]);
+ renderItems();
+
+ // Setup successful detection scenario
+ const mainContent = document.getElementById('main-content');
+ if (mainContent) {
+ mainContent.getBoundingClientRect = vi.fn(() => ({
+ top: 0, bottom: 800, height: 800, left: 0, right: 0, width: 0, x: 0, y: 0, toJSON: () => { }
+ }));
+ }
+
+ const itemEl = document.querySelector(`.feed-item[data-id="12345"]`);
+ if (itemEl) {
+ // Fully scrolled past
+ itemEl.getBoundingClientRect = vi.fn(() => ({
+ top: -150, bottom: -50, height: 100, left: 0, right: 0, width: 0, x: 0, y: 0, toJSON: () => { }
+ }));
+ }
+
+ vi.mocked(apiFetch).mockResolvedValue({ ok: true } as Response);
+
+ // Dispatch scroll on WINDOW, not mainContent
+ window.dispatchEvent(new Event('scroll'));
+
+ // Wait for potential debounce/poll
+ await new Promise(resolve => setTimeout(resolve, 1100));
+
+ // Expect it to handle it
+ expect(apiFetch).toHaveBeenCalledWith(expect.stringContaining('/api/item/12345'), expect.objectContaining({
+ method: 'PUT',
+ body: expect.stringContaining('"read":true')
+ }));
+ });
});
// NK-t8qnrh: Links in feed item descriptions should have no underlines (match v1 style)