From 612227bc3937a13996090c3ba24baba68f47413f Mon Sep 17 00:00:00 2001 From: git-mahade Date: Fri, 15 Dec 2023 20:40:55 +0600 Subject: [PATCH 1/3] dropdown --- src/App.vue | 15 +++++-- src/components/DxhDropdown.vue | 82 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/components/DxhDropdown.vue diff --git a/src/App.vue b/src/App.vue index a0d7a19..82f369d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,14 @@ + + diff --git a/src/components/DxhDropdown.vue b/src/components/DxhDropdown.vue new file mode 100644 index 0000000..8a79771 --- /dev/null +++ b/src/components/DxhDropdown.vue @@ -0,0 +1,82 @@ + + + From 8dc62c8bdfb6f08f36868cdd4fef179052833a6d Mon Sep 17 00:00:00 2001 From: git-mahade Date: Mon, 18 Dec 2023 11:31:52 +0600 Subject: [PATCH 2/3] dropdown --- src/App.vue | 8 ++- src/components/DxhDropdown.vue | 61 ++++++++++++++----- src/components/__tests__/DxhDropdown.spec.ts | 63 ++++++++++++++++++++ src/index.ts | 7 ++- 4 files changed, 120 insertions(+), 19 deletions(-) create mode 100644 src/components/__tests__/DxhDropdown.spec.ts diff --git a/src/App.vue b/src/App.vue index 82f369d..d5ef01e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,6 @@ @@ -9,6 +9,10 @@ import Dropdown from './components/DxhDropdown.vue' import { ref } from 'vue' -const dropdownOptions = ['Option 1', 'Option 2', 'Option 3'] +const dropdownItems = [ + { id: '1', option: 'Option 1' }, + { id: '2', option: 'Option 2' }, + { id: '3', option: 'Option 3' } +] const selectedItem = ref(null) diff --git a/src/components/DxhDropdown.vue b/src/components/DxhDropdown.vue index 8a79771..1a02d7b 100644 --- a/src/components/DxhDropdown.vue +++ b/src/components/DxhDropdown.vue @@ -1,12 +1,20 @@ 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 } From 1170f0cec93748dbc14f420f9b98fc4a9bc006b5 Mon Sep 17 00:00:00 2001 From: git-mahade Date: Mon, 18 Dec 2023 11:37:23 +0600 Subject: [PATCH 3/3] dropdown --- src/App.vue | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/App.vue b/src/App.vue index d5ef01e..46362c7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,18 +1,5 @@ - - +
+ Vue-Tailwind +
+ \ No newline at end of file