diff --git a/frontend/src/components/Contributions/ContributionForm.spec.js b/frontend/src/components/Contributions/ContributionForm.spec.js index 4f3ee6fa6..eb1509328 100644 --- a/frontend/src/components/Contributions/ContributionForm.spec.js +++ b/frontend/src/components/Contributions/ContributionForm.spec.js @@ -45,8 +45,70 @@ 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('buttons', () => { + it('has reset enabled', () => { + expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy() + }) + + it('has 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('buttons', () => { + it('has reset enabled', () => { + expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy() + }) + + it('has submit enabled', () => { + expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBeFalsy() + }) + }) + }) + }) + + describe('update contrubtion', () => { + describe('fill in form data and "id"', () => { + const now = new Date().toISOString() + + beforeEach(async () => { + await wrapper.setData({ + form: { + id: 2, + date: now, + memo: 'Mein Beitrag zur Gemeinschaft für diesen Monat ...', + amount: '200', + }, + }) + }) + + describe('buttons', () => { + it('has reset enabled', () => { + expect(wrapper.find('button[type="reset"]').attributes('disabled')).toBeFalsy() + }) + + it('has submit enabled', () => { + expect(wrapper.find('button[type="submit"]').attributes('disabled')).toBeFalsy() + }) + }) + }) }) }) }) diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index f345ffff4..b18a92a13 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -71,13 +71,13 @@ - - {{ $t('form.reset') }} + + {{ $t('form.cancel') }} - {{ value.id ? $t('form.edit') : $t('contribution.submit') }} + {{ form.id ? $t('form.change') : $t('contribution.submit') }} @@ -96,13 +96,12 @@ export default { minlength: 5, maxlength: 255, maximalDate: new Date(), - form: this.value, - id: this.value.id, + form: this.value, // includes 'id' } }, methods: { submit() { - if (this.value.id) { + if (this.form.id) { this.$emit('update-contribution', this.form) } else { this.$emit('set-contribution', this.form) @@ -111,9 +110,10 @@ export default { }, reset() { this.$refs.form.reset() + this.form.id = null this.form.date = '' - this.id = null this.form.memo = '' + this.form.amount = '' }, }, computed: { @@ -156,13 +156,13 @@ export default { }, maxGddLastMonth() { // When edited, the amount is added back on top of the amount - return this.value.id && !this.isThisMonth + return this.form.id && !this.isThisMonth ? parseInt(this.$store.state.creation[1]) + parseInt(this.updateAmount) : this.$store.state.creation[1] }, maxGddThisMonth() { // When edited, the amount is added back on top of the amount - return this.value.id && this.isThisMonth + return this.form.id && this.isThisMonth ? parseInt(this.$store.state.creation[2]) + parseInt(this.updateAmount) : this.$store.state.creation[2] }, diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 62edd9815..f0d2507db 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -105,12 +105,12 @@ "amount": "Betrag", "at": "am", "cancel": "Abbrechen", + "change": "Ändern", "check_now": "Jetzt prüfen", "close": "Schließen", "current_balance": "Aktueller Kontostand", "date": "Datum", "description": "Beschreibung", - "edit": "Bearbeiten", "email": "E-Mail", "firstname": "Vorname", "from": "Von", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 1cbdc5a8a..534addbe3 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -105,12 +105,12 @@ "amount": "Amount", "at": "at", "cancel": "Cancel", + "change": "Change", "check_now": "Check now", "close": "Close", "current_balance": "Current Balance", "date": "Date", "description": "Description", - "edit": "Edit", "email": "Email", "firstname": "Firstname", "from": "from", diff --git a/frontend/src/pages/Community.spec.js b/frontend/src/pages/Community.spec.js index deccabbb1..b4aa43785 100644 --- a/frontend/src/pages/Community.spec.js +++ b/frontend/src/pages/Community.spec.js @@ -193,6 +193,13 @@ describe('Community', () => { fetchPolicy: 'network-only', }) }) + + it('set all data to the default values)', () => { + expect(wrapper.vm.form.id).toBe(null) + expect(wrapper.vm.form.date).toBe('') + expect(wrapper.vm.form.memo).toBe('') + expect(wrapper.vm.form.amount).toBe('') + }) }) describe('with error', () => { @@ -273,6 +280,13 @@ describe('Community', () => { fetchPolicy: 'network-only', }) }) + + it('set all data to the default values)', () => { + expect(wrapper.vm.form.id).toBe(null) + expect(wrapper.vm.form.date).toBe('') + expect(wrapper.vm.form.memo).toBe('') + expect(wrapper.vm.form.amount).toBe('') + }) }) describe('with error', () => { @@ -379,7 +393,7 @@ describe('Community', () => { }) }) - it('sets the form date to the new values', () => { + it('sets the form data to the new values', () => { expect(wrapper.vm.form.id).toBe(2) expect(wrapper.vm.form.date).toBe(now) expect(wrapper.vm.form.memo).toBe('Mein Beitrag zur Gemeinschaft für diesen Monat ...')