import React from 'react' import { afterEach, describe, expect, it, vi } from 'vitest' import { cleanup, render } from '@testing-library/react' import AdSenseUnit from './AdSenseUnit' describe('AdSenseUnit', () => { afterEach(() => { cleanup() vi.restoreAllMocks() delete window.adsbygoogle }) it('renders the dashboard horizontal slot and pushes once', () => { window.adsbygoogle = [] const { container } = render() const unit = container.querySelector('ins.adsbygoogle') expect(unit).not.toBeNull() expect(container.firstChild.className).toContain('justify-center') expect(unit.className).toContain('max-w-3xl') expect(unit.getAttribute('data-ad-client')).toBe('ca-pub-6457864535683080') expect(unit.getAttribute('data-ad-slot')).toBe('8766048277') expect(unit.getAttribute('data-ad-format')).toBe('auto') expect(unit.getAttribute('data-full-width-responsive')).toBe('true') expect(window.adsbygoogle).toHaveLength(1) }) it('renders nothing without a slot', () => { const { container } = render() expect(container.querySelector('ins.adsbygoogle')).toBeNull() }) it('renders nothing when disabled for authenticated users', () => { window.adsbygoogle = [] const { container } = render() expect(container.querySelector('ins.adsbygoogle')).toBeNull() expect(window.adsbygoogle).toHaveLength(0) }) })