diff --git a/test/VModal.spec.ts b/test/VModal.spec.ts new file mode 100644 index 0000000..d25fdd9 --- /dev/null +++ b/test/VModal.spec.ts @@ -0,0 +1,69 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { mount } from '@vue/test-utils'; +import { nextTick } from 'vue'; +import VModal from '../src/components/modal/VModal.vue'; +import type IVButton from '../src/components/button/IVButton.type'; + +describe('VModal.vue', () => { + let actions: IVButton[]; + let visible: boolean; + + beforeEach(() => { + visible = true; + actions = [ + { + label: 'Bouton primaire', + onClick: vi.fn(), + title: 'primaire', + }, + { + label: 'Bouton secondaire', + secondary: true, + onClick: vi.fn(), + title: 'secondaire', + }, + { + label: 'Bouton tertiaire', + tertiary: true, + onClick: vi.fn(), + title: 'tertiaire', + }, + ]; + }); + + it('emits update:visible when internal visibility changes', async () => { + const wrapper = mount(VModal, { + props: { + visible: true, + actions, + }, + }); + + // Simulation d’un changement interne + await wrapper.vm.$emit('update:visible', false); + await nextTick(); + + const emitted = wrapper.emitted('update:visible'); + expect(emitted).toBeTruthy(); + expect(emitted?.[0]).toEqual([false]); + +}); + + + it('emits lifecycle events (show/hide)', async () => { + const wrapper = mount(VModal, { + props: { + visible, + actions, + }, + }); + + wrapper.vm.$emit('show'); + wrapper.vm.$emit('hide'); + + await nextTick(); + + expect(wrapper.emitted('show')).toBeTruthy(); + expect(wrapper.emitted('hide')).toBeTruthy(); + }); +});