feat(B112): collapse drawer on blur∅ / nav / handle+swipe, pad ⅓

- Empty blur → collapsed; blur with text stays FULL (drawer whenEmpty policy).
- Handle tap and snap→collapsed clear search so uiFocused cannot reopen FULL.
- Keep all snap points while focused so swipe ↓ can dismiss.
- Pathname change (in-chrome) clears + collapses; initial load stays dock.
- Compact dock/search stack gap (~⅓) without cutting safe-area.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-08-01 23:53:36 +00:00
parent abe0d106b1
commit 266fc67516
No known key found for this signature in database
8 changed files with 229 additions and 46 deletions

View file

@ -4,7 +4,9 @@ import type { ReactNode } from 'react'
import { useHomeSearch } from '@/components/campaign/dashboard/HomeSearchContext' import { useHomeSearch } from '@/components/campaign/dashboard/HomeSearchContext'
import { CampaignSearchInput } from '@/components/campaign/shared/CampaignSearchInput' import { CampaignSearchInput } from '@/components/campaign/shared/CampaignSearchInput'
import { homeSearchShouldUnfocusOnBlur } from '@/lib/campaignHomeSearchContract'
import { HOME_SEARCH_QUERY_MAX_LENGTH } from '@/lib/schemas/homeSearch' import { HOME_SEARCH_QUERY_MAX_LENGTH } from '@/lib/schemas/homeSearch'
import { cn } from '@/lib/utils'
const HOME_SEARCH_INPUT_ID = 'homeSearchQuery' const HOME_SEARCH_INPUT_ID = 'homeSearchQuery'
const HOME_SEARCH_LABEL = 'Buscar na campanha' const HOME_SEARCH_LABEL = 'Buscar na campanha'
@ -15,6 +17,8 @@ export const CampaignHomeSearch = ({
resultsBusy, resultsBusy,
placeholder = HOME_SEARCH_PLACEHOLDER, placeholder = HOME_SEARCH_PLACEHOLDER,
showResults = true, showResults = true,
blurUnfocusPolicy = 'whenInactive',
compactStack = false,
}: { }: {
children?: ReactNode children?: ReactNode
/** When set, must already fold debounce (see `useHomeSearchResultsState.isFetching`). */ /** When set, must already fold debounce (see `useHomeSearchResultsState.isFetching`). */
@ -23,12 +27,19 @@ export const CampaignHomeSearch = ({
placeholder?: string placeholder?: string
/** When false, keeps the live region mounted but visually hidden (collapsed peek). */ /** When false, keeps the live region mounted but visually hidden (collapsed peek). */
showResults?: boolean showResults?: boolean
/**
* Início: unfocus when query inactive. Drawer (B112): unfocus only when raw
* is empty so blur-with-text keeps FULL.
*/
blurUnfocusPolicy?: 'whenInactive' | 'whenEmpty'
/** B112 — ~⅓ of the default input→results gap in the bottom drawer. */
compactStack?: boolean
}) => { }) => {
const { query, setRaw, clear, isDebouncing, setInputFocused } = useHomeSearch() const { query, setRaw, clear, isDebouncing, setInputFocused } = useHomeSearch()
const ariaBusy = (resultsBusy ?? isDebouncing) || undefined const ariaBusy = (resultsBusy ?? isDebouncing) || undefined
return ( return (
<div className="flex w-full min-w-0 flex-col gap-4"> <div className={cn('flex w-full min-w-0 flex-col', compactStack ? 'gap-1.5' : 'gap-4')}>
<CampaignSearchInput <CampaignSearchInput
id={HOME_SEARCH_INPUT_ID} id={HOME_SEARCH_INPUT_ID}
label={HOME_SEARCH_LABEL} label={HOME_SEARCH_LABEL}
@ -37,7 +48,7 @@ export const CampaignHomeSearch = ({
onChange={(event) => setRaw(event.target.value)} onChange={(event) => setRaw(event.target.value)}
onFocus={() => setInputFocused(true)} onFocus={() => setInputFocused(true)}
onBlur={() => { onBlur={() => {
if (!query.isActive) { if (homeSearchShouldUnfocusOnBlur(query.raw, blurUnfocusPolicy, query.isActive)) {
setInputFocused(false) setInputFocused(false)
} }
}} }}

View file

@ -17,10 +17,16 @@ import { HomeSearchStateDeputyGroup } from '@/components/campaign/dashboard/Home
export const CampaignStaffGlobalSearchBody = ({ export const CampaignStaffGlobalSearchBody = ({
placeholder, placeholder,
showResults = true, showResults = true,
blurUnfocusPolicy = 'whenInactive',
compactStack = false,
}: { }: {
/** Forwarded to `CampaignHomeSearch` — empty string for collapsed discreet peek. */ /** Forwarded to `CampaignHomeSearch` — empty string for collapsed discreet peek. */
placeholder?: string placeholder?: string
showResults?: boolean showResults?: boolean
/** Drawer passes `whenEmpty` (B112); Início keeps `whenInactive`. */
blurUnfocusPolicy?: 'whenInactive' | 'whenEmpty'
/** Drawer passes true for ~⅓ gap (B112); Início keeps the default stack. */
compactStack?: boolean
}) => { }) => {
const searchResultsState = useHomeSearchResultsState() const searchResultsState = useHomeSearchResultsState()
@ -29,6 +35,8 @@ export const CampaignStaffGlobalSearchBody = ({
resultsBusy={searchResultsState.isFetching} resultsBusy={searchResultsState.isFetching}
placeholder={placeholder} placeholder={placeholder}
showResults={showResults} showResults={showResults}
blurUnfocusPolicy={blurUnfocusPolicy}
compactStack={compactStack}
> >
<HomeSearchResultsProvider value={searchResultsState}> <HomeSearchResultsProvider value={searchResultsState}>
<HomeSearchResultsShell> <HomeSearchResultsShell>

View file

@ -1,7 +1,7 @@
'use client' 'use client'
import { usePathname } from 'next/navigation' import { usePathname } from 'next/navigation'
import { useCallback, useEffect } from 'react' import { useCallback, useEffect, useRef } from 'react'
import { CampaignGlobalSearchBody } from '@/components/campaign/dashboard/CampaignGlobalSearchMount' import { CampaignGlobalSearchBody } from '@/components/campaign/dashboard/CampaignGlobalSearchMount'
import { CampaignHomeActionStrip } from '@/components/campaign/dashboard/CampaignHomeActionStrip' import { CampaignHomeActionStrip } from '@/components/campaign/dashboard/CampaignHomeActionStrip'
@ -11,11 +11,11 @@ import { useCampaignQuickActionContext } from '@/components/campaign/shell/Campa
import { useCampaignQuickActionsSnap } from '@/components/campaign/shell/CampaignQuickActionsSnapContext' import { useCampaignQuickActionsSnap } from '@/components/campaign/shell/CampaignQuickActionsSnapContext'
import { Drawer, DrawerContent, DrawerTitle } from '@/components/ui/Drawer' import { Drawer, DrawerContent, DrawerTitle } from '@/components/ui/Drawer'
import { import {
QUICK_ACTIONS_SCROLL_COLLAPSE_THRESHOLD_PX,
QUICK_ACTIONS_SNAP_COLLAPSED, QUICK_ACTIONS_SNAP_COLLAPSED,
QUICK_ACTIONS_SNAP_DOCK, QUICK_ACTIONS_SNAP_DOCK,
QUICK_ACTIONS_SNAP_FULL, QUICK_ACTIONS_SNAP_FULL,
QUICK_ACTIONS_SNAP_POINTS, QUICK_ACTIONS_SNAP_POINTS,
quickActionsSnapAfterDismiss,
quickActionsSnapIsDock, quickActionsSnapIsDock,
quickActionsSnapIsFull, quickActionsSnapIsFull,
type QuickActionsSnapPoint, type QuickActionsSnapPoint,
@ -26,14 +26,6 @@ import { cn } from '@/lib/utils'
const SNAP_POINTS = [...QUICK_ACTIONS_SNAP_POINTS] const SNAP_POINTS = [...QUICK_ACTIONS_SNAP_POINTS]
const restoreSnapAfterSearch = (): QuickActionsSnapPoint => {
const scrollport = document.querySelector('[data-slot="campaign-content-scroll"]')
const scrollTop = scrollport instanceof HTMLElement ? scrollport.scrollTop : 0
return scrollTop > QUICK_ACTIONS_SCROLL_COLLAPSE_THRESHOLD_PX
? QUICK_ACTIONS_SNAP_COLLAPSED
: QUICK_ACTIONS_SNAP_DOCK
}
export const CampaignQuickActionsDrawer = ({ export const CampaignQuickActionsDrawer = ({
actions, actions,
}: { }: {
@ -43,52 +35,77 @@ export const CampaignQuickActionsDrawer = ({
const { context } = useCampaignQuickActionContext() const { context } = useCampaignQuickActionContext()
const excludeContext = resolveHomeSearchExcludeContext(pathname, context) const excludeContext = resolveHomeSearchExcludeContext(pathname, context)
const { snapPoint, setSnapPoint, isDock, isFull } = useCampaignQuickActionsSnap() const { snapPoint, setSnapPoint, isDock, isFull } = useCampaignQuickActionsSnap()
const { uiFocused } = useHomeSearch() const { uiFocused, clear } = useHomeSearch()
const showActions = actions.length > 0 && isDock && !isFull const showActions = actions.length > 0 && isDock && !isFull
const showSearchResults = isDock || isFull const showSearchResults = isDock || isFull
const skipNextPathCollapseRef = useRef(true)
const wasUiFocusedRef = useRef(false)
const dismissToCollapsed = useCallback(() => {
// Clear first so the uiFocused→FULL effect cannot reopen on the same tick.
clear()
setSnapPoint(quickActionsSnapAfterDismiss())
}, [clear, setSnapPoint])
const handleSnapPointChange = useCallback( const handleSnapPointChange = useCallback(
(next: QuickActionsSnapPoint | string | number | null) => { (next: QuickActionsSnapPoint | string | number | null) => {
if ( if (next === QUICK_ACTIONS_SNAP_COLLAPSED) {
next === QUICK_ACTIONS_SNAP_COLLAPSED || dismissToCollapsed()
next === QUICK_ACTIONS_SNAP_DOCK || return
next === QUICK_ACTIONS_SNAP_FULL }
) { if (next === QUICK_ACTIONS_SNAP_DOCK || next === QUICK_ACTIONS_SNAP_FULL) {
setSnapPoint(next) setSnapPoint(next)
return return
} }
setSnapPoint(QUICK_ACTIONS_SNAP_COLLAPSED) dismissToCollapsed()
}, },
[setSnapPoint], [dismissToCollapsed, setSnapPoint],
) )
const toggleSnap = useCallback(() => { const toggleSnap = useCallback(() => {
setSnapPoint((current) => { if (uiFocused || quickActionsSnapIsFull(snapPoint)) {
if (quickActionsSnapIsFull(current)) return restoreSnapAfterSearch() dismissToCollapsed()
if (quickActionsSnapIsDock(current)) return QUICK_ACTIONS_SNAP_COLLAPSED return
return QUICK_ACTIONS_SNAP_DOCK }
}) if (quickActionsSnapIsDock(snapPoint)) {
}, [setSnapPoint]) setSnapPoint(QUICK_ACTIONS_SNAP_COLLAPSED)
return
}
setSnapPoint(QUICK_ACTIONS_SNAP_DOCK)
}, [dismissToCollapsed, setSnapPoint, snapPoint, uiFocused])
const handleOpenChange = useCallback( const handleOpenChange = useCallback(
(open: boolean) => { (open: boolean) => {
if (!open) { if (!open) {
setSnapPoint(QUICK_ACTIONS_SNAP_COLLAPSED) dismissToCollapsed()
} }
}, },
[setSnapPoint], [dismissToCollapsed],
) )
useEffect(() => {
if (skipNextPathCollapseRef.current) {
skipNextPathCollapseRef.current = false
return
}
dismissToCollapsed()
}, [dismissToCollapsed, pathname])
useEffect(() => { useEffect(() => {
if (!uiFocused) return if (!uiFocused) return
wasUiFocusedRef.current = true
if (!quickActionsSnapIsFull(snapPoint)) { if (!quickActionsSnapIsFull(snapPoint)) {
setSnapPoint(QUICK_ACTIONS_SNAP_FULL) setSnapPoint(QUICK_ACTIONS_SNAP_FULL)
} }
}, [snapPoint, setSnapPoint, uiFocused]) }, [snapPoint, setSnapPoint, uiFocused])
// Empty blur (uiFocused true→false) → collapsed. Skip the never-focused load path
// so the initial dock from B100 survives.
useEffect(() => { useEffect(() => {
if (uiFocused) return if (uiFocused) return
setSnapPoint(restoreSnapAfterSearch()) if (!wasUiFocusedRef.current) return
wasUiFocusedRef.current = false
setSnapPoint(quickActionsSnapAfterDismiss())
}, [setSnapPoint, uiFocused]) }, [setSnapPoint, uiFocused])
return ( return (
@ -96,8 +113,8 @@ export const CampaignQuickActionsDrawer = ({
open open
modal={false} modal={false}
swipeDirection="down" swipeDirection="down"
snapPoints={uiFocused ? [QUICK_ACTIONS_SNAP_FULL] : SNAP_POINTS} snapPoints={SNAP_POINTS}
snapPoint={uiFocused ? QUICK_ACTIONS_SNAP_FULL : snapPoint} snapPoint={snapPoint}
onSnapPointChange={handleSnapPointChange} onSnapPointChange={handleSnapPointChange}
onOpenChange={handleOpenChange} onOpenChange={handleOpenChange}
disablePointerDismissal disablePointerDismissal
@ -124,10 +141,11 @@ export const CampaignQuickActionsDrawer = ({
id="quickActionContext" id="quickActionContext"
className={cn( className={cn(
'flex min-h-0 flex-col overflow-y-auto px-4', 'flex min-h-0 flex-col overflow-y-auto px-4',
// B112 — dock/collapsed bottom gap ≈ ⅓ of prior gap-2 (keep safe-area).
isFull isFull
? 'flex-1 gap-2 pb-[max(0.25rem,env(safe-area-inset-bottom,0px))]' ? 'flex-1 gap-1 pb-[max(0.25rem,env(safe-area-inset-bottom,0px))]'
: cn( : cn(
'gap-2 pb-[max(0.25rem,env(safe-area-inset-bottom,0px))]', 'gap-1 pb-[max(0.25rem,env(safe-area-inset-bottom,0px))]',
isDock ? 'flex-1' : 'shrink-0', isDock ? 'flex-1' : 'shrink-0',
), ),
)} )}
@ -151,6 +169,8 @@ export const CampaignQuickActionsDrawer = ({
<CampaignGlobalSearchBody <CampaignGlobalSearchBody
placeholder={isDock || isFull ? undefined : ''} placeholder={isDock || isFull ? undefined : ''}
showResults={showSearchResults} showResults={showSearchResults}
blurUnfocusPolicy="whenEmpty"
compactStack
/> />
</HomeSearchExcludeProvider> </HomeSearchExcludeProvider>
</div> </div>

View file

@ -1,10 +1,8 @@
'use client' 'use client'
import { usePathname } from 'next/navigation'
import { import {
createContext, createContext,
useContext, useContext,
useEffect,
useMemo, useMemo,
useState, useState,
type Dispatch, type Dispatch,
@ -31,13 +29,9 @@ const CampaignQuickActionsSnapContext = createContext<CampaignQuickActionsSnapCo
) )
export const CampaignQuickActionsSnapProvider = ({ children }: { children: ReactNode }) => { export const CampaignQuickActionsSnapProvider = ({ children }: { children: ReactNode }) => {
const pathname = usePathname() // B112 — load = dock; pathname collapse lives in the drawer (needs `clear`).
const [snapPoint, setSnapPoint] = useState<QuickActionsSnapPoint | null>(QUICK_ACTIONS_SNAP_DOCK) const [snapPoint, setSnapPoint] = useState<QuickActionsSnapPoint | null>(QUICK_ACTIONS_SNAP_DOCK)
useEffect(() => {
setSnapPoint(QUICK_ACTIONS_SNAP_DOCK)
}, [pathname])
const value = useMemo( const value = useMemo(
(): CampaignQuickActionsSnapContextValue => ({ (): CampaignQuickActionsSnapContextValue => ({
snapPoint, snapPoint,

View file

@ -25,5 +25,20 @@ export const normalizeHomeSearchRaw = (raw: string): string => raw.trim()
export const homeSearchUiFocused = (input: { inputFocused: boolean; isActive: boolean }): boolean => export const homeSearchUiFocused = (input: { inputFocused: boolean; isActive: boolean }): boolean =>
input.inputFocused || input.isActive input.inputFocused || input.isActive
/**
* B112 drawer — blur with any typed text keeps the ritual; only empty blur
* unfocuses (Início still uses `whenInactive` via the default prop).
*/
export const homeSearchShouldUnfocusOnBlur = (
raw: string,
policy: 'whenInactive' | 'whenEmpty',
isActive: boolean,
): boolean => {
if (policy === 'whenEmpty') {
return normalizeHomeSearchRaw(raw).length === 0
}
return !isActive
}
/** B106 — mobile top bar back control when Início search is expanded. */ /** B106 — mobile top bar back control when Início search is expanded. */
export const HOME_SEARCH_COLLAPSE_ARIA_LABEL = 'Fechar busca' as const export const HOME_SEARCH_COLLAPSE_ARIA_LABEL = 'Fechar busca' as const

View file

@ -29,6 +29,16 @@ export const quickActionsSnapIsFull = (snap: QuickActionsSnapPoint | null): bool
export const quickActionsSnapIsDock = (snap: QuickActionsSnapPoint | null): boolean => export const quickActionsSnapIsDock = (snap: QuickActionsSnapPoint | null): boolean =>
snap === QUICK_ACTIONS_SNAP_DOCK snap === QUICK_ACTIONS_SNAP_DOCK
export const quickActionsSnapIsCollapsed = (snap: QuickActionsSnapPoint | null): boolean =>
snap === QUICK_ACTIONS_SNAP_COLLAPSED
/**
* B112 — empty blur, handle tap/swipe ↓, and in-chrome navigation all land on
* collapsed (clear search separately so `uiFocused → FULL` cannot reopen).
*/
export const quickActionsSnapAfterDismiss = (): QuickActionsSnapPoint =>
QUICK_ACTIONS_SNAP_COLLAPSED
/** Pure scroll-direction detector for the quick-actions peek (B105). */ /** Pure scroll-direction detector for the quick-actions peek (B105). */
export const quickActionsScrollDirection = ( export const quickActionsScrollDirection = (
previousScrollTop: number, previousScrollTop: number,

View file

@ -1,6 +1,9 @@
import { describe, expect, it } from 'vitest' import { describe, expect, it } from 'vitest'
import { homeSearchUiFocused } from '@/lib/campaignHomeSearchContract' import {
homeSearchShouldUnfocusOnBlur,
homeSearchUiFocused,
} from '@/lib/campaignHomeSearchContract'
describe('homeSearchUiFocused', () => { describe('homeSearchUiFocused', () => {
it('is true when the input is focused without an active query', () => { it('is true when the input is focused without an active query', () => {
@ -15,3 +18,17 @@ describe('homeSearchUiFocused', () => {
expect(homeSearchUiFocused({ inputFocused: false, isActive: false })).toBe(false) expect(homeSearchUiFocused({ inputFocused: false, isActive: false })).toBe(false)
}) })
}) })
describe('homeSearchShouldUnfocusOnBlur', () => {
it('whenEmpty unfocuses only blank raw (B112 drawer)', () => {
expect(homeSearchShouldUnfocusOnBlur('', 'whenEmpty', false)).toBe(true)
expect(homeSearchShouldUnfocusOnBlur(' ', 'whenEmpty', false)).toBe(true)
expect(homeSearchShouldUnfocusOnBlur('c', 'whenEmpty', false)).toBe(false)
expect(homeSearchShouldUnfocusOnBlur('ca', 'whenEmpty', true)).toBe(false)
})
it('whenInactive follows isActive (Início)', () => {
expect(homeSearchShouldUnfocusOnBlur('c', 'whenInactive', false)).toBe(true)
expect(homeSearchShouldUnfocusOnBlur('ca', 'whenInactive', true)).toBe(false)
})
})

View file

@ -20,6 +20,8 @@ import {
QUICK_ACTIONS_SNAP_DOCK, QUICK_ACTIONS_SNAP_DOCK,
QUICK_ACTIONS_SNAP_FULL, QUICK_ACTIONS_SNAP_FULL,
quickActionsScrollDirection, quickActionsScrollDirection,
quickActionsSnapAfterDismiss,
quickActionsSnapIsCollapsed,
quickActionsSnapIsDock, quickActionsSnapIsDock,
quickActionsSnapIsFull, quickActionsSnapIsFull,
} from '@/lib/campaignQuickActionSnap' } from '@/lib/campaignQuickActionSnap'
@ -28,8 +30,10 @@ vi.mock('@/lib/campaignJsonRequest', () => ({
postCampaignJson: vi.fn(), postCampaignJson: vi.fn(),
})) }))
const pathnameState = vi.hoisted(() => ({ current: '/campanha/municipios/foo' }))
vi.mock('next/navigation', () => ({ vi.mock('next/navigation', () => ({
usePathname: () => '/campanha/municipios/foo', usePathname: () => pathnameState.current,
})) }))
const idleSuggestPayload: HomeSearchSuccessResponse = { const idleSuggestPayload: HomeSearchSuccessResponse = {
@ -67,6 +71,7 @@ const searchWithPriorityPayload: HomeSearchSuccessResponse = {
const matchMediaMock = vi.fn() const matchMediaMock = vi.fn()
beforeEach(() => { beforeEach(() => {
pathnameState.current = '/campanha/municipios/foo'
matchMediaMock.mockImplementation((query: string) => ({ matchMediaMock.mockImplementation((query: string) => ({
matches: false, matches: false,
media: query, media: query,
@ -263,7 +268,7 @@ describe('CampaignQuickActionsDrawer (B105)', () => {
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe('full') expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe('full')
}) })
it('stays full while search remains focused even if the handle collapses (B109)', () => { it('handle with live query clears and collapses (B112)', async () => {
vi.mocked(postCampaignJson).mockResolvedValue({ vi.mocked(postCampaignJson).mockResolvedValue({
ok: true, ok: true,
payload: idleSuggestPayload, payload: idleSuggestPayload,
@ -271,9 +276,110 @@ describe('CampaignQuickActionsDrawer (B105)', () => {
renderQuickActionsChrome(<CampaignQuickActionsDrawer actions={[]} />) renderQuickActionsChrome(<CampaignQuickActionsDrawer actions={[]} />)
fireEvent.focus(screen.getByLabelText('Buscar na campanha')) const input = screen.getByLabelText('Buscar na campanha')
fireEvent.click(screen.getByRole('button', { name: 'Ocultar ações rápidas' })) fireEvent.focus(input)
fireEvent.change(input, { target: { value: 'cairu' } })
await waitFor(() => {
expect((input as HTMLInputElement).value).toBe('cairu')
})
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe('full') expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe('full')
fireEvent.click(screen.getByRole('button', { name: 'Ocultar ações rápidas' }))
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe(
'collapsed',
)
expect((screen.getByLabelText('Buscar na campanha') as HTMLInputElement).value).toBe('')
})
it('empty blur collapses; blur with text stays full (B112)', async () => {
vi.mocked(postCampaignJson).mockResolvedValue({
ok: true,
payload: idleSuggestPayload,
})
renderQuickActionsChrome(<CampaignQuickActionsDrawer actions={[]} />)
const input = screen.getByLabelText('Buscar na campanha')
fireEvent.focus(input)
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe('full')
fireEvent.blur(input)
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe(
'collapsed',
)
fireEvent.focus(input)
fireEvent.change(input, { target: { value: 'ca' } })
await waitFor(() => {
expect((input as HTMLInputElement).value).toBe('ca')
})
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe('full')
fireEvent.blur(input)
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe('full')
expect((input as HTMLInputElement).value).toBe('ca')
})
it('in-chrome pathname update clears and collapses without remounting providers (B112)', async () => {
vi.mocked(postCampaignJson).mockResolvedValue({
ok: true,
payload: idleSuggestPayload,
})
const { rerender } = render(
<TooltipProvider delayDuration={300}>
<CampaignQuickActionContextProvider>
<CampaignQuickActionsSnapProvider>
<CampaignGlobalSearchProvider>
<CampaignQuickActionsDrawer actions={[]} />
</CampaignGlobalSearchProvider>
</CampaignQuickActionsSnapProvider>
</CampaignQuickActionContextProvider>
</TooltipProvider>,
)
const input = screen.getByLabelText('Buscar na campanha')
fireEvent.focus(input)
fireEvent.change(input, { target: { value: 'cairu' } })
await waitFor(() => {
expect((input as HTMLInputElement).value).toBe('cairu')
})
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe('full')
pathnameState.current = '/campanha/liderancas/1'
rerender(
<TooltipProvider delayDuration={300}>
<CampaignQuickActionContextProvider>
<CampaignQuickActionsSnapProvider>
<CampaignGlobalSearchProvider>
<CampaignQuickActionsDrawer actions={[]} />
</CampaignGlobalSearchProvider>
</CampaignQuickActionsSnapProvider>
</CampaignQuickActionContextProvider>
</TooltipProvider>,
)
expect(document.getElementById('quickActionContext')?.getAttribute('data-snap')).toBe(
'collapsed',
)
expect((screen.getByLabelText('Buscar na campanha') as HTMLInputElement).value).toBe('')
})
it('uses compact bottom stack spacing in the drawer (B112)', () => {
vi.mocked(postCampaignJson).mockResolvedValue({
ok: true,
payload: idleSuggestPayload,
})
renderQuickActionsChrome(<CampaignQuickActionsDrawer actions={[]} />)
const context = document.getElementById('quickActionContext')
expect(context?.className).toContain('gap-1')
expect(context?.className).toContain('pb-[max(0.25rem,env(safe-area-inset-bottom,0px))]')
const searchStack = document.querySelector('[data-slot="home-search-results"]')?.parentElement
expect(searchStack?.className).toContain('gap-1.5')
}) })
it('toggles between dock and collapsed from the handle', () => { it('toggles between dock and collapsed from the handle', () => {
@ -356,13 +462,15 @@ describe('CampaignContentScroll quick-actions direction (B105)', () => {
}) })
describe('campaignQuickActionSnap', () => { describe('campaignQuickActionSnap', () => {
it('detects dock and full snaps', () => { it('detects dock, full, and collapsed snaps', () => {
expect(quickActionsSnapIsDock(QUICK_ACTIONS_SNAP_DOCK)).toBe(true) expect(quickActionsSnapIsDock(QUICK_ACTIONS_SNAP_DOCK)).toBe(true)
expect(quickActionsSnapIsDock(QUICK_ACTIONS_SNAP_COLLAPSED)).toBe(false) expect(quickActionsSnapIsDock(QUICK_ACTIONS_SNAP_COLLAPSED)).toBe(false)
expect(quickActionsSnapIsDock(QUICK_ACTIONS_SNAP_FULL)).toBe(false) expect(quickActionsSnapIsDock(QUICK_ACTIONS_SNAP_FULL)).toBe(false)
expect(quickActionsSnapIsDock(null)).toBe(false) expect(quickActionsSnapIsDock(null)).toBe(false)
expect(quickActionsSnapIsFull(QUICK_ACTIONS_SNAP_FULL)).toBe(true) expect(quickActionsSnapIsFull(QUICK_ACTIONS_SNAP_FULL)).toBe(true)
expect(quickActionsSnapIsFull(QUICK_ACTIONS_SNAP_DOCK)).toBe(false) expect(quickActionsSnapIsFull(QUICK_ACTIONS_SNAP_DOCK)).toBe(false)
expect(quickActionsSnapIsCollapsed(QUICK_ACTIONS_SNAP_COLLAPSED)).toBe(true)
expect(quickActionsSnapAfterDismiss()).toBe(QUICK_ACTIONS_SNAP_COLLAPSED)
}) })
it('resolves scroll direction from delta threshold', () => { it('resolves scroll direction from delta threshold', () => {