teqo-backup/tests/unit/campaignHomeLayout.unit.spec.tsx
Francisco Ignácio Fontoura Solla 854daf6309 Allow agents to rewrite prior code; stop pinning layout Tailwind.
Clarify that new Issues track work and do not fence closed-ticket code, and replace brittle className layout assertions with structure/data-slot contracts.
2026-08-02 01:42:22 -03:00

78 lines
3.4 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import { describe, expect, it } from 'vitest'
import { CampaignHomeLayout } from '@/components/campaign/dashboard/CampaignHomeLayout'
describe('CampaignHomeLayout', () => {
it('renders actions in the home-actions slot inside home-dock', () => {
const { container } = render(<CampaignHomeLayout actions={<p>Actions block</p>} />)
const actions = container.querySelector('[data-slot="home-actions"]')
expect(actions).not.toBeNull()
expect(actions?.closest('[data-slot="home-dock"]')).not.toBeNull()
})
it('allows horizontal bleed on the actions retraction shell', () => {
const { container } = render(<CampaignHomeLayout actions={<p>Actions block</p>} />)
const actionsChrome = container.querySelector('[data-slot="home-actions-chrome"]')
const bleedWrapper = actionsChrome?.querySelector('[data-allow-horizontal-bleed="true"]')
expect(bleedWrapper).not.toBeNull()
})
it('renders search slot inside home-dock when provided', () => {
render(
<CampaignHomeLayout
actions={<p>Actions block</p>}
searchSlot={<p data-testid="home-search-stub">Search stub</p>}
/>,
)
const search = screen.getByTestId('home-search-stub').closest('[data-slot="home-search"]')
expect(search).not.toBeNull()
expect(search?.closest('[data-slot="home-dock"]')).not.toBeNull()
})
it('omits search slot when not provided', () => {
const { container } = render(<CampaignHomeLayout actions={<p>Actions block</p>} />)
expect(container.querySelector('[data-slot="home-search"]')).toBeNull()
expect(container.querySelector('[data-slot="home-dock"]')).not.toBeNull()
})
it('renders mobile thumb-zone spacer inside home-chrome above home-dock', () => {
const { container } = render(<CampaignHomeLayout actions={<p>Actions block</p>} />)
const chrome = container.querySelector('[data-slot="home-chrome"]')
const spacer = chrome?.querySelector('[data-slot="home-thumb-spacer"]')
expect(chrome).not.toBeNull()
expect(spacer).not.toBeNull()
expect(spacer?.getAttribute('aria-hidden')).toBe('true')
expect(chrome?.nextElementSibling?.getAttribute('data-slot')).toBe('home-dock')
})
it('retracts spacer, summary, and actions when focused but keeps search', () => {
const { container } = render(
<CampaignHomeLayout
actions={<p>Actions block</p>}
focused
searchSlot={<p data-testid="home-search-stub">Search stub</p>}
summarySlot={<p data-testid="home-summary-stub">Summary stub</p>}
/>,
)
const homeChrome = container.querySelector('[data-slot="home-chrome"]')
expect(homeChrome?.getAttribute('data-retracted')).toBe('true')
expect(homeChrome?.getAttribute('aria-hidden')).toBe('true')
const actionsChrome = container.querySelector('[data-slot="home-actions-chrome"]')
expect(actionsChrome?.getAttribute('data-retracted')).toBe('true')
expect(actionsChrome?.getAttribute('aria-hidden')).toBe('true')
expect(container.querySelector('[data-slot="home-thumb-spacer"]')).not.toBeNull()
expect(container.querySelector('[data-slot="home-summary"]')).not.toBeNull()
expect(container.querySelector('[data-slot="home-actions"]')).not.toBeNull()
expect(container.querySelector('[data-slot="home-search"]')).not.toBeNull()
expect(container.querySelector('[data-slot="home-dock"]')).not.toBeNull()
})
})