|
| 1 | +import { mount } from '@vue/test-utils'; |
| 2 | +import { describe, expect, it, vi } from 'vitest'; |
| 3 | +import MeasurementToolDetails from '@/src/components/MeasurementToolDetails.vue'; |
| 4 | +import MeasurementRulerDetails from '@/src/components/MeasurementRulerDetails.vue'; |
| 5 | +import { ToolID } from '@/src/types/annotation-tool'; |
| 6 | + |
| 7 | +vi.mock('@/src/store/tools/rulers', () => ({ |
| 8 | + useRulerStore: () => ({ |
| 9 | + lengthByID: { 'tool-1': 12.345 }, |
| 10 | + }), |
| 11 | +})); |
| 12 | + |
| 13 | +const stubs = { |
| 14 | + 'v-row': { template: '<div><slot /></div>' }, |
| 15 | + 'v-col': { template: '<div><slot /></div>' }, |
| 16 | +}; |
| 17 | + |
| 18 | +const baseTool = { |
| 19 | + id: 'tool-1' as ToolID, |
| 20 | + imageID: 'img-1', |
| 21 | + frameOfReference: { |
| 22 | + planeOrigin: [0, 0, 0] as [number, number, number], |
| 23 | + planeNormal: [0, 0, 1] as [number, number, number], |
| 24 | + }, |
| 25 | + color: '#fff', |
| 26 | + name: 'Tool', |
| 27 | + axis: 'Axial', |
| 28 | +}; |
| 29 | + |
| 30 | +describe('MeasurementToolDetails', () => { |
| 31 | + it('shows slice number for a volume annotation', () => { |
| 32 | + const wrapper = mount(MeasurementToolDetails, { |
| 33 | + props: { tool: { ...baseTool, slice: 4 } }, |
| 34 | + global: { stubs }, |
| 35 | + }); |
| 36 | + expect(wrapper.text()).toContain('Slice: 5'); |
| 37 | + expect(wrapper.text()).not.toContain('Frame:'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('shows frame number for a cine annotation', () => { |
| 41 | + const wrapper = mount(MeasurementToolDetails, { |
| 42 | + props: { tool: { ...baseTool, slice: 0, frame: 7 } }, |
| 43 | + global: { stubs }, |
| 44 | + }); |
| 45 | + expect(wrapper.text()).toContain('Frame: 8'); |
| 46 | + expect(wrapper.text()).not.toContain('Slice:'); |
| 47 | + }); |
| 48 | +}); |
| 49 | + |
| 50 | +describe('MeasurementRulerDetails', () => { |
| 51 | + it('shows slice number for a volume ruler', () => { |
| 52 | + const wrapper = mount(MeasurementRulerDetails, { |
| 53 | + props: { tool: { ...baseTool, slice: 9 } }, |
| 54 | + global: { stubs }, |
| 55 | + }); |
| 56 | + expect(wrapper.text()).toContain('Slice: 10'); |
| 57 | + expect(wrapper.text()).not.toContain('Frame:'); |
| 58 | + }); |
| 59 | + |
| 60 | + it('shows frame number for a cine ruler', () => { |
| 61 | + const wrapper = mount(MeasurementRulerDetails, { |
| 62 | + props: { tool: { ...baseTool, slice: 0, frame: 2 } }, |
| 63 | + global: { stubs }, |
| 64 | + }); |
| 65 | + expect(wrapper.text()).toContain('Frame: 3'); |
| 66 | + expect(wrapper.text()).not.toContain('Slice:'); |
| 67 | + }); |
| 68 | +}); |
0 commit comments