mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-25 05:07:05 +00:00
* feat(fue): just-in-time callouts for three unlabelled icon-only controls The message-content search scope toggle, the session list sort/filter menu, and the per-session title lock are shipped, icon-only controls with no text label and no existing discovery path. Wire each into the existing hapi.fue.v1 primitive (useFue + FueDot + FueCallout) so first click explains the control, following the pattern already used for scratchlist, terminal-to-agent, and rich composer mentions. via HAPI (https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> * fix(fue): don't collapse search on blur into the portaled FUE callout The scope FueCallout (like the other two) portals to document.body, so it is never a DOM descendant of the search container. The container's existing onBlur handler used a raw DOM .contains() check to decide whether to collapse the search bar, which doesn't account for that — clicking "Got it" in the callout read as focus leaving the search bar entirely and collapsed it out from under the dismiss action. Also marks FueCallout's portal root with a stable data-fue-callout attribute so any caller (not just this one) can make the same "is this interaction actually inside my UI" check despite the portal. Investigated the review bot's related "modal interaction scope" concern on RenameSessionDialog.tsx against a differential control (confirmed a truly detached element at the same point in the interaction sequence does close the dialog, so the harness/timing is valid): clicking the title-lock callout does NOT close the dialog, because Radix's outside-pointerdown check is itself a React onPointerDownCapture handler, and React's synthetic events bubble along the logical JSX tree regardless of portal placement. No fix needed there. That investigation surfaced a narrower, real limitation instead: Radix's FocusScope traps focus via a raw DOM containment check (unlike the pointerdown case, there's no portal transparency here), so Tab/programmatic focus into the portaled callout gets pulled back to the dialog's input. Mouse-click dismiss and Escape-to-dismiss both still work. Tracked with an it.fails() regression marker rather than left invisible; not fixed in this PR (would mean restructuring FueCallout's portal/positioning, which is riskier than this diff's scope). via HAPI (https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> * fix(fue): keep the callout clickable when hosted inside a modal dialog The automated review's follow-up pass caught something my first response missed: Radix's modal Dialog sets document.body's pointer-events to none and re-enables it only on its own content node. FueCallout's portal is a separate sibling of that node — document.body, not a descendant of DialogContent — so without an explicit override its buttons inherited pointer-events: none and were unclickable by a real pointer while the rename dialog was open. This is distinct from (and more severe than) the modal-interaction-scope question already answered: that was about whether Radix's own outside-click *detection* misfires on the callout (it doesn't, verified earlier), not about whether a real click can land on it at all. A plain fireEvent.click in jsdom bypasses CSS hit-testing entirely, which is exactly why the existing "dismisses and persists acknowledgement on Got it" test kept passing throughout — it was never exercising this path. Fixed by setting pointer-events: auto on the callout panel unconditionally. Harmless outside a modal context (no other FUE caller sets body's pointer-events to none). Red/green verified. via HAPI (https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> --------- Co-authored-by: HAPI <noreply@hapi.run>
140 lines
5.8 KiB
TypeScript
140 lines
5.8 KiB
TypeScript
import { fireEvent, render, screen, within } from '@testing-library/react'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { I18nProvider } from '@/lib/i18n-context'
|
|
import { SessionListSearch } from './SessionList'
|
|
|
|
function renderSearch(overrides: Partial<Parameters<typeof SessionListSearch>[0]> = {}) {
|
|
return render(
|
|
<I18nProvider>
|
|
<SessionListSearch
|
|
value=""
|
|
onChange={vi.fn()}
|
|
expanded={true}
|
|
onExpandedChange={vi.fn()}
|
|
searchMode="metadata"
|
|
onSearchModeChange={vi.fn()}
|
|
{...overrides}
|
|
/>
|
|
</I18nProvider>
|
|
)
|
|
}
|
|
|
|
describe('SessionListSearch content scope', () => {
|
|
it('flips to content scope in one tap without changing the default scope', () => {
|
|
const onSearchModeChange = vi.fn()
|
|
renderSearch({ onSearchModeChange })
|
|
|
|
expect(screen.getByRole('searchbox').getAttribute('placeholder')).toContain('title/path')
|
|
const scopeButton = screen.getByTestId('session-list-search-scope')
|
|
expect(scopeButton).toHaveAttribute('data-search-scope', 'metadata')
|
|
fireEvent.click(scopeButton)
|
|
expect(onSearchModeChange).toHaveBeenCalledWith('content')
|
|
})
|
|
|
|
it('flips back to metadata scope from content scope', () => {
|
|
const onSearchModeChange = vi.fn()
|
|
renderSearch({ searchMode: 'content', onSearchModeChange })
|
|
|
|
fireEvent.click(screen.getByTestId('session-list-search-scope'))
|
|
expect(onSearchModeChange).toHaveBeenCalledWith('metadata')
|
|
})
|
|
|
|
it('names the real scopes instead of Default/Content chrome labels', () => {
|
|
renderSearch()
|
|
|
|
const scopeButton = screen.getByTestId('session-list-search-scope')
|
|
// No chrome label text: the glyph plus tooltip carry the mode.
|
|
expect(scopeButton).toHaveTextContent('')
|
|
expect(scopeButton.getAttribute('title')).toBe(
|
|
'Searching session details: title, summary, path, Agent, machine, ID. Switch to Message text'
|
|
)
|
|
expect(scopeButton.getAttribute('aria-label')).toBe(scopeButton.getAttribute('title'))
|
|
|
|
renderSearch({ searchMode: 'content' })
|
|
const contentScope = screen.getAllByTestId('session-list-search-scope')[1]!
|
|
expect(contentScope.getAttribute('title')).toBe(
|
|
'Searching message text inside sessions. Switch to Session details'
|
|
)
|
|
})
|
|
|
|
it('gives the scope toggle the same hit target as the clear endcap', () => {
|
|
renderSearch({ value: 'cache' })
|
|
|
|
const scopeButton = screen.getByTestId('session-list-search-scope')
|
|
const clearButton = screen.getByRole('button', { name: 'Clear search' })
|
|
for (const size of ['min-h-[48px]', 'min-w-[48px]']) {
|
|
expect(scopeButton.className).toContain(size)
|
|
expect(clearButton.className).toContain(size)
|
|
}
|
|
})
|
|
|
|
it('keeps the content-scope glyph on the collapsed applying chip', () => {
|
|
renderSearch({ expanded: false, value: 'cache', searchMode: 'content' })
|
|
|
|
expect(screen.getByText('cache')).toBeInTheDocument()
|
|
const chip = document.querySelector('[data-toolbar-chrome][data-search-scope]')
|
|
expect(chip).toHaveAttribute('data-search-scope', 'content')
|
|
})
|
|
|
|
it('leaves the idle collapsed button a plain magnifier with no query applied', () => {
|
|
renderSearch({ expanded: false, value: '', searchMode: 'content' })
|
|
|
|
// No scope is in effect yet, and this button is what opens search.
|
|
expect(document.querySelector('[data-toolbar-chrome][data-search-scope]')).toBeNull()
|
|
})
|
|
|
|
it('uses the message-content placeholder after selecting content scope', () => {
|
|
renderSearch({ searchMode: 'content' })
|
|
|
|
expect(screen.getByRole('searchbox').getAttribute('placeholder')).toBe('Search message content')
|
|
})
|
|
})
|
|
|
|
describe('SessionListSearch content-scope FUE', () => {
|
|
afterEach(() => {
|
|
window.localStorage.removeItem('hapi.fue.v1.session-list-search-scope')
|
|
})
|
|
|
|
it('shows a pulsing FUE dot on the scope toggle until acknowledged', () => {
|
|
renderSearch()
|
|
|
|
const scopeButton = screen.getByTestId('session-list-search-scope')
|
|
expect(within(scopeButton).getByRole('status', { name: 'New feature available' })).toBeInTheDocument()
|
|
})
|
|
|
|
it('flips scope and shows the explainer on first click', () => {
|
|
const onSearchModeChange = vi.fn()
|
|
renderSearch({ onSearchModeChange })
|
|
|
|
fireEvent.click(screen.getByTestId('session-list-search-scope'))
|
|
|
|
expect(onSearchModeChange).toHaveBeenCalledWith('content')
|
|
expect(screen.getByRole('dialog', { name: 'New: search message text' })).toBeInTheDocument()
|
|
})
|
|
|
|
it('dismisses and persists acknowledgement on Got it', () => {
|
|
renderSearch()
|
|
|
|
fireEvent.click(screen.getByTestId('session-list-search-scope'))
|
|
fireEvent.click(screen.getByRole('button', { name: 'Got it' }))
|
|
|
|
expect(window.localStorage.getItem('hapi.fue.v1.session-list-search-scope')).toBe('1')
|
|
expect(screen.queryByRole('dialog', { name: 'New: search message text' })).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('does not collapse the search bar when focus moves into the portaled callout', () => {
|
|
const onExpandedChange = vi.fn()
|
|
renderSearch({ onExpandedChange })
|
|
|
|
fireEvent.click(screen.getByTestId('session-list-search-scope'))
|
|
const gotIt = screen.getByRole('button', { name: 'Got it' })
|
|
|
|
// FueCallout portals to document.body, so it's never a DOM descendant
|
|
// of the search container — without the fix this blur would read as
|
|
// focus leaving and collapse the bar out from under the callout.
|
|
fireEvent.blur(screen.getByTestId('session-list-search'), { relatedTarget: gotIt })
|
|
|
|
expect(onExpandedChange).not.toHaveBeenCalledWith(false)
|
|
})
|
|
})
|