diff --git a/src/App.vue b/src/App.vue index a0d7a19..ef16a8e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,5 +1,3 @@ diff --git a/src/components/DxhFileInput.vue b/src/components/DxhFileInput.vue new file mode 100644 index 0000000..549edbb --- /dev/null +++ b/src/components/DxhFileInput.vue @@ -0,0 +1,79 @@ + + + diff --git a/src/components/__tests__/DxhFileInput.spec.ts b/src/components/__tests__/DxhFileInput.spec.ts new file mode 100644 index 0000000..fc6e4b2 --- /dev/null +++ b/src/components/__tests__/DxhFileInput.spec.ts @@ -0,0 +1,35 @@ +import { describe, it, expect, beforeEach } from 'vitest' +import { mount } from '@vue/test-utils' +import DxhFileInput from '../DxhFileInput.vue' + +describe('DxhFileInput', () => { + let wrapper: any + + beforeEach(() => { + wrapper = mount(DxhFileInput) + }) + + it('renders correctly with default props', () => { + expect(wrapper.find('label').exists()).toBe(true) + expect(wrapper.find('input[type="file"]').exists()).toBe(true) + }) + + it('displays label and placeholder text', async () => { + const label = 'File Input' + const placeholder = 'Choose a file' + + await wrapper.setProps({ label, placeholder }) + + expect(wrapper.find('span').text()).toBe(label) + expect(wrapper.find('input').attributes('placeholder')).toBe(placeholder) + }) + + it('clears file on clearFile method call', async () => { + await wrapper.setProps({ modelValue: 'test-file.txt' }) + + await wrapper.vm.clearFile() + + expect(wrapper.emitted('update:modelValue')).toBeTruthy() + expect(wrapper.emitted('update:modelValue')[0]).toEqual(['']) + }) +}) diff --git a/src/index.ts b/src/index.ts index ee2ff8d..cdd33da 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 DxhFileInput from './components/DxhFileInput.vue' -export default {DButton, DInput} \ No newline at end of file +export default { DButton, DInput, DxhFileInput }