teqo-backup/tests/unit/homeSearchExcludeCurrentEntity.unit.spec.ts
Cursor Agent 490d5deeb7
B109 — bottom drawer: fullscreen search, wider labels, exclude current entity
- Add QUICK_ACTIONS_SNAP_FULL; drawer expands on search focus and hides action strip
- Tighten dock bottom gap; restore dock/collapsed on blur per scroll position (B100)
- Widen CampaignHomeActionButton to w-[5.5rem] for two-line labels
- Client-side filter excludes current page entity from drawer search hits
- Unit + e2e coverage for full snap, exclusion, and label readability
2026-08-01 20:38:10 +00:00

64 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { HomeSearchSuccessResponse } from '@/lib/campaignHomeSearchHits'
import {
filterHomeSearchResponseForContext,
resolveHomeSearchExcludeContext,
} from '@/lib/homeSearchExcludeCurrentEntity'
const sampleResponse = (): HomeSearchSuccessResponse => ({
status: 'success',
resultKind: 'suggest',
municipalities: [
{
kind: 'municipality',
slug: 'cairu',
name: 'Cairu',
region: 'Baixo Sul',
priority: null,
votePosition2022: null,
},
{
kind: 'municipality',
slug: 'feira-de-santana',
name: 'Feira de Santana',
region: 'Centro-Norte',
priority: null,
votePosition2022: null,
},
],
territories: [],
advisors: [{ id: 9, name: 'Assessor', phone: null, municipalityCount: 2 }],
leaderships: [{ kind: 'leadership', id: 42, name: 'Líder', phone: null, municipalitiesSummary: '' }],
stateDeputies: [],
activities: [{ id: 1, slug: 'comicio', title: 'Comício', secondary: '' }],
demands: [{ id: 2, slug: 'pedido', title: 'Pedido', secondary: '' }],
})
describe('homeSearchExcludeCurrentEntity (B109)', () => {
it('merges municipality slug from pathname when context is empty', () => {
expect(
resolveHomeSearchExcludeContext('/campanha/municipios/cairu', {}).municipalitySlug,
).toBe('cairu')
})
it('filters the current municipality from suggest and search hits', () => {
const filtered = filterHomeSearchResponseForContext(sampleResponse(), {
municipalitySlug: 'cairu',
})
expect(filtered.municipalities.map((hit) => hit.slug)).toEqual(['feira-de-santana'])
})
it('filters leadership, advisor, activity and demand entities', () => {
const filtered = filterHomeSearchResponseForContext(sampleResponse(), {
leadershipId: 42,
advisorId: 9,
activitySlug: 'comicio',
demandSlug: 'pedido',
})
expect(filtered.leaderships).toHaveLength(0)
expect(filtered.advisors).toHaveLength(0)
expect(filtered.activities).toHaveLength(0)
expect(filtered.demands).toHaveLength(0)
})
})