2020-01-28 20:12:08 +03:00
|
|
|
import Vue from 'vue'
|
2020-05-09 00:25:52 +03:00
|
|
|
import flushPromises from 'flush-promises'
|
2020-01-28 20:12:08 +03:00
|
|
|
import { mount } from '@vue/test-utils'
|
2020-04-13 18:59:54 +03:00
|
|
|
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)
|
|
|
|
|
2020-05-09 00:25:52 +03:00
|
|
|
describe('FormulateInputButton', () => {
|
2020-01-28 20:12:08 +03:00
|
|
|
|
2020-05-09 00:25:52 +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
|
|
|
|
2020-05-09 00:25:52 +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
|
|
|
|
2020-05-09 00:25:52 +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
|
|
|
|
2020-05-09 00:25:52 +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
|
|
|
|
2020-05-09 00:25:52 +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
|
|
|
|
2020-05-09 00:25:52 +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
|
|
|
|
2020-05-09 00:25:52 +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
|
|
|
|
2020-05-09 00:25:52 +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',
|
2020-05-09 00:25:52 +03:00
|
|
|
label: 'my label'
|
|
|
|
}})
|
|
|
|
expect(wrapper.find('label').exists()).toBe(false)
|
2020-01-28 20:12:08 +03:00
|
|
|
})
|
2020-05-09 00:25:52 +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
|
|
|
})
|