import { describe, it, expect } from 'vitest'; import reducer, { togglePublishBlogModal, toggleEditBlogModal, setCurrentBlog, setVisitingBlog, setIsLoadingGlobal, setAddToDownloads, updateDownloads, setUserAvatarHash, } from '@/state/features/globalSlice'; describe('globalSlice reducers', () => { it('toggles modals', () => { let s = reducer(undefined, togglePublishBlogModal(true)); expect(s.isOpenPublishBlogModal).toBe(true); s = reducer(s, toggleEditBlogModal(true)); expect(s.isOpenEditBlogModal).toBe(true); }); it('sets current and visiting blog and clears loading flag', () => { const blog = { createdAt: 1, blogId: 'b', title: 't', description: 'd', blogImage: '' }; let s = reducer(undefined, setCurrentBlog(blog as any)); expect(s.currentBlog?.blogId).toBe('b'); expect(s.isLoadingCurrentBlog).toBe(false); s = reducer(s, setVisitingBlog({ ...blog, name: 'alice' } as any)); expect(s.visitingBlog?.name).toBe('alice'); expect(s.isLoadingCurrentBlog).toBe(false); }); it('sets global loading flag', () => { const s = reducer(undefined, setIsLoadingGlobal(true)); expect(s.isLoadingGlobal).toBe(true); }); it('adds and updates downloads', () => { let s = reducer(undefined, setAddToDownloads({ identifier: 'x', status: 'start' })); expect(s.downloads['x'].status).toBe('start'); s = reducer(s, updateDownloads({ identifier: 'x', progress: 50 })); expect(s.downloads['x'].progress).toBe(50); }); it('sets user avatar hash when valid', () => { const s = reducer(undefined, setUserAvatarHash({ name: 'bob', url: 'u' })); expect(s.userAvatarHash['bob']).toBe('u'); }); });