Refactor and enhance tests, try

This commit is contained in:
Wolfgang Huß 2022-07-26 16:20:49 +02:00
parent b590a82b04
commit 7eb6fc6c51

View File

@ -1,4 +1,5 @@
import { mount } from '@vue/test-utils'
import flushPromises from 'flush-promises'
import ContributionForm from './ContributionForm.vue'
const localVue = global.localVue
@ -6,7 +7,7 @@ const localVue = global.localVue
describe('ContributionForm', () => {
let wrapper
const propsData = {
let propsData = {
value: {
id: null,
date: '',
@ -42,8 +43,132 @@ describe('ContributionForm', () => {
expect(wrapper.find('div.contribution-form').exists()).toBe(true)
})
it('is submit button disable of true', () => {
expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBe('disabled')
describe('empty form data', () => {
describe('has button', () => {
it('reset enabled', () => {
expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy()
})
it('submit disabled', () => {
expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBe('disabled')
})
})
})
describe('set contrubtion', () => {
describe('fill in form data', () => {
const now = new Date().toISOString()
beforeEach(async () => {
await wrapper.setData({
form: {
id: null,
date: now,
memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...',
amount: '200',
},
})
})
describe('has button', () => {
it('reset enabled', () => {
expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy()
})
it('submit enabled', () => {
expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBeFalsy()
})
})
describe.skip('on trigger submit', () => {
beforeEach(async () => {
// await wrapper.find('.test-submit').trigger('click')
await wrapper.find('button[type="submit"]').trigger('click')
})
it('emits "set-contribution"', () => {
expect(wrapper.emitted('set-contribution')).toEqual({
id: null,
date: now,
memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...',
amount: '200',
})
})
})
})
})
describe('update contrubtion', () => {
describe('fill in form data and "id"', () => {
const now = new Date().toISOString()
beforeEach(async () => {
// Wolle: await wrapper.setData({
// form: {
// id: 2,
// date: now,
// memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...',
// amount: '200',
// },
// })
// await wrapper.setData({
// form: {
// id: 2,
// },
// })
propsData = {
value: {
id: 2,
date: '',
memo: '',
amount: '',
},
}
wrapper = Wrapper()
// await wrapper.findComponent({ name: 'BFormDatepicker' }).vm.$emit('input', now)
await wrapper
.find('#contribution-memo')
.find('textarea')
.setValue('Mein Beitrag zur Gemeinschaft für diesen Monat ...')
await wrapper.find('#contribution-amount').find('input').setValue('200')
await flushPromises()
// Wolle:
await wrapper.vm.$nextTick()
})
describe('has button', () => {
it('reset enabled', () => {
expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy()
})
it('submit enabled', () => {
expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBeFalsy()
})
})
describe.only('on trigger submit', () => {
beforeEach(async () => {
// await wrapper.find('.test-submit').trigger('click')
// await wrapper.find('button[type="submit"]').trigger('click')
await wrapper.find('form').trigger('submit')
})
it('emits "update-contribution"', () => {
expect(wrapper.emitted('update-contribution')).toEqual(
expect.arrayContaining([
expect.arrayContaining([
{
id: 2,
date: now,
memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...',
amount: '200',
},
]),
]),
)
})
})
})
})
})
})