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

56 lines
1.6 KiB
TypeScript

import { vi } from 'vitest'
import type { FindingLayer } from '@/editor/tabs'
import CitationsSheet from '@/components/editor/references/CitationsSheet'
import FindingsTab from '@/components/editor/tabs/FindingsTab'
import { findingLayerOf } from '@/editor/findingLayer'
import { citationsOfView } from '@/editor/navigation'
import { useEditorNavigation } from '@/editor/useEditorNavigation'
import { ReadOnlyContext } from '@/editor/editingContext'
/**
* Constats with the navigation that drives its dialog and the sheet over it (what the
* workspace gives it), without the rest of the editor.
*/
export default function FindingsHost({
readOnly = false,
}: {
readOnly?: boolean
}) {
const nav = useEditorNavigation('findings')
return (
<ReadOnlyContext value={readOnly}>
<FindingsTab
readOnly={readOnly}
navigate={vi.fn()}
reloadSheet={vi.fn()}
layer={findingLayerOf(nav)}
/>
<CitationsSheet
citedBy={citationsOfView(nav.state)}
readOnly={readOnly}
onClose={nav.closeCitations}
onShowAll={() => undefined}
navigate={nav.navigate}
onEdit={nav.references.open}
returnFocus={nav.citationsTrigger}
/>
</ReadOnlyContext>
)
}
/** A layer that never opens: for a test that mounts Constats only to read its focus. */
export const testLayer: FindingLayer = {
view: null,
guards: {
register: () => undefined,
ask: () => ({ allowed: true }),
askAll: () => ({ allowed: true }),
},
open: () => undefined,
start: () => undefined,
close: () => true,
replace: () => undefined,
openCitations: () => undefined,
announce: () => undefined,
}