From dd951ece3bd11febca89103ceb4f61fe328cdb89 Mon Sep 17 00:00:00 2001 From: git-mahade Date: Tue, 5 Dec 2023 17:06:28 +0600 Subject: [PATCH 1/5] radio --- src/components/DxhRadio.vue | 39 ++++++++++++++++++++ src/components/__tests__/DxhRadio.spec.ts | 45 +++++++++++++++++++++++ src/index.ts | 7 ++-- 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 src/components/DxhRadio.vue create mode 100644 src/components/__tests__/DxhRadio.spec.ts diff --git a/src/components/DxhRadio.vue b/src/components/DxhRadio.vue new file mode 100644 index 0000000..2845ac5 --- /dev/null +++ b/src/components/DxhRadio.vue @@ -0,0 +1,39 @@ + + + diff --git a/src/components/__tests__/DxhRadio.spec.ts b/src/components/__tests__/DxhRadio.spec.ts new file mode 100644 index 0000000..b2216c5 --- /dev/null +++ b/src/components/__tests__/DxhRadio.spec.ts @@ -0,0 +1,45 @@ +import { describe, it, expect } from 'vitest' +import { mount } from '@vue/test-utils' +import DxhRadio from '../DxhRadio.vue' + +describe('DxhRadio.vue', () => { + it('renders a radio button with the correct default state', async () => { + const wrapper: any = mount(DxhRadio, { + props: { + id: '1', + name: 'radioGroup', + value: 'option1', + label: 'Option 1', + checked: false, + defaultChecked: false, + hint: 'Select this option', + disabled: false + } + }) + + expect(wrapper.find('input[type="radio"]').exists()).toBe(true) + expect(wrapper.find('input[type="radio"]').element.checked).toBe(false) + expect(wrapper.find('label').text()).toBe('Option 1') + expect(wrapper.find('p').text()).toBe('Select this option') + }) + + it('emits a change event when the radio button is clicked', async () => { + const wrapper: any = mount(DxhRadio, { + props: { + id: '2', + name: 'radioGroup', + value: 'option2', + label: 'Option 2', + checked: false, + defaultChecked: false, + hint: 'Select this option', + disabled: false + } + }) + + await wrapper.find('input[type="radio"]').trigger('change') + + expect(wrapper.emitted()).toHaveProperty('change') + expect(wrapper.emitted('change')[0]).toEqual([expect.any(Object)]) + }) +}) diff --git a/src/index.ts b/src/index.ts index ee2ff8d..4a1af27 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 DxhRadio from './components/DxhRadio.vue' -export default {DButton, DInput} \ No newline at end of file +export default { DButton, DInput, DxhRadio } From 125595d991195f6ff03c693bc45ca01ba5c4b151 Mon Sep 17 00:00:00 2001 From: git-mahade Date: Tue, 12 Dec 2023 23:52:39 +0600 Subject: [PATCH 2/5] radio --- src/App.vue | 2 +- src/components/DxhRadio.vue | 5 +++-- src/components/__tests__/DxhRadio.spec.ts | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) 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/DxhRadio.vue b/src/components/DxhRadio.vue index 2845ac5..cb56b1c 100644 --- a/src/components/DxhRadio.vue +++ b/src/components/DxhRadio.vue @@ -8,13 +8,14 @@ :checked="defaultChecked ? defaultChecked : checked" :disabled="disabled" :class="{ 'opacity-50 cursor-not-allowed': disabled }" + data-test="radio" @change="handleChange" /> -