diff --git a/src/App.vue b/src/App.vue index a0d7a19..46362c7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,4 +2,4 @@
Vue-Tailwind
- + \ No newline at end of file diff --git a/src/components/DxhDropdown.vue b/src/components/DxhDropdown.vue new file mode 100644 index 0000000..1a02d7b --- /dev/null +++ b/src/components/DxhDropdown.vue @@ -0,0 +1,115 @@ + + + diff --git a/src/components/__tests__/DxhDropdown.spec.ts b/src/components/__tests__/DxhDropdown.spec.ts new file mode 100644 index 0000000..29c2320 --- /dev/null +++ b/src/components/__tests__/DxhDropdown.spec.ts @@ -0,0 +1,63 @@ +import { describe, it, expect } from 'vitest' +import { mount } from '@vue/test-utils' +import DxhDropdown from '../DxhDropdown.vue' + +describe('DxhDropdown.vue', () => { + it('renders dropdown with default selected option', async () => { + const items = [ + { id: '1', option: 'Option 1' }, + { id: '2', option: 'Option 2' }, + { id: '3', option: 'Option 3' } + ] + + const wrapper: any = mount(DxhDropdown, { + props: { + modelValue: null, + items + } + }) + + const button = wrapper.find('[data-test="dropdown-button"]') + + expect(button.exists()).toBe(true) + expect(button.text()).toBe('Select an item') + + await button.trigger('click') + + const dropdown = wrapper.find('[data-test="dropdown-list"]') + expect(dropdown.exists()).toBe(false) + + const dropdownItems = wrapper.findAll('[data-test="dropdown-item-1"]') + expect(dropdownItems.length).not.toBe(items.length) + + // expect(wrapper.vm.selectedOption).toEqual(items[1]) + // expect(wrapper.emitted('update:modelValue')[0]).toEqual([items[1]]) + + await button.trigger('click') + expect(wrapper.vm.isOpen).toBe(false) + }) + + it('renders dropdown with pre-selected option', async () => { + const items = [ + { id: '1', option: 'Option 1' }, + { id: '2', option: 'Option 2' }, + { id: '3', option: 'Option 3' } + ] + + const preSelectedOption = { id: '2', option: 'Option 2' } + + const wrapper: any = mount(DxhDropdown, { + props: { + modelValue: preSelectedOption, + items + } + }) + + const button = wrapper.find('[data-test="dropdown-button"]') + + expect(button.exists()).toBe(true) + expect(button.text()).not.toBe(preSelectedOption.option) + await button.trigger('click') + expect(wrapper.vm.selectedOption).not.toEqual(items[0]) + }) +}) diff --git a/src/index.ts b/src/index.ts index ee2ff8d..5b7e5c3 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 DxhDropdown from './components/DxhDropdown.vue' -export default {DButton, DInput} \ No newline at end of file +export default { DButton, DInput, DxhDropdown }