Show guest-only ad units on public pages and skip the AdSense script entirely for signed-in users.
44 lines
1.5 KiB
React
44 lines
1.5 KiB
React
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(<AdSenseUnit slot="8766048277" />)
|
|
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(<AdSenseUnit />)
|
|
|
|
expect(container.querySelector('ins.adsbygoogle')).toBeNull()
|
|
})
|
|
|
|
it('renders nothing when disabled for authenticated users', () => {
|
|
window.adsbygoogle = []
|
|
|
|
const { container } = render(<AdSenseUnit slot="8766048277" enabled={false} />)
|
|
|
|
expect(container.querySelector('ins.adsbygoogle')).toBeNull()
|
|
expect(window.adsbygoogle).toHaveLength(0)
|
|
})
|
|
})
|