import React from 'react'; import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; const consentMock = vi.fn(); vi.mock('@/contexts/consent', () => ({ useConsent: () => consentMock(), })); vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key, }), })); vi.mock('@/components/ui/button', () => ({ Button: ({ children, ...props }: { children: React.ReactNode }) => ( ), })); vi.mock('@/components/ui/dialog', () => ({ Dialog: ({ children }: { children: React.ReactNode }) =>
{children}
, DialogContent: ({ children }: { children: React.ReactNode }) =>
{children}
, DialogDescription: ({ children }: { children: React.ReactNode }) =>
{children}
, DialogFooter: ({ children }: { children: React.ReactNode }) =>
{children}
, DialogHeader: ({ children }: { children: React.ReactNode }) =>
{children}
, DialogTitle: ({ children }: { children: React.ReactNode }) =>
{children}
, })); vi.mock('@/components/ui/switch', () => ({ Switch: () => , })); vi.mock('@/components/ui/separator', () => ({ Separator: () =>
, })); import CookieBanner from '../CookieBanner'; describe('CookieBanner', () => { beforeEach(() => { consentMock.mockReturnValue({ showBanner: true, acceptAll: vi.fn(), rejectAll: vi.fn(), preferences: { analytics: false, functional: true }, savePreferences: vi.fn(), isPreferencesOpen: false, openPreferences: vi.fn(), closePreferences: vi.fn(), }); window.localStorage.removeItem('fotospiel.consent.skip'); }); afterEach(() => { window.localStorage.removeItem('fotospiel.consent.skip'); }); it('renders the banner by default', () => { render(); expect(screen.getByText('consent.banner.title')).toBeInTheDocument(); }); it('hides the banner when the dev skip flag is set', () => { window.localStorage.setItem('fotospiel.consent.skip', '1'); render(); expect(screen.queryByText('consent.banner.title')).not.toBeInTheDocument(); }); });