You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

104 lines
3.6 KiB

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: '<input :type="$attrs.type" :disabled="$attrs.disabled" :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)" />',
props: ['type', 'disabled', 'modelValue', 'placeholder'],
},
UButton: {
template: '<button :disabled="$attrs.disabled" @click="$emit(\'click\')"><slot /></button>',
props: ['disabled'],
emits: ['click'],
},
UFormField: {
template: '<div><slot /></div>',
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: '<input :type="$attrs.type" :disabled="$attrs.disabled" :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)" />',
props: ['type', 'disabled', 'modelValue', 'placeholder'],
},
UButton: {
template: '<button :disabled="$attrs.disabled" @click="$emit(\'click\')"><slot /></button>',
props: ['disabled'],
emits: ['click'],
},
UFormField: {
template: '<div><slot /></div>',
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: '<input :type="$attrs.type" :disabled="$attrs.disabled" :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)" />',
props: ['type', 'disabled', 'modelValue', 'placeholder'],
},
UButton: {
template: '<button :disabled="$attrs.disabled" @click="$emit(\'click\')"><slot /></button>',
props: ['disabled'],
emits: ['click'],
},
UFormField: {
template: '<div><slot /></div>',
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: '<input :type="$attrs.type" :disabled="$attrs.disabled" :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)" />',
props: ['type', 'disabled', 'modelValue', 'placeholder'],
},
UButton: {
template: '<button :disabled="$attrs.disabled" @click="$emit(\'click\')"><slot /></button>',
props: ['disabled'],
emits: ['click'],
},
UFormField: {
template: '<div><slot /></div>',
props: ['label'],
},
},
},
})
expect(wrapper.find('input').element.disabled).toBe(true)
})
})