increase test coverage

This commit is contained in:
Moriz Wahl 2022-10-13 10:18:36 +02:00
parent d662338f6a
commit 51da13b461
2 changed files with 63 additions and 41 deletions

View File

@ -1,6 +1,7 @@
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import ContributionLinkForm from './ContributionLinkForm.vue' import ContributionLinkForm from './ContributionLinkForm.vue'
import { toastErrorSpy } from '../../test/testSetup' import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup'
import { createContributionLink } from '@/graphql/createContributionLink.js'
const localVue = global.localVue const localVue = global.localVue
@ -72,48 +73,70 @@ describe('ContributionLinkForm', () => {
}) })
}) })
// describe('successfull submit', () => { describe('successfull submit', () => {
// beforeEach(async () => { beforeEach(async () => {
// mockAPIcall.mockResolvedValue({ apolloMutateMock.mockResolvedValue({
// data: { data: {
// createContributionLink: { createContributionLink: {
// link: 'https://localhost/redeem/CL-1a2345678', link: 'https://localhost/redeem/CL-1a2345678',
// }, },
// }, },
// }) })
// await wrapper.find('input.test-validFrom').setValue('2022-6-18') await wrapper
// await wrapper.find('input.test-validTo').setValue('2022-7-18') .findAllComponents({ name: 'BFormDatepicker' })
// await wrapper.find('input.test-name').setValue('test name') .at(0)
// await wrapper.find('input.test-memo').setValue('test memo') .vm.$emit('input', '2022-6-18')
// await wrapper.find('input.test-amount').setValue('100') await wrapper
// await wrapper.find('form').trigger('submit') .findAllComponents({ name: 'BFormDatepicker' })
// }) .at(1)
.vm.$emit('input', '2022-7-18')
await wrapper.find('input.test-name').setValue('test name')
await wrapper.find('textarea.test-memo').setValue('test memo')
await wrapper.find('input.test-amount').setValue('100')
await wrapper.find('form').trigger('submit')
})
// it('calls the API', () => { it('calls the API', () => {
// expect(mockAPIcall).toHaveBeenCalledWith( expect(apolloMutateMock).toHaveBeenCalledWith({
// expect.objectContaining({ mutation: createContributionLink,
// variables: { variables: {
// link: 'https://localhost/redeem/CL-1a2345678', validFrom: '2022-6-18',
// }, validTo: '2022-7-18',
// }), name: 'test name',
// ) amount: '100',
// }) memo: 'test memo',
cycle: 'ONCE',
maxPerCycle: 1,
maxAmountPerMonth: '0',
},
})
})
// it('displays the new username', () => { it('toasts a succes message', () => {
// expect(wrapper.find('div.display-username').text()).toEqual('@username') expect(toastSuccessSpy).toBeCalledWith('https://localhost/redeem/CL-1a2345678')
// }) })
// })
})
describe('send createContributionLink with error', () => {
beforeEach(() => {
apolloMutateMock.mockRejectedValue({ message: 'OUCH!' })
wrapper = Wrapper()
wrapper.vm.onSubmit()
}) })
it('toasts an error message', () => { describe('send createContributionLink with error', () => {
expect(toastErrorSpy).toBeCalledWith('contributionLink.noStartDate') beforeEach(async () => {
apolloMutateMock.mockRejectedValue({ message: 'OUCH!' })
await wrapper
.findAllComponents({ name: 'BFormDatepicker' })
.at(0)
.vm.$emit('input', '2022-6-18')
await wrapper
.findAllComponents({ name: 'BFormDatepicker' })
.at(1)
.vm.$emit('input', '2022-7-18')
await wrapper.find('input.test-name').setValue('test name')
await wrapper.find('textarea.test-memo').setValue('test memo')
await wrapper.find('input.test-amount').setValue('100')
await wrapper.find('form').trigger('submit')
})
it('toasts an error message', () => {
expect(toastErrorSpy).toBeCalledWith('OUCH!')
})
}) })
}) })
}) })

View File

@ -193,8 +193,7 @@ export default {
return this.contributionLinkData return this.contributionLinkData
}, },
disabled() { disabled() {
if (this.form.cycle === 'ONCE') return true return true
return false
}, },
}, },
watch: { watch: {