import { mount } from '@vue/test-utils'; import MultiLoginError from '@/components/shared/MultiLoginError.vue'; import { VDialog, VSnackbar } from 'vuetify/components'; import { nextTick } from 'vue'; describe('MultiLoginError', () => { it('should render the dialog', () => { const wrapper = mount(MultiLoginError); const dialog = wrapper.findComponent(VDialog); expect(dialog.exists()).toBe(true); }); it('calls verifyOwnership function', async () => { const wrapper = mount(MultiLoginError); wrapper.vm.verifyOwnership(); expect(wrapper.vm.snackbarTest).toBe(true); }); it('requestAccess should set snackbar to true', () => { const wrapper = mount(MultiLoginError); wrapper.vm.requestAccess(); expect(wrapper.vm.snackbar).toBe(true); const snackbar = wrapper.findAllComponents(VSnackbar)[0]; expect(snackbar.exists()).toBe(true); expect(snackbar.isVisible()).toBe(true); }); it('snackbar should initially be hidden and display when triggered', async () => { const wrapper = mount(MultiLoginError); expect(wrapper.vm.snackbar).toBe(false); wrapper.vm.snackbar = true; await nextTick(); const snackbar = wrapper.findAllComponents(VSnackbar)[0]; for (const snack of wrapper.findAllComponents(VSnackbar)) { await snack.setValue(true); } expect(snackbar.exists()).toBe(true); expect(snackbar.isVisible()).toBe(true); }); it('should hide the snackbar when the close button is clicked', async () => { const wrapper = mount(MultiLoginError); wrapper.vm.snackbar = true; await nextTick(); const snackbar = wrapper.findComponent({ name: 'VSnackbar' }); expect(snackbar.isVisible()).toBe(true); const closeButton = wrapper.findComponent('[data-testid="closeSnackbar"]'); expect(closeButton.exists()).toBe(true); await closeButton.trigger('click'); await nextTick(); expect(wrapper.vm.snackbar).toBe(false); }); });