feat(canvas): inline SVG load + delegated click + state classes
This commit is contained in:
1 parent
90d398656c
commit
bea3712851
2 files changed
+101
-2
No files matched your search
@@ -0,0 +1,39 @@
|
||||
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'))
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user