|
| 1 | +/** |
| 2 | + * @vitest-environment jsdom |
| 3 | + */ |
| 4 | +import { act } from 'react' |
| 5 | +import { createRoot, type Root } from 'react-dom/client' |
| 6 | +import { afterEach, describe, expect, it } from 'vitest' |
| 7 | +import { SubBlockRowView } from './sub-block-row-view' |
| 8 | + |
| 9 | +let host: HTMLDivElement | null = null |
| 10 | +let root: Root | null = null |
| 11 | + |
| 12 | +function mount(element: React.ReactElement): HTMLDivElement { |
| 13 | + host = document.createElement('div') |
| 14 | + document.body.appendChild(host) |
| 15 | + root = createRoot(host) |
| 16 | + act(() => root?.render(element)) |
| 17 | + return host |
| 18 | +} |
| 19 | + |
| 20 | +function hover(element: HTMLElement): void { |
| 21 | + act(() => { |
| 22 | + element.dispatchEvent( |
| 23 | + new MouseEvent('pointerover', { bubbles: true, clientX: 100, clientY: 100 }) |
| 24 | + ) |
| 25 | + }) |
| 26 | +} |
| 27 | + |
| 28 | +afterEach(() => { |
| 29 | + act(() => root?.unmount()) |
| 30 | + host?.remove() |
| 31 | + document.body.querySelectorAll('[data-native-surface-overlay]').forEach((node) => node.remove()) |
| 32 | + host = null |
| 33 | + root = null |
| 34 | +}) |
| 35 | + |
| 36 | +describe('SubBlockRowView tooltip values', () => { |
| 37 | + it('shows a full tooltip for an upstream-truncated inline value', () => { |
| 38 | + const compactValue = 'You are a research assistant. Keep every instruction...' |
| 39 | + const fullValue = |
| 40 | + 'You are a research assistant. Keep every instruction, constraint, and output requirement.' |
| 41 | + const container = mount( |
| 42 | + <SubBlockRowView |
| 43 | + title='Messages' |
| 44 | + displayValue={compactValue} |
| 45 | + tooltipValue={fullValue} |
| 46 | + variant='inline-value' |
| 47 | + /> |
| 48 | + ) |
| 49 | + |
| 50 | + expect(container.textContent).toBe(compactValue) |
| 51 | + |
| 52 | + const trigger = container.querySelector<HTMLElement>('.truncate') |
| 53 | + if (!trigger) throw new Error('inline tooltip trigger not found') |
| 54 | + hover(trigger) |
| 55 | + |
| 56 | + expect(document.body.querySelector('[data-native-surface-overlay]')?.textContent).toBe( |
| 57 | + fullValue |
| 58 | + ) |
| 59 | + }) |
| 60 | +}) |
0 commit comments