diff --git a/src/App.vue b/src/App.vue index a0d7a19..2f96d8b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,47 @@ + + diff --git a/src/components/DxhRadio.vue b/src/components/DxhRadio.vue new file mode 100644 index 0000000..9ad8d6f --- /dev/null +++ b/src/components/DxhRadio.vue @@ -0,0 +1,40 @@ + + + diff --git a/src/components/__tests__/DxhRadio.spec.ts b/src/components/__tests__/DxhRadio.spec.ts new file mode 100644 index 0000000..25c8733 --- /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('[data-test="radio"]').exists()).toBe(true) + expect(wrapper.find('[data-test="radio"]').element.checked).toBe(false) + expect(wrapper.find('[data-test="label"]').text()).toBe('Option 1') + expect(wrapper.find('[data-test="hint"]').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('[data-test="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 }