|
| 1 | +import { mount, createLocalVue } from '@vue/test-utils' |
| 2 | +import flushPromises from 'flush-promises' |
| 3 | +import FormBuilder from '../../src/components/from-builder/FormBuilder.vue' |
| 4 | +import schema from './data/formSchema' |
| 5 | +import VeeValidate from 'vee-validate' |
| 6 | + |
| 7 | +const localVue = createLocalVue() |
| 8 | +localVue.use(VeeValidate) |
| 9 | + |
| 10 | +describe('FormBuilder', () => { |
| 11 | + const wrapper = mount(FormBuilder, { |
| 12 | + localVue, |
| 13 | + propsData: { |
| 14 | + model: { |
| 15 | + id: 1, |
| 16 | + name: 'John Doe', |
| 17 | + password: '123', |
| 18 | + passwordConfirm: '123', |
| 19 | + skills: [1], |
| 20 | + email: 'john.do@gmail.com', |
| 21 | + status: true, |
| 22 | + addons: [1, 3], |
| 23 | + delivery: 1, |
| 24 | + comment: 'some text' |
| 25 | + }, |
| 26 | + schema |
| 27 | + } |
| 28 | + }) |
| 29 | + it('rendered all fields from schema', () => { |
| 30 | + expect(wrapper.exists()).toBe(true) |
| 31 | + schema.fields.map(f => { |
| 32 | + if (f.type !== 'actions') { |
| 33 | + expect(wrapper.find(`[name="${f.name}"]`).exists()).toBe(true) |
| 34 | + } else { |
| 35 | + f.buttons.map((b, i) => { |
| 36 | + expect(wrapper.findAll('.vue-button').at(i).exists()).toBe(true) |
| 37 | + }) |
| 38 | + } |
| 39 | + }) |
| 40 | + }) |
| 41 | + it('check validation', async () => { |
| 42 | + const input = wrapper.find('[name="delivery"]') |
| 43 | + expect(wrapper.vm.errors.count()).toBe(0) |
| 44 | + wrapper.setData({ clonedModel: { ...wrapper.vm.clonedModel, delivery: null } }) |
| 45 | + input.trigger('input') |
| 46 | + await flushPromises() |
| 47 | + expect(wrapper.vm.errors.count()).toBe(1) |
| 48 | + }) |
| 49 | +}) |
0 commit comments