Replace the feed select with a multi-feed filter modal
The header's feed <select> is now a funnel button that opens a modal with an "All feeds" checkbox and one checkbox per feed with unread items. The selection is either "All feeds" or at least one feed, is applied once when the modal closes, and is persisted in localStorage. - feedFilter holds string[] | null; setFeedFilter is a no-op when the selection is unchanged (order-insensitive), sparing callers the scroll/mark-read side effects. - Selected feeds stay listed at 0 unread so they can be unchecked; titles whose feed no longer exists are pruned after each fetch. - The persisted filter is cleared on logout and on 401 (handler extracted to httpAuthInterceptor.js so it is unit-testable). - The modal locks body scroll while open so scrolling behind it can't mark articles read.
This commit is contained in:
1 parent
8f7ddb77c4
commit
5ed780baa3
10 files changed
+1217
-114
No files matched your search
@@ -0,0 +1,72 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { useFeeds } from '../composables/useFeeds'
|
||||
|
||||
// router/index.js's route definitions lazily import(...) the view components,
|
||||
// which importing the real module would still be safe to do (the imports
|
||||
// themselves aren't eagerly evaluated) — but mocking it keeps this test from
|
||||
// depending on the app's actual routes and lets currentRoute/push be
|
||||
// controlled directly.
|
||||
vi.mock('../router', () => ({
|
||||
default: {
|
||||
currentRoute: { value: { name: 'feeds' } },
|
||||
push: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
import router from '../router'
|
||||
import { handleUnauthorizedResponse } from '../httpAuthInterceptor'
|
||||
|
||||
describe('handleUnauthorizedResponse', () => {
|
||||
const { feedFilter } = useFeeds()
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.setItem('user-token', 'abc123')
|
||||
localStorage.setItem('user-id', '7')
|
||||
localStorage.setItem('feedFilter', JSON.stringify(['Feed A']))
|
||||
feedFilter.value = ['Feed A']
|
||||
router.currentRoute.value.name = 'feeds'
|
||||
router.push.mockClear()
|
||||
})
|
||||
|
||||
it('clears the session and the feed filter, and redirects to login, on a 401 from a non-login route', async () => {
|
||||
const error = { response: { status: 401 } }
|
||||
|
||||
await expect(handleUnauthorizedResponse(error)).rejects.toBe(error)
|
||||
|
||||
expect(localStorage.getItem('user-token')).toBeNull()
|
||||
expect(localStorage.getItem('user-id')).toBeNull()
|
||||
expect(localStorage.getItem('feedFilter')).toBeNull()
|
||||
expect(feedFilter.value).toBeNull()
|
||||
expect(router.push).toHaveBeenCalledWith({ name: 'login' })
|
||||
})
|
||||
|
||||
it('still clears the session on a 401 but does not push again when already on the login route', async () => {
|
||||
router.currentRoute.value.name = 'login'
|
||||
const error = { response: { status: 401 } }
|
||||
|
||||
await expect(handleUnauthorizedResponse(error)).rejects.toBe(error)
|
||||
|
||||
expect(localStorage.getItem('user-token')).toBeNull()
|
||||
expect(router.push).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('leaves the session and filter untouched, and still rejects, on a non-401 error response', async () => {
|
||||
const error = { response: { status: 500 } }
|
||||
|
||||
await expect(handleUnauthorizedResponse(error)).rejects.toBe(error)
|
||||
|
||||
expect(localStorage.getItem('user-token')).toBe('abc123')
|
||||
expect(localStorage.getItem('feedFilter')).toBe(JSON.stringify(['Feed A']))
|
||||
expect(feedFilter.value).toEqual(['Feed A'])
|
||||
expect(router.push).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('leaves the session untouched and still rejects on an error with no response (e.g. a network error)', async () => {
|
||||
const error = new Error('network')
|
||||
|
||||
await expect(handleUnauthorizedResponse(error)).rejects.toBe(error)
|
||||
|
||||
expect(localStorage.getItem('user-token')).toBe('abc123')
|
||||
expect(router.push).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user