import { InteractionType, ScanView } from '@3cr/types-ts'; import { useAnnotationMoveTool } from '@/tools/annotation-move.tool'; import { useViewerStore } from '@/stores/viewer.store'; import { flushPromises } from '@vue/test-utils'; import { storeToRefs } from 'pinia'; import { useDataOverlayStore } from '@/stores/data-overlay.store'; import { DataOverlayDataFaker } from '@test/fakers/data-overlay-data.faker'; import { DataOverlayAnnotationFaker } from '@test/fakers/data-overlay-annotation.faker'; import { useViewer3cr } from '@/composables/useViewer3cr'; import { MockInstance } from '@vitest/spy'; describe('annotation move tool', () => { const viewer3cr = useViewer3cr(); const { event } = storeToRefs(useDataOverlayStore()); const { activeView } = storeToRefs(useViewerStore()); let move2dSpy: MockInstance; let move3dSpy: MockInstance; beforeEach(() => { move2dSpy = vi.spyOn(viewer3cr, 'moveAnnotation2dTool'); move3dSpy = vi.spyOn(viewer3cr, 'moveAnnotation3dTool'); }); afterEach(() => { move2dSpy.mockRestore(); move3dSpy.mockRestore(); }); it('should activate for 2D views', async () => { activeView.value = ScanView.Coronal; const annotationMoveTool = useAnnotationMoveTool(); annotationMoveTool.isActive.value = true; event.value = DataOverlayDataFaker.annotationEventRaw( InteractionType.POINTER_UP, ); await flushPromises(); expect(move2dSpy).toHaveBeenCalled(); expect(move3dSpy).not.toHaveBeenCalled(); }); it('should activate for 3D views', async () => { activeView.value = ScanView.Volume; const annotationMoveTool = useAnnotationMoveTool(); annotationMoveTool.isActive.value = true; event.value = DataOverlayDataFaker.annotationEventRaw( InteractionType.POINTER_UP, ); await flushPromises(); expect(move2dSpy).not.toHaveBeenCalled(); expect(move3dSpy).toHaveBeenCalled(); }); it('should deactivate move', async () => { activeView.value = ScanView.Coronal; const annotationMoveTool = useAnnotationMoveTool(); annotationMoveTool.isActive.value = true; annotationMoveTool.selected.value = DataOverlayAnnotationFaker.random(); await flushPromises(); annotationMoveTool.isActive.value = false; await flushPromises(); expect(move2dSpy).toHaveBeenCalled(); expect(move3dSpy).toHaveBeenCalled(); expect(annotationMoveTool.selected.value).toBeNull(); }); it('should do nothing if not active', async () => { const annotationMoveTool = useAnnotationMoveTool(); const dataOverlayStore = useDataOverlayStore(); annotationMoveTool.isActive.value = false; dataOverlayStore.event = DataOverlayDataFaker.annotationEventRaw( InteractionType.POINTER_UP, ); await flushPromises(); expect(annotationMoveTool.selected.value).toBeNull(); }); it('should 2d if scanView Saggital', async () => { activeView.value = ScanView.Sagittal; const dataOverlayStore = useDataOverlayStore(); const annotationMoveTool = useAnnotationMoveTool(); annotationMoveTool.isActive.value = true; dataOverlayStore.event = DataOverlayDataFaker.annotationEventRaw( InteractionType.POINTER_UP, ); await flushPromises(); expect(move2dSpy).toHaveBeenCalled(); expect(annotationMoveTool.selected.value).toStrictEqual( dataOverlayStore.annotationEvent?.Data.DataOverlay, ); }); it('should do nothing if scanView Undefined', async () => { activeView.value = undefined; const dataOverlayStore = useDataOverlayStore(); const annotationMoveTool = useAnnotationMoveTool(); annotationMoveTool.isActive.value = true; dataOverlayStore.event = DataOverlayDataFaker.annotationEventRaw( InteractionType.POINTER_UP, ); await flushPromises(); expect(move2dSpy).not.toHaveBeenCalled(); }); });