1
0
mirror of synced 2024-11-22 21:36:04 +03:00
vue-formulario/test/unit/FormulateInputButton.test.js

106 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-01-28 20:12:08 +03:00
import Vue from 'vue'
import flushPromises from 'flush-promises'
2020-01-28 20:12:08 +03:00
import { mount } from '@vue/test-utils'
import Formulate from '@/Formulate.js'
2020-01-28 20:12:08 +03:00
import FormulateInput from '@/FormulateInput.vue'
import FormulateInputButton from '@/inputs/FormulateInputButton.vue'
Vue.use(Formulate)
describe('FormulateInputButton', () => {
2020-01-28 20:12:08 +03:00
it('renders a button element', () => {
const wrapper = mount(FormulateInput, { propsData: { type: 'button' } })
expect(wrapper.contains(FormulateInputButton)).toBe(true)
})
2020-01-28 20:12:08 +03:00
it('renders a button element when type submit', () => {
const wrapper = mount(FormulateInput, { propsData: { type: 'submit' } })
expect(wrapper.contains(FormulateInputButton)).toBe(true)
})
2020-01-28 20:12:08 +03:00
it('uses value as highest priority content', () => {
const wrapper = mount(FormulateInput, { propsData: {
type: 'submit',
value: 'Value content',
label: 'Label content',
name: 'Name content'
}})
expect(wrapper.find('button').text()).toBe('Value content')
})
2020-01-28 20:12:08 +03:00
it('uses label as second highest priority content', () => {
const wrapper = mount(FormulateInput, { propsData: {
type: 'submit',
label: 'Label content',
name: 'Name content'
}})
expect(wrapper.find('button').text()).toBe('Label content')
})
2020-01-28 20:12:08 +03:00
it('uses name as lowest priority content', () => {
const wrapper = mount(FormulateInput, { propsData: {
type: 'submit',
name: 'Name content'
}})
expect(wrapper.find('button').text()).toBe('Name content')
})
2020-01-28 20:12:08 +03:00
it('uses "Submit" as default content', () => {
const wrapper = mount(FormulateInput, { propsData: {
type: 'submit',
}})
expect(wrapper.find('button').text()).toBe('Submit')
})
2020-01-28 20:12:08 +03:00
it('with label does not render label element', () => {
const wrapper = mount(FormulateInput, { propsData: {
type: 'button',
label: 'my label'
}})
expect(wrapper.find('label').exists()).toBe(false)
})
2020-01-28 20:12:08 +03:00
it('does not render label element when type "submit"', () => {
const wrapper = mount(FormulateInput, { propsData: {
2020-01-28 20:12:08 +03:00
type: 'button',
label: 'my label'
}})
expect(wrapper.find('label').exists()).toBe(false)
2020-01-28 20:12:08 +03:00
})
it('renders slot inside button when type "button"', () => {
const wrapper = mount(FormulateInput, {
propsData: {
type: 'button',
label: 'my label',
},
slots: {
default: '<span>My custom slot</span>'
}
})
expect(wrapper.find('button > span').html()).toBe('<span>My custom slot</span>')
})
it('emits a click event when the button itself is clicked', async () => {
const handle = jest.fn();
const wrapper = mount({
template: `
<div>
<FormulateInput
type="submit"
@click="handle"
/>
</div>
`,
methods: {
handle
}
})
wrapper.find('button[type="submit"]').trigger('click')
await flushPromises();
expect(handle.mock.calls.length).toBe(1)
})
2020-01-28 20:12:08 +03:00
})