feat(app): back to the parent view in the bilan detail window
This commit is contained in:
1 parent
4180d5e089
commit
a5c6ec4bcd
8 files changed
+281
-35
No files matched your search
@@ -14,7 +14,9 @@ import EditInfosDialog, {
|
|||||||
type Identity,
|
type Identity,
|
||||||
} from '@/components/report/EditInfosDialog'
|
} from '@/components/report/EditInfosDialog'
|
||||||
import DisclaimerDialog from '@/components/report/DisclaimerDialog'
|
import DisclaimerDialog from '@/components/report/DisclaimerDialog'
|
||||||
import CoreStoppedNotice, { CopyReportButton } from '@/components/report/CoreStoppedNotice'
|
import CoreStoppedNotice, {
|
||||||
|
CopyReportButton,
|
||||||
|
} from '@/components/report/CoreStoppedNotice'
|
||||||
import CoreUnavailable from '@/components/report/CoreUnavailable'
|
import CoreUnavailable from '@/components/report/CoreUnavailable'
|
||||||
import HeldSessionPanel from '@/components/report/HeldSessionPanel'
|
import HeldSessionPanel from '@/components/report/HeldSessionPanel'
|
||||||
import Notice from '@/components/ui/Notice'
|
import Notice from '@/components/ui/Notice'
|
||||||
@@ -34,10 +36,7 @@ import { pickLabel } from '@/i18n/pickLocaleLabel'
|
|||||||
import type { ViewStates } from '@/anatomy/drawing'
|
import type { ViewStates } from '@/anatomy/drawing'
|
||||||
import { exportReportToPdf } from '@/pdf/export'
|
import { exportReportToPdf } from '@/pdf/export'
|
||||||
import { downloadBlob } from '@/lib/download'
|
import { downloadBlob } from '@/lib/download'
|
||||||
import type {
|
import type { ExportWarning, RebaseOutcome } from '@faunosteo/core-wasm/types'
|
||||||
ExportWarning,
|
|
||||||
RebaseOutcome,
|
|
||||||
} from '@faunosteo/core-wasm/types'
|
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
|
import { DEFAULT_SPECIES_ID } from './NewReportRoute'
|
||||||
import { coreFailureMessage } from '@/core/failure'
|
import { coreFailureMessage } from '@/core/failure'
|
||||||
@@ -79,13 +78,12 @@ export default function EditorRoute() {
|
|||||||
const sheet = useSheet(report?.animal.speciesId ?? DEFAULT_SPECIES_ID)
|
const sheet = useSheet(report?.animal.speciesId ?? DEFAULT_SPECIES_ID)
|
||||||
const stopped = useCoreStopped()
|
const stopped = useCoreStopped()
|
||||||
|
|
||||||
const [detailViewId, setDetailViewId] = useState<string | null>(null)
|
// The views of the detail window, the one shown last; empty while it is closed.
|
||||||
|
const [detailStack, setDetailStack] = useState<string[]>([])
|
||||||
const [vertebraTarget, setVertebraTarget] = useState<VertebraTarget | null>(
|
const [vertebraTarget, setVertebraTarget] = useState<VertebraTarget | null>(
|
||||||
null,
|
null,
|
||||||
)
|
)
|
||||||
const [lateralTarget, setLateralTarget] = useState<LateralTarget | null>(
|
const [lateralTarget, setLateralTarget] = useState<LateralTarget | null>(null)
|
||||||
null,
|
|
||||||
)
|
|
||||||
// The core failed while reading the draft: stay here, keep the draft, offer a retry.
|
// The core failed while reading the draft: stay here, keep the draft, offer a retry.
|
||||||
const [restoreFailed, setRestoreFailed] = useState(false)
|
const [restoreFailed, setRestoreFailed] = useState(false)
|
||||||
// Texts that could not be set aside: the resolution panel replaces the editor.
|
// Texts that could not be set aside: the resolution panel replaces the editor.
|
||||||
@@ -166,7 +164,7 @@ export default function EditorRoute() {
|
|||||||
}, [activeObs])
|
}, [activeObs])
|
||||||
|
|
||||||
const onZoneClick = useCallback(
|
const onZoneClick = useCallback(
|
||||||
(annotationId: string) => {
|
(annotationId: string, fromViewId: string) => {
|
||||||
// Fresh state: two clicks may land before React re-renders the handler.
|
// Fresh state: two clicks may land before React re-renders the handler.
|
||||||
const { report, activeObservationIndex: activeIndex } =
|
const { report, activeObservationIndex: activeIndex } =
|
||||||
useReportStore.getState()
|
useReportStore.getState()
|
||||||
@@ -176,10 +174,18 @@ export default function EditorRoute() {
|
|||||||
const outcome = sheet.index.ops.zoneClick(activeObs ?? null, annotationId)
|
const outcome = sheet.index.ops.zoneClick(activeObs ?? null, annotationId)
|
||||||
if (!outcome.ok) return window.alert(coreFailureMessage(t))
|
if (!outcome.ok) return window.alert(coreFailureMessage(t))
|
||||||
const click = outcome.value
|
const click = outcome.value
|
||||||
if (click.observation) store.updateObservation(activeIndex, click.observation)
|
if (click.observation)
|
||||||
|
store.updateObservation(activeIndex, click.observation)
|
||||||
switch (click.kind) {
|
switch (click.kind) {
|
||||||
case 'open_view':
|
case 'open_view':
|
||||||
return setDetailViewId(click.viewId ?? null)
|
// From inside the window the view is pushed; from the page it starts a stack.
|
||||||
|
return setDetailStack((stack) =>
|
||||||
|
!click.viewId
|
||||||
|
? []
|
||||||
|
: stack[stack.length - 1] === fromViewId
|
||||||
|
? [...stack, click.viewId]
|
||||||
|
: [click.viewId],
|
||||||
|
)
|
||||||
case 'activate_fallback':
|
case 'activate_fallback':
|
||||||
return store.setActiveObservation(report.observations.length - 1)
|
return store.setActiveObservation(report.observations.length - 1)
|
||||||
case 'open_vertebra_picker':
|
case 'open_vertebra_picker':
|
||||||
@@ -302,7 +308,10 @@ export default function EditorRoute() {
|
|||||||
}
|
}
|
||||||
if (sheet.status === 'none') return null
|
if (sheet.status === 'none') return null
|
||||||
const index = sheet.index
|
const index = sheet.index
|
||||||
const detailView = detailViewId ? index.view(detailViewId) : undefined
|
const detailId = detailStack[detailStack.length - 1]
|
||||||
|
const detailView = detailId ? index.view(detailId) : undefined
|
||||||
|
const parentId = detailStack[detailStack.length - 2]
|
||||||
|
const parentView = parentId ? index.view(parentId) : undefined
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen flex flex-col">
|
<main className="min-h-screen flex flex-col">
|
||||||
@@ -385,7 +394,11 @@ export default function EditorRoute() {
|
|||||||
{detailView && (
|
{detailView && (
|
||||||
<DetailModal
|
<DetailModal
|
||||||
open
|
open
|
||||||
onClose={() => setDetailViewId(null)}
|
onClose={() => setDetailStack([])}
|
||||||
|
backTo={
|
||||||
|
parentView ? { name: pickLabel(parentView.name, locale) } : null
|
||||||
|
}
|
||||||
|
onBack={() => setDetailStack((stack) => stack.slice(0, -1))}
|
||||||
index={index}
|
index={index}
|
||||||
viewId={detailView.id}
|
viewId={detailView.id}
|
||||||
title={pickLabel(detailView.name, locale)}
|
title={pickLabel(detailView.name, locale)}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
import { useEffect, useRef } from 'react'
|
||||||
import Dialog from '@/components/ui/Dialog'
|
import Dialog from '@/components/ui/Dialog'
|
||||||
import AnatomyCanvas from './AnatomyCanvas'
|
import AnatomyCanvas from './AnatomyCanvas'
|
||||||
import type { ViewStates } from '@/anatomy/drawing'
|
import type { ViewStates } from '@/anatomy/drawing'
|
||||||
import type { SheetIndex } from '@/services/sheetIndex'
|
import type { SheetIndex } from '@/services/sheetIndex'
|
||||||
|
import Button from '@/components/ui/Button'
|
||||||
|
import Icon from '@/components/ui/Icon'
|
||||||
import { useT } from '@/i18n/useT'
|
import { useT } from '@/i18n/useT'
|
||||||
|
|
||||||
export interface DetailModalProps {
|
export interface DetailModalProps {
|
||||||
@@ -12,8 +15,18 @@ export interface DetailModalProps {
|
|||||||
title: string
|
title: string
|
||||||
states: ViewStates
|
states: ViewStates
|
||||||
onZoneClick: (annotationId: string, viewId: string) => void
|
onZoneClick: (annotationId: string, viewId: string) => void
|
||||||
|
/** The parent view when the window holds a view opened from another one. */
|
||||||
|
backTo: { name: string } | null
|
||||||
|
onBack: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TITLE_ID = 'detail-modal-title'
|
||||||
|
|
||||||
|
/** The drawing sits in the middle of its area, not at the top (the host is a flex row). */
|
||||||
|
const AREA =
|
||||||
|
'aspect-[4/3] w-full [&_.svg-canvas>div:first-child]:flex ' +
|
||||||
|
'[&_.svg-canvas>div:first-child]:items-center'
|
||||||
|
|
||||||
/** A detail view of the sheet (a crop or its own drawing) in a dialog. */
|
/** A detail view of the sheet (a crop or its own drawing) in a dialog. */
|
||||||
export default function DetailModal({
|
export default function DetailModal({
|
||||||
open,
|
open,
|
||||||
@@ -23,12 +36,45 @@ export default function DetailModal({
|
|||||||
title,
|
title,
|
||||||
states,
|
states,
|
||||||
onZoneClick,
|
onZoneClick,
|
||||||
|
backTo,
|
||||||
|
onBack,
|
||||||
}: DetailModalProps) {
|
}: DetailModalProps) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
|
const focusTitle = useRef(false)
|
||||||
|
// After a back the button is gone: the focus goes to the window's title.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!focusTitle.current) return
|
||||||
|
focusTitle.current = false
|
||||||
|
document.getElementById(TITLE_ID)?.focus()
|
||||||
|
}, [viewId])
|
||||||
|
const back = () => {
|
||||||
|
focusTitle.current = true
|
||||||
|
onBack()
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onClose={onClose} title={title} size="xl">
|
<Dialog
|
||||||
<div className="aspect-[4/3] w-full">
|
open={open}
|
||||||
|
onClose={onClose}
|
||||||
|
title={title}
|
||||||
|
titleId={TITLE_ID}
|
||||||
|
size="xl"
|
||||||
|
headerStart={
|
||||||
|
backTo && (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
onClick={back}
|
||||||
|
aria-label={t('detail.back').replace('{name}', backTo.name)}
|
||||||
|
>
|
||||||
|
<Icon name="arrow-left" size={16} aria-hidden />
|
||||||
|
<span className="ml-1">{backTo.name}</span>
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className={AREA}>
|
||||||
<AnatomyCanvas
|
<AnatomyCanvas
|
||||||
|
key={viewId}
|
||||||
index={index}
|
index={index}
|
||||||
viewId={viewId}
|
viewId={viewId}
|
||||||
states={states}
|
states={states}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ export interface DialogProps {
|
|||||||
/** The dialog's message, announced with its name (aria-describedby). */
|
/** The dialog's message, announced with its name (aria-describedby). */
|
||||||
description?: ReactNode
|
description?: ReactNode
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
|
/** Shown before the title in the header (a back button). */
|
||||||
|
headerStart?: ReactNode
|
||||||
size?: 'sm' | 'md' | 'lg' | 'xl'
|
size?: 'sm' | 'md' | 'lg' | 'xl'
|
||||||
/**
|
/**
|
||||||
* A box to sit over (A2: the editor's right column): the panel takes its left and width,
|
* A box to sit over (A2: the editor's right column): the panel takes its left and width,
|
||||||
@@ -86,6 +88,7 @@ function DialogSurface({
|
|||||||
titleId,
|
titleId,
|
||||||
description,
|
description,
|
||||||
children,
|
children,
|
||||||
|
headerStart,
|
||||||
size = 'md',
|
size = 'md',
|
||||||
anchor,
|
anchor,
|
||||||
veilCloses = true,
|
veilCloses = true,
|
||||||
@@ -125,6 +128,7 @@ function DialogSurface({
|
|||||||
style={place ?? undefined}
|
style={place ?? undefined}
|
||||||
>
|
>
|
||||||
<header className={HEADER}>
|
<header className={HEADER}>
|
||||||
|
{headerStart}
|
||||||
<h2
|
<h2
|
||||||
id={titleId ?? ownTitleId}
|
id={titleId ?? ownTitleId}
|
||||||
tabIndex={titleId ? -1 : undefined}
|
tabIndex={titleId ? -1 : undefined}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export type IconName =
|
|||||||
| 'lock'
|
| 'lock'
|
||||||
| 'google'
|
| 'google'
|
||||||
| 'apple'
|
| 'apple'
|
||||||
|
| 'arrow-left'
|
||||||
| 'chevron-right'
|
| 'chevron-right'
|
||||||
| 'chevron-down'
|
| 'chevron-down'
|
||||||
| 'external'
|
| 'external'
|
||||||
@@ -29,7 +30,8 @@ const PATHS: Record<IconName, string> = {
|
|||||||
close: 'M6 6l12 12M18 6L6 18',
|
close: 'M6 6l12 12M18 6L6 18',
|
||||||
dashboard: 'M4 4h7v7H4zM13 4h7v4h-7zM13 11h7v9h-7zM4 14h7v6H4z',
|
dashboard: 'M4 4h7v7H4zM13 4h7v4h-7zM13 11h7v9h-7zM4 14h7v6H4z',
|
||||||
user: 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0',
|
user: 'M12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4 21V5M8 7h7M8 11h5',
|
||||||
shield: 'M12 3l8 3v6c0 4.5-3.4 8-8 9-4.6-1-8-4.5-8-9V6zM9 12l2 2 4-4',
|
shield: 'M12 3l8 3v6c0 4.5-3.4 8-8 9-4.6-1-8-4.5-8-9V6zM9 12l2 2 4-4',
|
||||||
@@ -39,13 +41,16 @@ const PATHS: Record<IconName, string> = {
|
|||||||
'eye-off':
|
'eye-off':
|
||||||
'M3 3l18 18M10.6 10.6A3 3 0 0 0 13.4 13.4M9.9 5.2A10.5 10.5 0 0 1 12 5c6 0 10 7 10 7a17 17 0 0 1-3.2 3.9M6.1 6.1A17 17 0 0 0 2 12s4 7 10 7a10 10 0 0 0 4-.8',
|
'M3 3l18 18M10.6 10.6A3 3 0 0 0 13.4 13.4M9.9 5.2A10.5 10.5 0 0 1 12 5c6 0 10 7 10 7a17 17 0 0 1-3.2 3.9M6.1 6.1A17 17 0 0 0 2 12s4 7 10 7a10 10 0 0 0 4-.8',
|
||||||
check: 'M5 12l5 5L20 7',
|
check: 'M5 12l5 5L20 7',
|
||||||
|
'arrow-left': 'M19 12H5M11 6l-6 6 6 6',
|
||||||
'chevron-right': 'M9 6l6 6-6 6',
|
'chevron-right': 'M9 6l6 6-6 6',
|
||||||
'chevron-down': 'M6 9l6 6 6-6',
|
'chevron-down': 'M6 9l6 6 6-6',
|
||||||
external: 'M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5',
|
external:
|
||||||
|
'M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5',
|
||||||
lock: 'M6 11h12v9H6zM8 11V8a4 4 0 0 1 8 0v3',
|
lock: 'M6 11h12v9H6zM8 11V8a4 4 0 0 1 8 0v3',
|
||||||
'wifi-off':
|
'wifi-off':
|
||||||
'M3 3l18 18M8.5 16.1a6 6 0 0 1 7 0M5 12.5a11 11 0 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.3l2.6-2.6A9 9 0 0 0 4 7.8l3.1 2.5c.7-2.1 2.6-3.7 4.9-3.7z',
|
||||||
apple:
|
apple:
|
||||||
@@ -59,7 +64,12 @@ export interface IconProps extends SVGProps<SVGSVGElement> {
|
|||||||
size?: number
|
size?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Icon({ name, size = 20, className, ...rest }: IconProps) {
|
export default function Icon({
|
||||||
|
name,
|
||||||
|
size = 20,
|
||||||
|
className,
|
||||||
|
...rest
|
||||||
|
}: IconProps) {
|
||||||
const filled = FILLED.has(name)
|
const filled = FILLED.has(name)
|
||||||
return (
|
return (
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ export const en: Dict = {
|
|||||||
'editor.edit_dialog_title': 'Edit information',
|
'editor.edit_dialog_title': 'Edit information',
|
||||||
'editor.disclaimer_title': 'Legal scope of animal osteopathy',
|
'editor.disclaimer_title': 'Legal scope of animal osteopathy',
|
||||||
|
|
||||||
|
'detail.back': 'Back to the view “{name}”',
|
||||||
'detail.click_to_add':
|
'detail.click_to_add':
|
||||||
'Click the zones to add them to the current observation.',
|
'Click the zones to add them to the current observation.',
|
||||||
|
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ export const fr: Dict = {
|
|||||||
'editor.disclaimer_title': "Périmètre légal de l'ostéopathie animale",
|
'editor.disclaimer_title': "Périmètre légal de l'ostéopathie animale",
|
||||||
|
|
||||||
// detail modal
|
// detail modal
|
||||||
|
'detail.back': 'Revenir à la vue « {name} »',
|
||||||
'detail.click_to_add':
|
'detail.click_to_add':
|
||||||
"Cliquez sur les zones pour les ajouter à l'observation en cours.",
|
"Cliquez sur les zones pour les ajouter à l'observation en cours.",
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ import { useReportStore } from '@/state/reportStore'
|
|||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import { fr } from '@/i18n/fr'
|
import { fr } from '@/i18n/fr'
|
||||||
import type { SheetIndex } from '@/services/sheetIndex'
|
import type { SheetIndex } from '@/services/sheetIndex'
|
||||||
import { loadTestSheet, minimalReport } from '../helpers/sheet'
|
import { setSheetProvider } from '@/sheets/useSheet'
|
||||||
|
import { bundledSheetProvider } from '@/sheets/provider'
|
||||||
|
import { bundledSheet, loadTestSheet, minimalReport } from '../helpers/sheet'
|
||||||
|
|
||||||
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
|
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
|
||||||
let sheet: SheetIndex
|
let sheet: SheetIndex
|
||||||
@@ -43,20 +45,23 @@ beforeEach(() => {
|
|||||||
window.scrollTo = vi.fn() as unknown as typeof window.scrollTo
|
window.scrollTo = vi.fn() as unknown as typeof window.scrollTo
|
||||||
vi.stubGlobal('alert', vi.fn())
|
vi.stubGlobal('alert', vi.fn())
|
||||||
useReportStore.setState({ report: null, activeObservationIndex: 0 })
|
useReportStore.setState({ report: null, activeObservationIndex: 0 })
|
||||||
useReportStore.getState().hydrateImport({
|
useReportStore.getState().hydrateImport(
|
||||||
report: minimalReport(sheet, {
|
{
|
||||||
observations: [
|
report: minimalReport(sheet, {
|
||||||
{
|
observations: [
|
||||||
id: 'o1',
|
{
|
||||||
zones: [],
|
id: 'o1',
|
||||||
findings: [],
|
zones: [],
|
||||||
freeTextFindings: [],
|
findings: [],
|
||||||
comment: '',
|
freeTextFindings: [],
|
||||||
},
|
comment: '',
|
||||||
],
|
},
|
||||||
}),
|
],
|
||||||
archive: null,
|
}),
|
||||||
}, sheet)
|
archive: null,
|
||||||
|
},
|
||||||
|
sheet,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
cleanup()
|
cleanup()
|
||||||
@@ -249,3 +254,145 @@ describe('EditorRoute on the canonical sheet', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** The reference sheet plus a view « Incisives » opened from the head (the board's panel 16). */
|
||||||
|
async function withNestedView() {
|
||||||
|
const bundle = await bundledSheet()
|
||||||
|
const document = structuredClone(bundle.document) as {
|
||||||
|
views: unknown[]
|
||||||
|
annotations: unknown[]
|
||||||
|
}
|
||||||
|
document.views.push({
|
||||||
|
id: 'incisors',
|
||||||
|
kind: 'detail',
|
||||||
|
parent_view_id: 'head',
|
||||||
|
name: { fr: 'Incisives', en: 'Incisors' },
|
||||||
|
svg_asset_id: null,
|
||||||
|
view_box: { min_x: 300, min_y: 180, width: 200, height: 150 },
|
||||||
|
})
|
||||||
|
document.annotations.push({
|
||||||
|
id: 'incisors-trigger',
|
||||||
|
kind: 'detail_trigger',
|
||||||
|
view_id: 'head',
|
||||||
|
category_id: 'articulations',
|
||||||
|
laterality: 'unpaired',
|
||||||
|
geometry: {
|
||||||
|
type: 'polygon',
|
||||||
|
points: [
|
||||||
|
[330, 300],
|
||||||
|
[380, 300],
|
||||||
|
[380, 340],
|
||||||
|
[330, 340],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
name: null,
|
||||||
|
opens_view_id: 'incisors',
|
||||||
|
})
|
||||||
|
// Without a `fingerprint` block the reference is a historical one: read unverified, so an
|
||||||
|
// edited document loads (the frozen seed is never touched).
|
||||||
|
const ref = { ...bundle.ref, fingerprint: undefined }
|
||||||
|
const edited = { ...bundle, ref, document }
|
||||||
|
setSheetProvider({ getReferenceSheet: async () => edited })
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('EditorRoute detail window stack (D15)', () => {
|
||||||
|
const HEAD = 'Tête (vue latérale gauche)'
|
||||||
|
const BACK = fr['detail.back'].replace('{name}', HEAD)
|
||||||
|
|
||||||
|
beforeEach(withNestedView)
|
||||||
|
afterEach(() => setSheetProvider(bundledSheetProvider))
|
||||||
|
|
||||||
|
const bands = (dialog: HTMLElement) =>
|
||||||
|
dialog.querySelectorAll('[class*="frame-band"]')
|
||||||
|
|
||||||
|
async function openNested() {
|
||||||
|
await mount()
|
||||||
|
return pushNested()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pushNested() {
|
||||||
|
clickZone('head-trigger')
|
||||||
|
const head = await screen.findByRole('dialog', { name: HEAD })
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
head.querySelector('[data-anno-id="incisors-trigger"]'),
|
||||||
|
).not.toBeNull(),
|
||||||
|
)
|
||||||
|
clickZone('incisors-trigger', head)
|
||||||
|
return screen.findByRole('dialog', { name: 'Incisives' })
|
||||||
|
}
|
||||||
|
|
||||||
|
it('pushes a nested view, shows the way back, and pops it with the focus on the title', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
const dialog = await openNested()
|
||||||
|
const back = within(dialog).getByRole('button', { name: BACK })
|
||||||
|
expect(back).toHaveTextContent('Tête (vue latérale gauche)')
|
||||||
|
await user.click(back)
|
||||||
|
const head = await screen.findByRole('dialog', { name: HEAD })
|
||||||
|
expect(within(head).queryByRole('button', { name: BACK })).toBeNull()
|
||||||
|
expect(within(head).getByRole('heading', { name: HEAD })).toHaveFocus()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('opening from the page starts a new stack, so a first view has no back button', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
await openNested()
|
||||||
|
await user.keyboard('{Escape}')
|
||||||
|
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||||
|
clickZone('head-trigger')
|
||||||
|
const head = await screen.findByRole('dialog', { name: HEAD })
|
||||||
|
expect(within(head).queryByRole('button', { name: /Revenir/ })).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Escape and Fermer close the whole window, never one view', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
const dialog = await openNested()
|
||||||
|
await user.keyboard('{Escape}')
|
||||||
|
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||||
|
const again = await pushNested()
|
||||||
|
await user.click(
|
||||||
|
within(again).getByRole('button', { name: fr['common.close'] }),
|
||||||
|
)
|
||||||
|
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||||
|
expect(dialog).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('each view pushed or popped shows its own drawing and one band, none left over', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
const canvasOf = (d: HTMLElement, viewId: string) => {
|
||||||
|
const canvases = d.querySelectorAll('[data-testid="anatomy-canvas"]')
|
||||||
|
expect(canvases).toHaveLength(1)
|
||||||
|
expect(canvases[0]).toHaveAttribute('data-view-id', viewId)
|
||||||
|
return canvases[0]!
|
||||||
|
}
|
||||||
|
const dialog = await openNested()
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(canvasOf(dialog, 'incisors').querySelector('svg')).not.toBeNull(),
|
||||||
|
)
|
||||||
|
expect(bands(dialog)).toHaveLength(1)
|
||||||
|
expect(
|
||||||
|
canvasOf(dialog, 'incisors')
|
||||||
|
.querySelector('svg')!
|
||||||
|
.getAttribute('viewBox'),
|
||||||
|
).toBe('300 180 200 150')
|
||||||
|
await user.click(within(dialog).getByRole('button', { name: BACK }))
|
||||||
|
const head = await screen.findByRole('dialog', { name: HEAD })
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(canvasOf(head, 'head').querySelector('svg')).not.toBeNull(),
|
||||||
|
)
|
||||||
|
expect(bands(head)).toHaveLength(1)
|
||||||
|
expect(
|
||||||
|
canvasOf(head, 'head').querySelector('svg')!.getAttribute('viewBox'),
|
||||||
|
).toBe('60 100 500 380')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('centres the drawing vertically in its area (flex, items-center)', async () => {
|
||||||
|
const dialog = await openNested()
|
||||||
|
const area = dialog.querySelector(
|
||||||
|
'[data-testid="anatomy-canvas"]',
|
||||||
|
)!.parentElement!
|
||||||
|
expect(area.className).toContain('[&_.svg-canvas>div:first-child]:flex')
|
||||||
|
expect(area.className).toContain(
|
||||||
|
'[&_.svg-canvas>div:first-child]:items-center',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -81,6 +81,30 @@ describe('Dialog', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('renders headerStart before the title and leaves the ✕ unchanged', () => {
|
||||||
|
useLocaleStore.setState({ locale: 'fr' })
|
||||||
|
render(
|
||||||
|
<Dialog
|
||||||
|
open
|
||||||
|
onClose={() => {}}
|
||||||
|
title="X"
|
||||||
|
headerStart={<button type="button">Back</button>}
|
||||||
|
>
|
||||||
|
body
|
||||||
|
</Dialog>,
|
||||||
|
)
|
||||||
|
const back = screen.getByRole('button', { name: 'Back' })
|
||||||
|
const title = screen.getByRole('heading', { name: 'X' })
|
||||||
|
expect(
|
||||||
|
back.compareDocumentPosition(title) & Node.DOCUMENT_POSITION_FOLLOWING,
|
||||||
|
).toBeTruthy()
|
||||||
|
expect(screen.getAllByRole('button', { name: 'Fermer' })).toHaveLength(1)
|
||||||
|
expect(screen.getByRole('button', { name: 'Fermer' })).toHaveClass(
|
||||||
|
'h-11',
|
||||||
|
'w-11',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it('has no description when none is given', () => {
|
it('has no description when none is given', () => {
|
||||||
render(
|
render(
|
||||||
<Dialog open onClose={() => {}} title="X">
|
<Dialog open onClose={() => {}} title="X">
|
||||||
|
|||||||
Reference in new issue
Block a user