import { flushPromises, mount } from '@vue/test-utils'; import AnnotationTools from '@/components/navigation/annotation/AnnotationTools.vue'; import AnnotationDeleteSnackbar from '@/components/navigation/annotation/AnnotationDeleteSnackbar.vue'; import AnnotationCreateModal from '@/components/navigation/annotation/AnnotationCreateModal.vue'; import { storeToRefs } from 'pinia'; import { useViewerStore } from '@/stores/viewer.store'; import { VIcon, VSnackbar } from 'vuetify/components'; describe('AnnotationTools tests', () => { it('should mount', async () => { const wrapper = mount(AnnotationTools, { drawer: true }); await flushPromises(); expect(wrapper).toBeTruthy(); }); it('should AnnotationCreateModal', async () => { const wrapper = mount(AnnotationTools); const snack = wrapper.findComponent(AnnotationCreateModal); await snack.setValue(true); expect(snack.isVisible()).toBe(true); await snack.setValue(false); }); it('should create snackbar', async () => { const wrapper = mount(AnnotationTools, { drawer: true }); const snack = wrapper.findAllComponents(VSnackbar); await snack[0].setValue(true); expect(snack[0].isVisible()).toBe(true); }); it('should close create snackbar', async () => { const wrapper = mount(AnnotationTools, { drawer: true }); const [snack] = wrapper.findAllComponents(VSnackbar); await snack.setValue(true); expect(snack.isVisible()).toBe(true); const [_icon, icon] = snack.findAllComponents(VIcon); await icon.trigger('click'); await flushPromises(); expect(snack.vm.modelValue).toBe(false); }); it('should move snackbar', async () => { const wrapper = mount(AnnotationTools, { drawer: true }); const snack = wrapper.findAllComponents(VSnackbar); await snack[1].setValue(true); expect(snack[1].isVisible()).toBe(true); }); it('should close move snackbar', async () => { const wrapper = mount(AnnotationTools, { drawer: true }); const [_, snack] = wrapper.findAllComponents(VSnackbar); await snack.setValue(true); expect(snack.isVisible()).toBe(true); const [_icon, icon] = snack.findAllComponents(VIcon); await icon.trigger('click'); await flushPromises(); expect(snack.vm.modelValue).toBe(false); }); it('should AnnotationDeleteSnackbar', async () => { const wrapper = mount(AnnotationTools, { drawer: true }); const snack = wrapper.findComponent(AnnotationDeleteSnackbar); await snack.setValue(true); expect(snack.isVisible()).toBe(true); }); it('should create', async () => { const { measurementToDelete } = storeToRefs(useViewerStore()); measurementToDelete.value = {} as any; const wrapper = mount(AnnotationTools, { drawer: true }); const snack = wrapper.findAllComponents(VSnackbar); wrapper.vm.create(); expect(snack[0].isVisible()).toBe(true); }); it('should move', async () => { const { measurementToDelete } = storeToRefs(useViewerStore()); measurementToDelete.value = {} as any; const wrapper = mount(AnnotationTools, { drawer: true }); const snack = wrapper.findAllComponents(VSnackbar); wrapper.vm.move(); expect(snack[1].isVisible()).toBe(true); }); });