From 22e473b87c6c09f623ecd6900cf546cdaca47656 Mon Sep 17 00:00:00 2001 From: Paul Valerie GOMA Date: Mon, 28 Jul 2025 01:22:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20added=20test=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/VModal.spec.ts | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/VModal.spec.ts 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(); + }); +});