markCurrentArticleRead() already marked the displayed article read immediately at each deliberate navigation point (entering article view, paging next/prev), but reloading the page while viewMode was already 'article' (persisted in localStorage) booted straight into article view without marking anything read — the article on screen stayed unread until the user paged forward/back at least once. Close that gap with a single explicit call in RssFeeds.vue's onMounted: once the initial fetch resolves, if we're already in article view, mark the now-displayed article read the same way toggleViewMode()/ nextArticle()/prevArticle() do. (A first attempt replaced the explicit call sites with a generic watch on the displayed article's id, but that also fired on unrelated changes to it — e.g. switching the feed filter while in article view resets currentIndex and reprojects feeds, so the watch would silently mark an article the user never viewed as read. Reverted to the explicit, call-site-scoped approach and added only the one boot-time call needed.) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K2sYVA7rh7N5RYmcCd2KDV
77 lines
2.5 KiB
JavaScript
77 lines
2.5 KiB
JavaScript
// Reproduces the "reload the tab while in article view" boot sequence:
|
|
// module-scope init must pick up the persisted viewMode, and RssFeeds'
|
|
// mount flow (fetchData + sync) must not reset it back to 'list'.
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
|
|
vi.mock('axios')
|
|
|
|
class FakeIntersectionObserver {
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
}
|
|
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver)
|
|
|
|
describe('viewMode boot persistence', () => {
|
|
beforeEach(() => {
|
|
vi.resetModules()
|
|
localStorage.clear()
|
|
localStorage.setItem('user-token', 'test-token')
|
|
localStorage.setItem('user-id', '7')
|
|
})
|
|
|
|
afterEach(() => {
|
|
localStorage.clear()
|
|
})
|
|
|
|
it('boots into article view when localStorage says so, surviving the mount fetch/sync', async () => {
|
|
localStorage.setItem('viewMode', 'article')
|
|
|
|
const axios = (await import('axios')).default
|
|
axios.get.mockResolvedValue({
|
|
data: {
|
|
feeds: [
|
|
{
|
|
title: 'My Feed',
|
|
items: [
|
|
{ id: 1, title: 'Article one', content: '<p>hi</p>', url: 'https://example.test/1', timestamp: '2026-01-01 10:00:00' },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
})
|
|
axios.post.mockResolvedValue({ status: 200 })
|
|
axios.put.mockResolvedValue({ status: 200 })
|
|
|
|
// Import AFTER setting storage — module-scope refs initialize at import.
|
|
const { useFeeds } = await import('../useFeeds')
|
|
const { viewMode } = useFeeds()
|
|
expect(viewMode.value).toBe('article')
|
|
|
|
const RssFeeds = (await import('../../components/RssFeeds.vue')).default
|
|
const wrapper = mount(RssFeeds)
|
|
await flushPromises()
|
|
|
|
expect(viewMode.value).toBe('article')
|
|
expect(wrapper.find('.article-single').exists()).toBe(true)
|
|
expect(wrapper.find('#article').exists()).toBe(false)
|
|
|
|
// The article shown right after reload must be marked read immediately —
|
|
// not only once the user pages forward/back at least once.
|
|
expect(axios.put).toHaveBeenCalledWith('/api/v1/article/read/1', null, expect.anything())
|
|
|
|
wrapper.unmount()
|
|
})
|
|
|
|
it('boots into list view when the key is absent', async () => {
|
|
const axios = (await import('axios')).default
|
|
axios.get.mockResolvedValue({ data: { feeds: [] } })
|
|
axios.post.mockResolvedValue({ status: 200 })
|
|
|
|
const { useFeeds } = await import('../useFeeds')
|
|
const { viewMode } = useFeeds()
|
|
expect(viewMode.value).toBe('list')
|
|
})
|
|
})
|