diff --git a/frontend/src/components/Contributions/ContributionForm.spec.js b/frontend/src/components/Contributions/ContributionForm.spec.js index 36c209f8d..71414d284 100644 --- a/frontend/src/components/Contributions/ContributionForm.spec.js +++ b/frontend/src/components/Contributions/ContributionForm.spec.js @@ -47,8 +47,6 @@ describe('ContributionForm', () => { hours: 2, amount: 40, }, - isThisMonth: true, - minimalDate: new Date('2024-01-01'), maxGddLastMonth: 100, maxGddThisMonth: 200, } @@ -66,44 +64,82 @@ describe('ContributionForm', () => { expect(wrapper.find('.contribution-form').exists()).toBe(true) }) - it('computes showMessage correctly', async () => { - expect(wrapper.vm.showMessage).toBe(false) - - await wrapper.setProps({ - maxGddThisMonth: 0, - maxGddLastMonth: 0, + describe('compute isThisMonth', () => { + it('return true', async () => { + await wrapper.setProps({ + modelValue: { date: new Date().toISOString() } + }) + expect(wrapper.vm.isThisMonth).toBe(true) }) + it('return false', async () => { + const now = new Date() + const lastMonth = new Date(now.setMonth(now.getMonth() - 1, 1)) + await wrapper.setProps({ + modelValue: { date: lastMonth.toISOString() } + }) + expect(wrapper.vm.isThisMonth).toBe(false) + }) + }) - expect(wrapper.vm.showMessage).toBe(true) + describe('noOpenCreations return correct translation key', () => { + it("if both max gdd are > 0", () => { + expect(wrapper.vm.noOpenCreation).toBeUndefined() + }) + it('if max gdd for this month is 0, and form.date is in last month', async () => { + const now = new Date() + const lastMonth = new Date(now.setMonth(now.getMonth() - 1, 1)) + await wrapper.setProps({ + maxGddThisMonth: 0, + modelValue: { date: lastMonth.toISOString() } + }) + expect(wrapper.vm.noOpenCreation).toBeUndefined() + }) + it('if max gdd for last month is 0, and form.date is in this month', async () => { + await wrapper.setProps({ + maxGddLastMonth: 0, + modelValue: { date: new Date().toISOString() } + }) + expect(wrapper.vm.noOpenCreation).toBeUndefined() + }) + it('if max gdd is 0 for both months', async () => { + await wrapper.setProps({ + maxGddThisMonth: 0, + maxGddLastMonth: 0, + }) + expect(wrapper.vm.noOpenCreation).toBe('contribution.noOpenCreation.allMonth') + }) + it('if max gdd this month is zero and form.date is inside this month', async () => { + await wrapper.setProps({ + maxGddThisMonth: 0, + modelValue: { date: new Date().toISOString() } + }) + expect(wrapper.vm.noOpenCreation).toBe('contribution.noOpenCreation.thisMonth') + }) + it('if max gdd last month is zero and form.date is inside last month', async () => { + const now = new Date() + const lastMonth = new Date(now.setMonth(now.getMonth() - 1, 1)) + await wrapper.setProps({ + maxGddLastMonth: 0, + modelValue: { date: lastMonth.toISOString() } + }) + expect(wrapper.vm.noOpenCreation).toBe('contribution.noOpenCreation.lastMonth') + }) }) it('computes disabled correctly', async () => { - expect(wrapper.vm.disabled).toBe(false) + expect(wrapper.vm.disabled).toBe(true) await wrapper.setProps({ - maxGddThisMonth: 30, + modelValue: { date: new Date().toISOString().slice(0, 10) } }) wrapper.vm.form.amount = 100 - - expect(wrapper.vm.disabled).toBe(true) - }) - - it('computes validMaxGDD correctly', async () => { - expect(wrapper.vm.validMaxGDD).toBe(200) - - await wrapper.setProps({ isThisMonth: false }) - - expect(wrapper.vm.validMaxGDD).toBe(100) - }) + + expect(wrapper.vm.disabled).toBe(false) + }) it('updates amount when hours change', async () => { - const setFieldValueMock = vi.fn() - vi.mocked(useForm).mockReturnValue({ - ...vi.mocked(useForm)(), - setFieldValue: setFieldValueMock, - }) - + wrapper = mount(ContributionForm, { props: defaultProps, global: { @@ -114,9 +150,9 @@ describe('ContributionForm', () => { await wrapper.vm.$nextTick() // Simulate changing hours - wrapper.vm.updateAmount(3) + wrapper.vm.updateField(3, 'hours') - expect(setFieldValueMock).toHaveBeenCalledWith('amount', '60.00') + expect(wrapper.vm.form.amount).toBe('60.00') }) it('emits update-contribution event on submit for existing contribution', async () => { @@ -152,31 +188,4 @@ describe('ContributionForm', () => { expect(wrapper.emitted('set-contribution')).toBeTruthy() }) - - it('resets form on fullFormReset', () => { - const resetFormMock = vi.fn() - vi.mocked(useForm).mockReturnValue({ - ...vi.mocked(useForm)(), - resetForm: resetFormMock, - }) - - wrapper = mount(ContributionForm, { - props: defaultProps, - global: { - stubs: ['BForm', 'BFormInput', 'BRow', 'BCol', 'BButton'], - }, - }) - - wrapper.vm.fullFormReset() - - expect(resetFormMock).toHaveBeenCalledWith({ - values: { - id: null, - date: '', - memo: '', - hours: 0, - amount: '', - }, - }) - }) }) diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index fc96b1706..d879b7676 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -1,7 +1,6 @@ diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 0c71a5407..daa449afd 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -76,8 +76,6 @@ "allContributions": "Es wurden noch keine Beiträge eingereicht.", "myContributions": "Du hast noch keine Beiträge eingereicht." }, - "noDateSelected": "Wähle irgendein Datum im Monat", - "noHours": "Bitte trage deine Stunden ein", "noOpenCreation": { "allMonth": "Für alle beiden Monate ist dein Schöpfungslimit erreicht. Den Nächsten Monat kannst du wieder 1000 GDD Schöpfen.", "lastMonth": "Für den ausgewählten Monat ist das Schöpfungslimit erreicht.", @@ -188,7 +186,7 @@ "validation": { "gddCreationTime": { "min": "Die Stunden sollten mindestens {min} groß sein", - "max": "Die Stunden sollten höchsten {max} groß sein", + "max": "Die Stunden sollten höchstens {max} groß sein", "decimal-places": "Die Stunden sollten maximal zwei Nachkommastellen enthalten" }, "gddSendAmount": "Das Feld {_field_} muss eine Zahl zwischen {min} und {max} mit höchstens zwei Nachkommastellen sein", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 8804c7fe1..4a3ce5a2a 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -76,8 +76,6 @@ "allContributions": "No contributions have been submitted yet.", "myContributions": "You have not submitted any entries yet." }, - "noDateSelected": "Choose any date in the month", - "noHours": "Please enter your hours", "noOpenCreation": { "allMonth": "For all two months your creation limit is reached. The next month you can create 1000 GDD again.", "lastMonth": "The creation limit is reached for the selected month.", @@ -186,7 +184,11 @@ "username": "Username", "username-placeholder": "Choose your username", "validation": { - "gddCreationTime": "The field {_field_} must be a number between {min} and {max} with at most one decimal place.", + "gddCreationTime": { + "min": "The hours should be at least {min} in size", + "max": "The hours should be no larger than {max}", + "decimal-places": "The hours should contain a maximum of two decimal places" + }, "gddSendAmount": "The {_field_} field must be a number between {min} and {max} with at most two digits after the decimal point", "is-not": "You cannot send Gradidos to yourself", "memo": { diff --git a/frontend/src/pages/Community.vue b/frontend/src/pages/Community.vue index 4fc5173b2..c735f35f1 100644 --- a/frontend/src/pages/Community.vue +++ b/frontend/src/pages/Community.vue @@ -90,7 +90,7 @@ const contributionCount = ref(0) const contributionCountAll = ref(0) const form = ref({ id: null, - date: null, + date: undefined, memo: '', hours: '', amount: 20, @@ -115,7 +115,7 @@ const maxForMonths = computed(() => { creation.year === originalDate.getFullYear() && creation.month === originalDate.getMonth() ) { - return parseFloat(creation.amount) + amountToAdd + return parseFloat(creation.amount) + amountToAdd.value } return parseFloat(creation.amount) })