import { useViewerStore } from '@/stores/viewer.store'; import { FrontEndInterfaces, ScanView } from '@3cr/types-ts'; import { useAnnotationCreateTool } from '@/tools/annotation-create.tool'; import { Viewer3crServiceImpl } from '@/services/viewer-3cr.service'; import { flushPromises } from '@vue/test-utils'; import { storeToRefs } from 'pinia'; import { useViewer3cr } from '@/composables/useViewer3cr'; import { MockInstance } from '@vitest/spy'; describe('annotation create tool', () => { const viewer3cr = useViewer3cr() as Viewer3crServiceImpl; let create2dSpy: MockInstance; beforeEach(() => { create2dSpy = vi.spyOn(viewer3cr, 'createAnnotation2dTool'); }); afterEach(() => { create2dSpy.mockRestore(); }); it('should activate for 2D views', async () => { const { activeView } = storeToRefs(useViewerStore()); activeView.value = ScanView.Sagittal; const annotationCreateTool = useAnnotationCreateTool(); annotationCreateTool.isActive.value = true; await flushPromises(); expect(create2dSpy).toHaveBeenCalled(); }); it('should not activate for 3D view', async () => { const { activeView } = storeToRefs(useViewerStore()); activeView.value = ScanView.Volume; const annotationCreateTool = useAnnotationCreateTool(); annotationCreateTool.isActive.value = true; await flushPromises(); expect(create2dSpy).not.toHaveBeenCalled(); }); it('should activate and deactivate', async () => { const { activeView } = storeToRefs(useViewerStore()); activeView.value = ScanView.Sagittal; const annotationCreateTool = useAnnotationCreateTool(); annotationCreateTool.isActive.value = true; await flushPromises(); annotationCreateTool.isActive.value = false; await flushPromises(); expect(create2dSpy).toHaveBeenCalled(); }); it('should activate annotations from 3cr', async () => { const { activeView } = storeToRefs(useViewerStore()); activeView.value = ScanView.Sagittal; const annotationCreateTool = useAnnotationCreateTool(); const createAnnotation3CrSpy = vi .spyOn(viewer3cr, 'createAnnotation2dTool') .mockResolvedValue(); annotationCreateTool.isActive.value = true; await flushPromises(); await viewer3cr.onPayload({ Action: 'mu_01', ReturnChannel: '{}', ReturnTo: '', Message: '', Interface: FrontEndInterfaces.markups, }); expect(createAnnotation3CrSpy).toHaveBeenCalled(); annotationCreateTool.isActive.value = false; }); it('should not activate annotations from 3cr', async () => { const { activeView } = storeToRefs(useViewerStore()); activeView.value = ScanView.Sagittal; const annotationCreateTool = useAnnotationCreateTool(); annotationCreateTool.isActive.value = false; await flushPromises(); await viewer3cr.onPayload({ Action: 'mu_01', ReturnChannel: '{}', ReturnTo: '', Message: '', Interface: FrontEndInterfaces.markups, }); expect(create2dSpy).not.toHaveBeenCalled(); }); });