// @vitest-environment nuxt import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import { usePlaylistFollow } from '../use-playlist-follow'; import { useSnackbar } from '../use-snackbar'; describe('usePlaylistFollow', () => { beforeEach(() => { useNuxtApp().payload.state = {}; vi.useFakeTimers(); useSnackbar().resetSnackbar(); }); afterEach(() => { vi.useRealTimers(); }); it('подписка добавляет плейлист и не показывает снекбар', () => { const { follows, isFollowing, toggleFollow } = usePlaylistFollow(); const { snackbarText } = useSnackbar(); toggleFollow('playlist-1', 'Playlist name'); expect(follows.value).toEqual([ 'playlist-1' ]); expect(isFollowing('playlist-1')).toBe(true); expect(snackbarText.value).toBe(''); }); it('отписка показывает снекбар с кнопкой отмены', () => { const { follows, isFollowing, toggleFollow } = usePlaylistFollow(); const { snackbarText, snackbarIcon, snackbarHighlight, snackbarActionText } = useSnackbar(); toggleFollow('playlist-1', 'Playlist name'); toggleFollow('playlist-1', 'Playlist name'); expect(follows.value).toEqual([]); expect(isFollowing('playlist-1')).toBe(false); expect(snackbarText.value).toBe('unfollowed'); expect(snackbarIcon.value).toBe('minus'); expect(snackbarHighlight.value).toBe('Playlist name'); expect(snackbarActionText.value).toBe('undo'); }); it('отмена возвращает подписку и не показывает новый снекбар', () => { const { follows, toggleFollow } = usePlaylistFollow(); const { runSnackbarAction, snackbarText } = useSnackbar(); toggleFollow('playlist-2', 'Another name'); toggleFollow('playlist-2', 'Another name'); runSnackbarAction(); expect(follows.value).toEqual([ 'playlist-2' ]); expect(snackbarText.value).toBe(''); }); });