teqo-backup/tests/unit/campaignHomeSearch.unit.spec.tsx
Francisco Ignácio Fontoura Solla e733efbe42 B68: curated municipality suggestions on empty home search focus.
Staff see role-ranked shortcuts (advisor portfolio by signal age; CG/candidate by alta priority deficit) via POST mode suggest, without treating empty query as search.
2026-07-29 22:06:02 -03:00

62 lines
2 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { CampaignHomeLayout } from '@/components/campaign/dashboard/CampaignHomeLayout'
import { CampaignHomeSearch } from '@/components/campaign/dashboard/CampaignHomeSearch'
import { HomeSearchProvider } from '@/components/campaign/dashboard/HomeSearchContext'
const providerValue = {
query: { raw: 'ca', debounced: 'ca', isActive: true },
setRaw: vi.fn(),
clear: vi.fn(),
isDebouncing: false,
inputFocused: false,
setInputFocused: vi.fn(),
uiFocused: true,
}
describe('CampaignHomeLayout focused mode', () => {
it('hides actions, thumb spacer, and summary when focused', () => {
const { container } = render(
<CampaignHomeLayout
focused
actions={<p>Actions block</p>}
searchSlot={<p>Search</p>}
summarySlot={<p>Summary block</p>}
/>,
)
expect(container.querySelector('[data-slot="home-thumb-spacer"]')).toBeNull()
expect(container.querySelector('[data-slot="home-actions"]')?.className).toContain('hidden')
expect(container.querySelector('[data-slot="home-summary"]')?.className).toContain('hidden')
})
it('shows summary when not focused', () => {
render(
<CampaignHomeLayout
actions={<p>Actions block</p>}
summarySlot={<p data-testid="home-summary-stub">Summary stub</p>}
/>,
)
expect(
screen.getByTestId('home-summary-stub').closest('[data-slot="home-summary"]'),
).not.toBeNull()
})
})
describe('CampaignHomeSearch', () => {
it('renders search input and results region', () => {
render(
<HomeSearchProvider value={providerValue}>
<CampaignHomeSearch>
<p>Group stub</p>
</CampaignHomeSearch>
</HomeSearchProvider>,
)
expect(screen.getByLabelText('Buscar na campanha')).toBeTruthy()
expect(screen.getByRole('region', { name: 'Resultados da busca' })).toBeTruthy()
expect(screen.getByText('Group stub')).toBeTruthy()
})
})