Files
faunosteo/apps/app/tests/helpers/referencesHost.tsx
T

56 lines
1.8 KiB
TypeScript

import { vi } from 'vitest'
import ReferenceDialog from '@/components/editor/references/ReferenceDialog'
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
import { ReadOnlyContext } from '@/editor/editingContext'
import { referenceLayerOf } from '@/editor/findingLayer'
import { AnnounceContext } from '@/editor/focusRequest'
import { defaultView, type EditorView } from '@/editor/navigation'
import type { EditorPlaceProps } from '@/editor/tabs'
import {
useEditorNavigation,
type EditorNavigation,
} from '@/editor/useEditorNavigation'
interface Props extends Partial<EditorPlaceProps> {
/** The view the editor starts on (a filter, a dialog); the References tab by default. */
view?: EditorView
/** Reads the navigation each render, for a test that drives or inspects it. */
onNav?: (nav: EditorNavigation) => void
/** Renders the polite live region (the workspace's), for a test that reads announcements. */
live?: boolean
}
/**
* The References tab with the navigation that drives its dialog and its filter (what the
* workspace gives it), without the rest of the editor.
*/
export default function ReferencesHost({
readOnly = false,
view,
onNav,
live = false,
...extra
}: Props) {
const nav = useEditorNavigation(
'references',
view ?? defaultView('references'),
)
onNav?.(nav)
const references = referenceLayerOf(nav)
return (
<ReadOnlyContext value={readOnly}>
<AnnounceContext value={nav.announce}>
<ReferencesTab
readOnly={readOnly}
navigate={vi.fn()}
reloadSheet={vi.fn()}
{...extra}
references={references}
/>
<ReferenceDialog layer={references} readOnly={readOnly} />
</AnnounceContext>
{live && <p aria-live="polite">{nav.live}</p>}
</ReadOnlyContext>
)
}