diff --git a/src/App.vue b/src/App.vue index a0d7a19..c616e77 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,45 @@ - - Vue-Tailwind - + + Open Modal + + + + This is the modal content. + + + + diff --git a/src/components/DxhModal.vue b/src/components/DxhModal.vue new file mode 100644 index 0000000..5bcaf5b --- /dev/null +++ b/src/components/DxhModal.vue @@ -0,0 +1,112 @@ + + + + + + + + + + + {{ title }} + + + + + + + Cancel + + + + OK + + + + + + + diff --git a/src/components/__tests__/DxhModal.spec.ts b/src/components/__tests__/DxhModal.spec.ts new file mode 100644 index 0000000..613970b --- /dev/null +++ b/src/components/__tests__/DxhModal.spec.ts @@ -0,0 +1,67 @@ +import { describe, it, expect, beforeEach, afterEach } from 'vitest' +import { mount } from '@vue/test-utils' +import DxhModal from '@/components/DxhModal.vue' + +describe('DxhModal.vue', () => { + let wrapper: any + + beforeEach(() => { + wrapper = mount(DxhModal, { + props: { + title: 'Test Modal', + footer: true, + open: true, + keyboardEsc: true, + zIndex: 1000, + persistent: false + } + }) + }) + + afterEach(() => { + wrapper.unmount() + }) + + it('renders modal with title and footer', () => { + const title = wrapper.find('[data-test="modal-title"]') + const footer = wrapper.find('[data-test="modal-footer"]') + + expect(title.exists()).toBe(true) + expect(title.text()).toBe('Test Modal') + expect(footer.exists()).toBe(true) + }) + + it('emits cancel event on cancel button click', async () => { + const cancelButton = wrapper.find('[data-test="cancel-button"]') + + await cancelButton.trigger('click') + + const cancelEvent = wrapper.emitted('cancel') + expect(cancelEvent).toBeTruthy() + }) + + it('emits ok event on ok button click', async () => { + const okButton = wrapper.find('[data-test="ok-button"]') + + await okButton.trigger('click') + + const okEvent = wrapper.emitted('ok') + expect(okEvent).toBeTruthy() + }) + + it('closes modal on outside click', async () => { + const modalOverlay = wrapper.find('[data-test="modal-overlay"]') + + await modalOverlay.trigger('click') + + const cancelEvent = wrapper.emitted('close') + expect(cancelEvent).toBeTruthy() + }) + + it('closes modal on pressing ESC key', async () => { + await wrapper.trigger('keydown.esc') + + const cancelEvent = wrapper.emitted('close') + expect(cancelEvent).toBeUndefined() + }) +}) diff --git a/src/index.ts b/src/index.ts index ee2ff8d..16a1a01 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -import DButton from "./components/DButton.vue" -import DInput from "./components/DInput.vue" +import DButton from './components/DButton.vue' +import DInput from './components/DInput.vue' +import DxhModal from './components/DxhModal.vue' -export default {DButton, DInput} \ No newline at end of file +export default { DButton, DInput, DxhModal }
This is the modal content.