add unit tests for input email component

This commit is contained in:
mahula 2023-01-04 19:25:59 +01:00
parent ec2f06f9f6
commit abecbf77c2

View File

@ -1,5 +1,6 @@
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import InputHour from './InputHour' import InputHour from './InputHour'
import flushPromises from 'flush-promises'
const localVue = global.localVue const localVue = global.localVue
@ -17,12 +18,12 @@ describe('InputHour', () => {
}, },
} }
describe('mount in a InputHour', () => { describe('mount', () => {
const propsData = { const propsData = {
rules: {}, rules: {},
name: '', name: 'input-field-name',
label: '', label: 'input-field-label',
placeholder: '', placeholder: 'input-field-placeholder',
value: 500, value: 500,
validMaxTime: 25, validMaxTime: 25,
} }
@ -37,10 +38,52 @@ describe('InputHour', () => {
beforeEach(() => { beforeEach(() => {
wrapper = Wrapper() wrapper = Wrapper()
// await wrapper.setData({ currentValue: 15 })
}) })
it('renders the component input-hour', () => { it('renders the component input-hour', () => {
expect(wrapper.find('div.input-hour').exists()).toBe(true) expect(wrapper.find('div.input-hour').exists()).toBe(true)
}) })
it('has an input field', () => {
expect(wrapper.find('input').exists()).toBeTruthy()
})
describe('properties', () => {
it('has the id "input-field-name-input-field"', () => {
expect(wrapper.find('input').attributes('id')).toEqual('input-field-name-input-field')
})
it('has the placeholder "input-field-placeholder"', () => {
expect(wrapper.find('input').attributes('placeholder')).toEqual('input-field-placeholder')
})
it('has the value 0', () => {
expect(wrapper.vm.currentValue).toEqual(0)
})
it('has the label "input-field-label"', () => {
expect(wrapper.find('label').text()).toEqual('input-field-label')
})
it('has the label for "input-field-name-input-field"', () => {
expect(wrapper.find('label').attributes('for')).toEqual('input-field-name-input-field')
})
})
describe('input value changes', () => {
it('emits input with new value', async () => {
await wrapper.find('input').setValue('12')
expect(wrapper.emitted('input')).toBeTruthy()
expect(wrapper.emitted('input')).toEqual([['12']])
})
})
describe('value property changes', () => {
it('updates data model', async () => {
await wrapper.setProps({ value: 15 })
expect(wrapper.vm.currentValue).toEqual(15)
})
})
}) })
}) })