teqo-backup/tests/unit/campaignHomeSearch.unit.spec.tsx
Cursor Agent 98a69ab153
B105: bottom drawer handle top, scroll-up dock, discreet search peek
Revert handle to the top of the sheet; recalibrate collapsed/dock snaps
for handle+search and 2-line action labels; scroll ↓ collapses and ↑
re-docks; collapsed keeps a placeholder-less search peek that expands
on focus.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-01 18:40:51 +00:00

53 lines
1.7 KiB
TypeScript

import { cleanup, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
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,
}
afterEach(() => {
cleanup()
})
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.getByLabelText('Buscar na campanha') as HTMLInputElement).placeholder,
).toBe('Município, liderança, atividade…')
expect(screen.getByRole('region', { name: 'Resultados da busca' })).toBeTruthy()
expect(screen.getByText('Group stub')).toBeTruthy()
})
it('supports discreet peek without placeholder and hidden results', () => {
render(
<HomeSearchProvider value={providerValue}>
<CampaignHomeSearch placeholder="" showResults={false}>
<p>Group stub</p>
</CampaignHomeSearch>
</HomeSearchProvider>,
)
expect((screen.getByLabelText('Buscar na campanha') as HTMLInputElement).placeholder).toBe('')
const results = document.querySelector('[data-slot="home-search-results"]')
expect(results).toBeTruthy()
expect((results as HTMLElement).hidden).toBe(true)
})
})