From 208cb30274f6403ffd70d68cc360c0d959311111 Mon Sep 17 00:00:00 2001 From: ogerly Date: Mon, 31 Oct 2022 15:03:19 +0100 Subject: [PATCH 1/2] the last and current month is displayed cleanly again. --- .../Contributions/ContributionForm.spec.js | 16 ++++++++-------- .../Contributions/ContributionForm.vue | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/Contributions/ContributionForm.spec.js b/frontend/src/components/Contributions/ContributionForm.spec.js index 8f35948f9..e85a94884 100644 --- a/frontend/src/components/Contributions/ContributionForm.spec.js +++ b/frontend/src/components/Contributions/ContributionForm.spec.js @@ -109,8 +109,8 @@ describe('ContributionForm', () => { }) describe('minimalDate', () => { - it('has "2020-06-01T00:00:00.000Z"', () => { - expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-06-01T00:00:00.000Z') + it('has "2020-05-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-05-01T00:00:00.000Z') }) }) @@ -136,8 +136,8 @@ describe('ContributionForm', () => { }) describe('minimalDate', () => { - it('has "2020-06-01T00:00:00.000Z"', () => { - expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-06-01T00:00:00.000Z') + it('has "2020-05-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-05-01T00:00:00.000Z') }) }) @@ -159,8 +159,8 @@ describe('ContributionForm', () => { }) describe('minimalDate', () => { - it('has "2019-12-01T00:00:00.000Z"', () => { - expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-12-01T00:00:00.000Z') + it('has "2019-11-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-11-01T00:00:00.000Z') }) }) @@ -186,8 +186,8 @@ describe('ContributionForm', () => { }) describe('minimalDate', () => { - it('has "2019-12-01T00:00:00.000Z"', () => { - expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-12-01T00:00:00.000Z') + it('has "2019-11-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-11-01T00:00:00.000Z') }) }) diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index 71593f2b1..bb8a1902f 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -134,7 +134,7 @@ export default { // sets the date to the 1st of the previous month let date = new Date(this.maximalDate) // has to be a new object, because of 'setMonth' changes the objects date date = new Date(date.setMonth(date.getMonth() - 1)) - return new Date(date.getFullYear(), date.getMonth(), 1) + return new Date(date.getFullYear(), date.getMonth() - 1) }, disabled() { return ( From 6c8d9966491bef65cd65c497ff7dd1b3fe7402df Mon Sep 17 00:00:00 2001 From: ogerly Date: Tue, 1 Nov 2022 11:24:50 +0100 Subject: [PATCH 2/2] more tests, 31st, 28st, 29.02.2024 --- .../Contributions/ContributionForm.spec.js | 85 +++++++++++++++++-- .../Contributions/ContributionForm.vue | 6 +- 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/Contributions/ContributionForm.spec.js b/frontend/src/components/Contributions/ContributionForm.spec.js index e85a94884..3af716d36 100644 --- a/frontend/src/components/Contributions/ContributionForm.spec.js +++ b/frontend/src/components/Contributions/ContributionForm.spec.js @@ -109,8 +109,8 @@ describe('ContributionForm', () => { }) describe('minimalDate', () => { - it('has "2020-05-01T00:00:00.000Z"', () => { - expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-05-01T00:00:00.000Z') + it('has "2020-06-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-06-01T00:00:00.000Z') }) }) @@ -136,8 +136,8 @@ describe('ContributionForm', () => { }) describe('minimalDate', () => { - it('has "2020-05-01T00:00:00.000Z"', () => { - expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-05-01T00:00:00.000Z') + it('has "2020-06-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2020-06-01T00:00:00.000Z') }) }) @@ -159,8 +159,8 @@ describe('ContributionForm', () => { }) describe('minimalDate', () => { - it('has "2019-11-01T00:00:00.000Z"', () => { - expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-11-01T00:00:00.000Z') + it('has "2019-12-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-12-01T00:00:00.000Z') }) }) @@ -186,8 +186,8 @@ describe('ContributionForm', () => { }) describe('minimalDate', () => { - it('has "2019-11-01T00:00:00.000Z"', () => { - expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-11-01T00:00:00.000Z') + it('has "2019-12-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2019-12-01T00:00:00.000Z') }) }) @@ -198,6 +198,75 @@ describe('ContributionForm', () => { }) }) }) + + describe('date with the 31st day of the month', () => { + describe('same month', () => { + beforeEach(async () => { + await wrapper.setData({ + maximalDate: new Date('2022-10-31T00:00:00.000Z'), + form: { date: new Date('2022-10-31T00:00:00.000Z') }, + }) + }) + + describe('minimalDate', () => { + it('has "2022-09-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2022-09-01T00:00:00.000Z') + }) + }) + + describe('isThisMonth', () => { + it('has true', () => { + expect(wrapper.vm.isThisMonth).toBe(true) + }) + }) + }) + }) + + describe('date with the 28th day of the month', () => { + describe('same month', () => { + beforeEach(async () => { + await wrapper.setData({ + maximalDate: new Date('2023-02-28T00:00:00.000Z'), + form: { date: new Date('2023-02-28T00:00:00.000Z') }, + }) + }) + + describe('minimalDate', () => { + it('has "2023-01-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2023-01-01T00:00:00.000Z') + }) + }) + + describe('isThisMonth', () => { + it('has true', () => { + expect(wrapper.vm.isThisMonth).toBe(true) + }) + }) + }) + }) + + describe('date with 29.02.2024 leap year', () => { + describe('same month', () => { + beforeEach(async () => { + await wrapper.setData({ + maximalDate: new Date('2024-02-29T00:00:00.000Z'), + form: { date: new Date('2024-02-29T00:00:00.000Z') }, + }) + }) + + describe('minimalDate', () => { + it('has "2024-01-01T00:00:00.000Z"', () => { + expect(wrapper.vm.minimalDate.toISOString()).toBe('2024-01-01T00:00:00.000Z') + }) + }) + + describe('isThisMonth', () => { + it('has true', () => { + expect(wrapper.vm.isThisMonth).toBe(true) + }) + }) + }) + }) }) describe('set contrubtion', () => { diff --git a/frontend/src/components/Contributions/ContributionForm.vue b/frontend/src/components/Contributions/ContributionForm.vue index bb8a1902f..3884fd5b4 100644 --- a/frontend/src/components/Contributions/ContributionForm.vue +++ b/frontend/src/components/Contributions/ContributionForm.vue @@ -131,10 +131,8 @@ export default { }, computed: { minimalDate() { - // sets the date to the 1st of the previous month - let date = new Date(this.maximalDate) // has to be a new object, because of 'setMonth' changes the objects date - date = new Date(date.setMonth(date.getMonth() - 1)) - return new Date(date.getFullYear(), date.getMonth() - 1) + const date = new Date(this.maximalDate) + return new Date(date.setMonth(date.getMonth() - 1, 1)) }, disabled() { return (