40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
import AnatomyCanvas from '@/components/canvas/AnatomyCanvas'
|
|
|
|
vi.mock('@/anatomy/svgLoader', () => ({
|
|
loadSvg: vi.fn(async () => {
|
|
const doc = new DOMParser().parseFromString(
|
|
`<svg xmlns="http://www.w3.org/2000/svg">
|
|
<circle data-bone-id="epaule" data-bone-fr="Épaule" data-bone-en="Shoulder"
|
|
data-category="articulation" class="bone osteo articulation hitbox bone-epaule" />
|
|
<circle data-bone-id="epaule" data-bone-fr="Épaule" data-bone-en="Shoulder"
|
|
data-category="articulation" class="bone osteo articulation visible bone-epaule" />
|
|
</svg>`,
|
|
'image/svg+xml',
|
|
)
|
|
return doc.documentElement as unknown as SVGSVGElement
|
|
}),
|
|
}))
|
|
|
|
beforeEach(() => vi.clearAllMocks())
|
|
|
|
describe('AnatomyCanvas', () => {
|
|
it('renders the loaded SVG inline', async () => {
|
|
render(<AnatomyCanvas src="/x.svg" boneStates={new Map()} onZoneClick={() => {}} />)
|
|
await waitFor(() =>
|
|
expect(document.querySelector('[data-bone-id="epaule"]')).not.toBeNull(),
|
|
)
|
|
})
|
|
|
|
it('calls onZoneClick with the clicked bone id', async () => {
|
|
const onZoneClick = vi.fn()
|
|
render(<AnatomyCanvas src="/x.svg" boneStates={new Map()} onZoneClick={onZoneClick} />)
|
|
await waitFor(() => screen.getByTestId('anatomy-canvas'))
|
|
;(document.querySelector('[data-bone-id="epaule"]') as Element).dispatchEvent(
|
|
new Event('click', { bubbles: true }),
|
|
)
|
|
await waitFor(() => expect(onZoneClick).toHaveBeenCalledWith('epaule'))
|
|
})
|
|
})
|