test to 100%

This commit is contained in:
Moriz Wahl 2023-02-10 14:16:55 +01:00
parent 2e18ca41c9
commit 04fd66dbc4
2 changed files with 152 additions and 186 deletions

View File

@ -24,11 +24,6 @@ describe('ContributionForm', () => {
$t: jest.fn((t) => t), $t: jest.fn((t) => t),
$d: jest.fn((d) => d), $d: jest.fn((d) => d),
$n: jest.fn((n) => n), $n: jest.fn((n) => n),
$store: {
state: {
creation: ['1000', '1000', '1000'],
},
},
$i18n: { $i18n: {
locale: 'en', locale: 'en',
}, },
@ -61,7 +56,7 @@ describe('ContributionForm', () => {
}) })
}) })
describe('dates', () => { describe('dates and max amounts', () => {
beforeEach(async () => { beforeEach(async () => {
await wrapper.setData({ await wrapper.setData({
form: { form: {
@ -73,204 +68,176 @@ describe('ContributionForm', () => {
}) })
}) })
describe('actual date', () => { describe('max amount reached for both months', () => {
describe('same month', () => { beforeEach(() => {
beforeEach(async () => { wrapper.setProps({
const now = new Date().toISOString() maxGddLastMonth: 0,
await wrapper.findComponent({ name: 'BFormDatepicker' }).vm.$emit('input', now) maxGddThisMonth: 0,
}) })
wrapper.setData({
describe('isThisMonth', () => { form: {
it('has true', () => { id: null,
expect(wrapper.vm.isThisMonth).toBe(true) date: 'set',
}) memo: '',
amount: '',
},
}) })
}) })
describe.skip('month before', () => { it('shows message that no contributions are available', () => {
beforeEach(async () => { expect(wrapper.find('[data-test="contribtion-message"]').text()).toBe(
await wrapper 'contribution.noOpenCreation.allMonth',
.findComponent({ name: 'BFormDatepicker' }) )
.vm.$emit('input', wrapper.vm.minimalDate)
})
describe('isThisMonth', () => {
it('has false', () => {
expect(wrapper.vm.isThisMonth).toBe(false)
})
})
}) })
}) })
describe.skip('date in middle of year', () => { describe('max amount reached for last month, no date selected', () => {
describe('same month', () => { beforeEach(() => {
beforeEach(async () => { wrapper.setProps({
// jest.useFakeTimers('modern') maxGddLastMonth: 0,
// jest.setSystemTime(new Date('2020-07-06'))
// await wrapper.findComponent({ name: 'BFormDatepicker' }).vm.$emit('input', now)
await wrapper.setData({
maximalDate: new Date(2020, 6, 6),
form: { date: new Date(2020, 6, 6) },
})
})
describe('minimalDate', () => {
it('has "2020-06-01T00:00:00.000Z"', () => {
expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-06-01T00:00:00.000Z')
})
})
describe('isThisMonth', () => {
it('has true', () => {
expect(wrapper.vm.isThisMonth).toBe(true)
})
}) })
}) })
describe('month before', () => { it('shows no message', () => {
beforeEach(async () => { expect(wrapper.find('[data-test="contribtion-message"]').exists()).toBe(false)
// jest.useFakeTimers('modern')
// jest.setSystemTime(new Date('2020-07-06'))
// console.log('middle of year date now:', wrapper.vm.minimalDate)
// await wrapper
// .findComponent({ name: 'BFormDatepicker' })
// .vm.$emit('input', wrapper.vm.minimalDate)
await wrapper.setData({
maximalDate: new Date(2020, 6, 6),
form: { date: new Date(2020, 5, 6) },
})
})
describe('minimalDate', () => {
it('has "2020-06-01T00:00:00.000Z"', () => {
expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-06-01T00:00:00.000Z')
})
})
describe('isThisMonth', () => {
it('has false', () => {
expect(wrapper.vm.isThisMonth).toBe(false)
})
})
}) })
}) })
describe.skip('date in january', () => { describe('max amount reached for last month, last month selected', () => {
describe('same month', () => { beforeEach(async () => {
beforeEach(async () => { wrapper.setProps({
await wrapper.setData({ maxGddLastMonth: 0,
maximalDate: new Date(2020, 0, 6), isThisMonth: false,
form: { date: new Date(2020, 0, 6) },
})
}) })
await wrapper.setData({
describe('minimalDate', () => { form: {
it('has "2019-12-01T00:00:00.000Z"', () => { id: null,
expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-12-01T00:00:00.000Z') date: 'set',
}) memo: '',
}) amount: '',
},
describe('isThisMonth', () => {
it('has true', () => {
expect(wrapper.vm.isThisMonth).toBe(true)
})
}) })
}) })
describe('month before', () => { it('shows message that no contributions are available for last month', () => {
beforeEach(async () => { expect(wrapper.find('[data-test="contribtion-message"]').text()).toBe(
// jest.useFakeTimers('modern') 'contribution.noOpenCreation.lastMonth',
// jest.setSystemTime(new Date('2020-07-06')) )
// console.log('middle of year date now:', wrapper.vm.minimalDate)
// await wrapper
// .findComponent({ name: 'BFormDatepicker' })
// .vm.$emit('input', wrapper.vm.minimalDate)
await wrapper.setData({
maximalDate: new Date(2020, 0, 6),
form: { date: new Date(2019, 11, 6) },
})
})
describe('minimalDate', () => {
it('has "2019-12-01T00:00:00.000Z"', () => {
expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-12-01T00:00:00.000Z')
})
})
describe('isThisMonth', () => {
it('has false', () => {
expect(wrapper.vm.isThisMonth).toBe(false)
})
})
}) })
}) })
describe.skip('date with the 31st day of the month', () => { describe('max amount reached for last month, this month selected', () => {
describe('same month', () => { beforeEach(async () => {
beforeEach(async () => { wrapper.setProps({
await wrapper.setData({ maxGddLastMonth: 0,
maximalDate: new Date('2022-10-31T00:00:00.000Z'), isThisMonth: true,
form: { date: new Date('2022-10-31T00:00:00.000Z') },
})
}) })
await wrapper.setData({
form: {
id: null,
date: 'set',
memo: '',
amount: '',
},
})
})
describe('minimalDate', () => { it('shows no message', () => {
it('has "2022-09-01T00:00:00.000Z"', () => { expect(wrapper.find('[data-test="contribtion-message"]').exists()).toBe(false)
expect(wrapper.vm.minimalDate.toISOString()).toBe('2022-09-01T00:00:00.000Z')
})
})
describe('isThisMonth', () => {
it('has true', () => {
expect(wrapper.vm.isThisMonth).toBe(true)
})
})
}) })
}) })
describe.skip('date with the 28th day of the month', () => { describe('max amount reached for this month, no date selected', () => {
describe('same month', () => { beforeEach(() => {
beforeEach(async () => { wrapper.setProps({
await wrapper.setData({ maxGddThisMonth: 0,
maximalDate: new Date('2023-02-28T00:00:00.000Z'),
form: { date: new Date('2023-02-28T00:00:00.000Z') },
})
}) })
})
describe('minimalDate', () => { it('shows no message', () => {
it('has "2023-01-01T00:00:00.000Z"', () => { expect(wrapper.find('[data-test="contribtion-message"]').exists()).toBe(false)
expect(wrapper.vm.minimalDate.toISOString()).toBe('2023-01-01T00:00:00.000Z')
})
})
describe('isThisMonth', () => {
it('has true', () => {
expect(wrapper.vm.isThisMonth).toBe(true)
})
})
}) })
}) })
describe.skip('date with 29.02.2024 leap year', () => { describe('max amount reached for this month, this month selected', () => {
describe('same month', () => { beforeEach(async () => {
beforeEach(async () => { wrapper.setProps({
await wrapper.setData({ maxGddThisMonth: 0,
maximalDate: new Date('2024-02-29T00:00:00.000Z'), isThisMonth: true,
form: { date: new Date('2024-02-29T00:00:00.000Z') },
})
}) })
await wrapper.setData({
form: {
id: null,
date: 'set',
memo: '',
amount: '',
},
})
})
describe('minimalDate', () => { it('shows message that no contributions are available for last month', () => {
it('has "2024-01-01T00:00:00.000Z"', () => { expect(wrapper.find('[data-test="contribtion-message"]').text()).toBe(
expect(wrapper.vm.minimalDate.toISOString()).toBe('2024-01-01T00:00:00.000Z') 'contribution.noOpenCreation.thisMonth',
}) )
}) })
})
describe('isThisMonth', () => { describe('max amount reached for this month, last month selected', () => {
it('has true', () => { beforeEach(async () => {
expect(wrapper.vm.isThisMonth).toBe(true) wrapper.setProps({
}) maxGddThisMonth: 0,
isThisMonth: false,
}) })
await wrapper.setData({
form: {
id: null,
date: 'set',
memo: '',
amount: '',
},
})
})
it('shows no message', () => {
expect(wrapper.find('[data-test="contribtion-message"]').exists()).toBe(false)
})
})
})
describe('default return message', () => {
it('returns an empty string', () => {
expect(wrapper.vm.noOpenCreation).toBe('')
})
})
describe('update amount', () => {
beforeEach(() => {
wrapper.findComponent({ name: 'InputHour' }).vm.$emit('updateAmount', 20)
})
it('updates form amount', () => {
expect(wrapper.vm.form.amount).toBe('400.00')
})
})
describe('watch value', () => {
beforeEach(() => {
wrapper.setProps({
value: {
id: 42,
date: 'set',
memo: 'Some Memo',
amount: '400.00',
},
})
})
it('updates form', () => {
expect(wrapper.vm.form).toEqual({
id: 42,
date: 'set',
memo: 'Some Memo',
amount: '400.00',
}) })
}) })
}) })
@ -477,24 +444,23 @@ describe('ContributionForm', () => {
}) })
}) })
describe.skip('on trigger submit', () => { describe('on trigger submit', () => {
beforeEach(async () => { beforeEach(async () => {
await wrapper.find('form').trigger('submit') await wrapper.find('form').trigger('submit')
}) })
it('emits "update-contribution"', () => { it('emits "update-contribution"', () => {
expect(wrapper.emitted('update-contribution')).toEqual( expect(wrapper.emitted('update-contribution')).toEqual([
expect.arrayContaining([ [
expect.arrayContaining([ {
{ id: 2,
id: 2, date: now,
date: now, hours: 0,
memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...', memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...',
amount: '200', amount: '200',
}, },
]), ],
]), ])
)
}) })
}) })
}) })

View File

@ -23,7 +23,7 @@
<template #nav-next-year><span></span></template> <template #nav-next-year><span></span></template>
</b-form-datepicker> </b-form-datepicker>
<div v-if="showMessage" class="p-3"> <div v-if="showMessage" class="p-3" data-test="contribtion-message">
{{ noOpenCreation }} {{ noOpenCreation }}
</div> </div>
<div v-else> <div v-else>
@ -115,8 +115,8 @@ export default {
} }
}, },
methods: { methods: {
updateAmount(amount) { updateAmount(hours) {
this.form.amount = (amount * 20).toFixed(2).toString() this.form.amount = (hours * 20).toFixed(2).toString()
}, },
submit() { submit() {
this.$emit(this.form.id ? 'update-contribution' : 'set-contribution', { ...this.form }) this.$emit(this.form.id ? 'update-contribution' : 'set-contribution', { ...this.form })