From 6d38b9a23278c8dc807659ae2b8092fb2fc302a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Mon, 8 Aug 2022 14:43:03 +0200 Subject: [PATCH] Add date test that didn't work unfortunately for now and be skipped --- .../Contributions/ContributionForm.spec.js | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/frontend/src/components/Contributions/ContributionForm.spec.js b/frontend/src/components/Contributions/ContributionForm.spec.js index 6d6f2164b..1cb2b3e8a 100644 --- a/frontend/src/components/Contributions/ContributionForm.spec.js +++ b/frontend/src/components/Contributions/ContributionForm.spec.js @@ -61,6 +61,117 @@ describe('ContributionForm', () => { }) }) + describe('dates', () => { + beforeEach(async () => { + await wrapper.setData({ + form: { + id: null, + date: '', + memo: '', + amount: '', + }, + }) + }) + + describe('actual date', () => { + describe('same month', () => { + beforeEach(async () => { + const now = new Date().toISOString() + await wrapper.findComponent({ name: 'BFormDatepicker' }).vm.$emit('input', now) + }) + + describe('isThisMonth', () => { + it('has true', () => { + expect(wrapper.vm.isThisMonth).toBe(true) + }) + }) + }) + + describe('month before', () => { + beforeEach(async () => { + await wrapper + .findComponent({ name: 'BFormDatepicker' }) + .vm.$emit('input', wrapper.vm.minimalDate) + }) + + describe('isThisMonth', () => { + it('has false', () => { + expect(wrapper.vm.isThisMonth).toBe(false) + }) + }) + }) + }) + + // jest-environment-jsdom-sixteen + // testEnvironment: 'jest-environment-jsdom-sixteen', + // https://www.npmjs.com/package/jest-environment-jsdom-sixteen + // https://dev.to/philw_/problems-with-using-usefaketimersmodern-in-a-create-react-app-cra-project-with-jest-26-and-lodashs-debounce-function-3ohd + describe.skip('date in middle of year', () => { + describe('same month', () => { + beforeEach(async () => { + jest.useFakeTimers('modern') + jest.setSystemTime(new Date('2020-07-06')) + const now = new Date().toISOString() + // Wolle: console.log('middle of year date – now:', now) + await wrapper.findComponent({ name: 'BFormDatepicker' }).vm.$emit('input', now) + }) + + describe('isThisMonth', () => { + it('has true', () => { + expect(wrapper.vm.isThisMonth).toBe(true) + }) + }) + }) + + describe('month before', () => { + beforeEach(async () => { + // Wolle: console.log('middle of year date – now:', wrapper.vm.minimalDate) + await wrapper + .findComponent({ name: 'BFormDatepicker' }) + .vm.$emit('input', wrapper.vm.minimalDate) + }) + + describe('isThisMonth', () => { + it('has false', () => { + expect(wrapper.vm.isThisMonth).toBe(false) + }) + }) + }) + }) + + describe.skip('date in january', () => { + describe('same month', () => { + beforeEach(async () => { + jest.useFakeTimers('modern').setSystemTime(new Date('2020-01-12')) + const now = new Date().toISOString() + // Wolle: console.log('in january date – now:', now) + await wrapper.findComponent({ name: 'BFormDatepicker' }).vm.$emit('input', now) + }) + + describe('isThisMonth', () => { + it('has true', () => { + expect(wrapper.vm.isThisMonth).toBe(true) + }) + }) + }) + + describe('month before', () => { + beforeEach(async () => { + // Wolle: console.log('in january date – wrapper.vm.minimalDate:', wrapper.vm.minimalDate) + await wrapper + .findComponent({ name: 'BFormDatepicker' }) + .vm.$emit('input', wrapper.vm.minimalDate) + }) + + describe('isThisMonth', () => { + it('has false', () => { + expect(wrapper.vm.isThisMonth).toBe(false) + }) + }) + }) + }) + }) + describe('set contrubtion', () => { describe('fill in form data with "id === null"', () => { const now = new Date().toISOString()