diff --git a/app/components/register/PasswordInput.vue b/app/components/register/PasswordInput.vue new file mode 100644 index 0000000..7b883b3 --- /dev/null +++ b/app/components/register/PasswordInput.vue @@ -0,0 +1,42 @@ + + + diff --git a/app/components/register/__tests__/PasswordInput.test.ts b/app/components/register/__tests__/PasswordInput.test.ts new file mode 100644 index 0000000..b5ea609 --- /dev/null +++ b/app/components/register/__tests__/PasswordInput.test.ts @@ -0,0 +1,104 @@ +import { describe, it, expect } from 'vitest' +import { mount } from '@vue/test-utils' +import PasswordInput from '../PasswordInput.vue' + +describe('PasswordInput', () => { + it('renders with type=password by default', () => { + const wrapper = mount(PasswordInput, { + props: { modelValue: '' }, + global: { + stubs: { + UInput: { + template: '', + props: ['type', 'disabled', 'modelValue', 'placeholder'], + }, + UButton: { + template: '', + props: ['disabled'], + emits: ['click'], + }, + UFormField: { + template: '
', + props: ['label'], + }, + }, + }, + }) + const input = wrapper.find('input') + expect(input.attributes('type')).toBe('password') + }) + + it('toggles to type=text when button clicked', async () => { + const wrapper = mount(PasswordInput, { + props: { modelValue: '' }, + global: { + stubs: { + UInput: { + template: '', + props: ['type', 'disabled', 'modelValue', 'placeholder'], + }, + UButton: { + template: '', + props: ['disabled'], + emits: ['click'], + }, + UFormField: { + template: '
', + props: ['label'], + }, + }, + }, + }) + const btn = wrapper.find('button') + await btn.trigger('click') + expect(wrapper.find('input').attributes('type')).toBe('text') + }) + + it('renders label when provided', () => { + const wrapper = mount(PasswordInput, { + props: { modelValue: '', label: 'Test Label' }, + global: { + stubs: { + UInput: { + template: '', + props: ['type', 'disabled', 'modelValue', 'placeholder'], + }, + UButton: { + template: '', + props: ['disabled'], + emits: ['click'], + }, + UFormField: { + template: '
', + props: ['label'], + }, + }, + }, + }) + expect(wrapper.text()).toContain('Test Label') + }) + + it('disables input when disabled prop is true', () => { + const wrapper = mount(PasswordInput, { + props: { modelValue: '', disabled: true }, + global: { + stubs: { + UInput: { + template: '', + props: ['type', 'disabled', 'modelValue', 'placeholder'], + }, + UButton: { + template: '', + props: ['disabled'], + emits: ['click'], + }, + UFormField: { + template: '
', + props: ['label'], + }, + }, + }, + }) + expect(wrapper.find('input').element.disabled).toBe(true) + }) +})