mark all as read

This commit is contained in:
2026-06-08 07:06:38 +02:00
parent b4fc86302f
commit 3c42ebb972
4 changed files with 82 additions and 4 deletions
+56 -1
View File
@@ -15,11 +15,13 @@ describe('AppNav', () => {
localStorage.setItem('user-id', '7')
vi.clearAllMocks()
const { feeds, showMessage, message, showModal } = useFeeds()
const { feeds, showMessage, message, showModal, viewMode, currentIndex } = useFeeds()
feeds.value = []
showMessage.value = false
message.value = ''
showModal.value = false
viewMode.value = 'list'
currentIndex.value = 0
router = createRouter({
history: createWebHistory(),
@@ -90,4 +92,57 @@ describe('AppNav', () => {
expect(showModal.value).toBe(true)
})
it('switches the view mode from the menu and closes it', async () => {
const wrapper = await mountWithMenuOpen()
const { viewMode } = useFeeds()
const viewButton = wrapper.findAll('.app-nav__menu-item').find(el => el.text() === 'Article view')
await viewButton.trigger('click')
expect(viewMode.value).toBe('article')
expect(wrapper.find('.app-nav__menu').exists()).toBe(false)
})
it('marks all articles as read from the menu after confirmation', async () => {
const { feeds } = useFeeds()
feeds.value = [
{ id: 1, title: 'Article one', content: '', url: 'https://example.test/1', timestamp: '2026-01-01' },
{ id: 2, title: 'Article two', content: '', url: 'https://example.test/2', timestamp: '2026-01-02' },
]
axios.put.mockResolvedValue({ status: 200 })
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true)
const wrapper = await mountWithMenuOpen()
const markAllButton = wrapper.findAll('.app-nav__menu-item').find(el => el.text() === 'Mark all as read')
await markAllButton.trigger('click')
await flushPromises()
expect(confirmSpy).toHaveBeenCalled()
expect(axios.put).toHaveBeenCalledWith('/api/v1/article/read/1', null, expect.anything())
expect(axios.put).toHaveBeenCalledWith('/api/v1/article/read/2', null, expect.anything())
expect(feeds.value).toHaveLength(0)
expect(wrapper.find('.app-nav__menu').exists()).toBe(false)
confirmSpy.mockRestore()
})
it('does not mark articles as read when the confirmation is dismissed', async () => {
const { feeds } = useFeeds()
feeds.value = [
{ id: 1, title: 'Article one', content: '', url: 'https://example.test/1', timestamp: '2026-01-01' },
]
const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(false)
const wrapper = await mountWithMenuOpen()
const markAllButton = wrapper.findAll('.app-nav__menu-item').find(el => el.text() === 'Mark all as read')
await markAllButton.trigger('click')
await flushPromises()
expect(confirmSpy).toHaveBeenCalled()
expect(axios.put).not.toHaveBeenCalled()
expect(feeds.value).toHaveLength(1)
confirmSpy.mockRestore()
})
})