fix sync missing articles
This commit is contained in:
@@ -12,7 +12,7 @@ class FakeIntersectionObserver {
|
||||
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver)
|
||||
|
||||
describe('useFeeds', () => {
|
||||
const { feeds, showMessage, message, showModal, fetchData, sync, getReadable } = useFeeds()
|
||||
const { feeds, showMessage, message, showModal, fetchData, sync, getReadable, setInitialLoad, handleIntersection } = useFeeds()
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.setItem('user-token', 'test-token')
|
||||
@@ -91,6 +91,31 @@ describe('useFeeds', () => {
|
||||
expect(axios.get).toHaveBeenCalledWith('/api/v1/article/get/7', expect.anything())
|
||||
})
|
||||
|
||||
it('marks the correct articles read when several scroll out of view in one batch', async () => {
|
||||
feeds.value = [
|
||||
{ id: 101, title: 'First' },
|
||||
{ id: 102, title: 'Second' },
|
||||
{ id: 103, title: 'Third' },
|
||||
]
|
||||
setInitialLoad(true)
|
||||
axios.put.mockResolvedValue({ status: 200 })
|
||||
|
||||
// Both the first and second articles scrolled above the viewport in the
|
||||
// same IntersectionObserver callback — their `target.id` reflects their
|
||||
// original render-time indices (0 and 1).
|
||||
await handleIntersection([
|
||||
{ isIntersecting: false, boundingClientRect: { y: -10 }, target: { id: '0' } },
|
||||
{ isIntersecting: false, boundingClientRect: { y: -5 }, target: { id: '1' } },
|
||||
])
|
||||
|
||||
expect(axios.put).toHaveBeenCalledWith('/api/v1/article/read/101', null, expect.anything())
|
||||
expect(axios.put).toHaveBeenCalledWith('/api/v1/article/read/102', null, expect.anything())
|
||||
expect(axios.put).not.toHaveBeenCalledWith('/api/v1/article/read/103', null, expect.anything())
|
||||
expect(feeds.value).toEqual([{ id: 103, title: 'Third' }])
|
||||
|
||||
setInitialLoad(false)
|
||||
})
|
||||
|
||||
it('resolves Deutsche-Welle-style templated image URLs from data-format/data-url', async () => {
|
||||
feeds.value = [{
|
||||
id: 1,
|
||||
|
||||
Reference in New Issue
Block a user