import { mount } from '@vue/test-utils'; import { storeToRefs } from 'pinia'; import { VCardText, VCardTitle, VDialog } from 'vuetify/components'; import DemoLicenceInfoModal from '@/components/demo/DemoInfoModal.vue'; import { PRICING_URL } from '@/constants'; import { useDemoStore } from '@/stores/demo.store'; describe('DemoLicenceInfoModal tests', () => { it('should mount', () => { const props = { modal: true, isModalOpen: true }; const wrapper = mount(DemoLicenceInfoModal, { props }); expect(wrapper).toBeTruthy(); }); it('should close modal', async () => { const props = { modal: true, isModalOpen: true }; const wrapper = mount(DemoLicenceInfoModal, { props }); const close = wrapper.findComponentByTestId('close'); await close.trigger('click'); expect(wrapper.emitted('update:modal')).toBeTruthy(); }); it('should open support url', async () => { vi.stubGlobal('open', vi.fn()); const spy = vi.spyOn(window, 'open'); const props = { modal: true, isModalOpen: true }; const wrapper = mount(DemoLicenceInfoModal, { props }); const button = wrapper.findComponentByTestId('confirm'); await button.trigger('click'); expect(spy).toHaveBeenCalledWith(PRICING_URL, '_self'); vi.clearAllMocks(); }); it('should open via input', async () => { const props = { modal: false, isModalOpen: true }; const wrapper = mount(DemoLicenceInfoModal, { props }); const dialog = wrapper.findComponent(VDialog); await dialog.setValue(true); }); it('should show title and subtitle', async () => { const { demoTitle, demoSubtitles } = storeToRefs(useDemoStore()); vi.spyOn(demoTitle, 'value', 'get').mockReturnValue('Title'); vi.spyOn(demoSubtitles, 'value', 'get').mockReturnValue(['Subtitle']); const props = { modal: true, isModalOpen: true }; const wrapper = mount(DemoLicenceInfoModal, { props }); expect(wrapper.findComponent(VCardTitle).text()).contains('Title'); expect(wrapper.findComponent(VCardText).text()).contains('Subtitle'); }); });