Files
faunosteo/apps/app/tests/helpers/findingDialog.ts
T
bchanot abc781df52 feat(editor): references dialog over the finding, view mode
A modal Dialog replaces the citations side sheet; families open it too
(isCitable). The finding dialog shows only « Références citées » and
« X références », also at zero; its edit form no longer carries
reference_ids. A dirty form refusing « Aller à » or « Tout afficher »
closes the clean references dialog first.
2026-11-15 16:13:57 +01:00

37 lines
1.3 KiB
TypeScript

import { act, screen, waitFor, within } from '@testing-library/react'
import type userEvent from '@testing-library/user-event'
import { expect } from 'vitest'
type User = ReturnType<typeof userEvent.setup>
export const treeRow = (name: RegExp) => screen.getByRole('treeitem', { name })
/** The open finding dialog: the layer dialog that is not the references dialog. */
export const findingDialog = () =>
[...document.querySelectorAll<HTMLElement>('dialog[open][data-layer]')].find(
(dialog) => !dialog.querySelector('[data-testid="editor-citations-panel"]'),
) ?? null
/** Expands a tree row from the keyboard: a click would open its dialog (R2F-3). */
export async function expandRow(user: User, name: RegExp) {
act(() => treeRow(name).focus())
await user.keyboard('{ArrowRight}')
}
/**
* Activates the row of `name` (a click): its dialog opens. The family is expanded first
* when the row is hidden under it.
*/
export async function openFinding(
user: User,
name: RegExp,
family: RegExp = /Cat A/,
) {
if (!screen.queryByRole('treeitem', { name })) await expandRow(user, family)
await user.click(treeRow(name))
await waitFor(() => expect(findingDialog()).not.toBeNull())
}
/** The dialog's content, queried like a place. */
export const inFindingDialog = () => within(findingDialog()!)