Files
hapi/web/src/components/Fue.test.ts
T
f6da005b50 feat(web): FUE + composer hint for session @-mentions (#1274)
* feat(web): FUE + placeholder for rich composer session @-mentions

Discover session @-mentions via composer-grounded FUE and always-on
placeholder copy when rich composer is active (#1273).

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(web): notify onFocus after programmatic rich-composer autofocus

Playwright headless (and some engines) skip the DOM focus event for
element.focus(), so FUE engage never ran. Call the onFocus prop after
autofocus so discovery still works.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(web): engage rich-composer FUE on mount

DOM focus events are unreliable for programmatic autofocus (and in
Playwright). Treat the live rich composer as the affordance and open
the callout when the rich path mounts.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(web): measure FueCallout height; ellipsis rich placeholder

Bot review on #1274: position from real panel height (ResizeObserver)
so multi-line FUE bodies clear the composer, and keep long mention
placeholders on one ellipsized line in the input row.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(web): Escape dismisses rich-composer FUE; keep expand flex chain

Escape while the mention FUE is engaging only dismisses the callout
(no abort/collapse). FUE anchor is a flex container so expanded
RichComposerInput still fills height. Mock resolveComposerPlaceholderKey
in sendError tests.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-04 11:18:21 +08:00

85 lines
3.0 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { computeFueCalloutPlacement } from './Fue'
const VIEWPORT = { width: 1024, height: 768 }
describe('computeFueCalloutPlacement', () => {
it('floats above the anchor when there is room', () => {
const result = computeFueCalloutPlacement({
anchor: { top: 600, left: 100, right: 132, bottom: 632 },
panelWidth: 256,
panelHeight: 96,
viewport: VIEWPORT,
gap: 8,
})
expect(result.placement).toBe('above')
// top = anchor.top - gap - panelHeight = 600 - 8 - 96 = 496
expect(result.top).toBe(496)
// left aligns with anchor.left when on-screen
expect(result.left).toBe(100)
})
it('drops below the anchor when there is not enough room above', () => {
const result = computeFueCalloutPlacement({
anchor: { top: 20, left: 100, right: 132, bottom: 52 },
panelWidth: 256,
panelHeight: 96,
viewport: VIEWPORT,
gap: 8,
})
expect(result.placement).toBe('below')
// top = anchor.bottom + gap = 52 + 8 = 60 (clamped to fit viewport)
expect(result.top).toBe(60)
})
it('clamps left edge to viewport margin when anchor is at the left edge', () => {
const result = computeFueCalloutPlacement({
anchor: { top: 600, left: 0, right: 32, bottom: 632 },
panelWidth: 256,
panelHeight: 96,
viewport: VIEWPORT,
margin: 8,
})
// anchor.left=0, but margin=8 means minLeft=8
expect(result.left).toBe(8)
})
it('clamps left edge so panel does not overflow right viewport edge', () => {
const result = computeFueCalloutPlacement({
anchor: { top: 600, left: 900, right: 932, bottom: 632 },
panelWidth: 256,
panelHeight: 96,
viewport: VIEWPORT,
margin: 8,
})
// maxLeft = viewportRight - panelWidth - margin = 1024 - 256 - 8 = 760
expect(result.left).toBe(760)
})
it('respects viewport offset (e.g. visualViewport on mobile keyboards)', () => {
const result = computeFueCalloutPlacement({
anchor: { top: 600, left: 100, right: 132, bottom: 632 },
panelWidth: 256,
panelHeight: 96,
viewport: { width: 1024, height: 600, offsetTop: 0, offsetLeft: 0 },
gap: 8,
margin: 8,
})
expect(result.placement).toBe('above')
expect(result.top).toBeGreaterThanOrEqual(8)
})
it('uses measured panelHeight so taller callouts clear the anchor', () => {
const result = computeFueCalloutPlacement({
anchor: { top: 700, left: 100, right: 132, bottom: 732 },
panelWidth: 288,
panelHeight: 180,
viewport: VIEWPORT,
gap: 8,
})
expect(result.placement).toBe('above')
// top = anchor.top - gap - panelHeight = 700 - 8 - 180 = 512
expect(result.top).toBe(512)
})
})