mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Fix date tests
Co-Authored-By: elweyn <heine.hannes@gmail.com>
This commit is contained in:
parent
59f415bd0a
commit
9d5325c199
@ -73,7 +73,7 @@ describe('ContributionForm', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe.only('actual date', () => {
|
||||
describe('actual date', () => {
|
||||
describe('same month', () => {
|
||||
beforeEach(async () => {
|
||||
const now = new Date().toISOString()
|
||||
@ -102,14 +102,22 @@ describe('ContributionForm', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe.skip('date in middle of year', () => {
|
||||
describe('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()
|
||||
// console.log('middle of year date – now:', now)
|
||||
await wrapper.findComponent({ name: 'BFormDatepicker' }).vm.$emit('input', now)
|
||||
// jest.useFakeTimers('modern')
|
||||
// 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', () => {
|
||||
@ -121,10 +129,22 @@ describe('ContributionForm', () => {
|
||||
|
||||
describe('month before', () => {
|
||||
beforeEach(async () => {
|
||||
// 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
|
||||
// .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', () => {
|
||||
@ -135,13 +155,19 @@ describe('ContributionForm', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe.skip('date in january', () => {
|
||||
describe('date in january', () => {
|
||||
describe('same month', () => {
|
||||
beforeEach(async () => {
|
||||
jest.useFakeTimers('modern').setSystemTime(new Date('2020-01-12'))
|
||||
const now = new Date().toISOString()
|
||||
// console.log('in january date – now:', now)
|
||||
await wrapper.findComponent({ name: 'BFormDatepicker' }).vm.$emit('input', now)
|
||||
await wrapper.setData({
|
||||
maximalDate: new Date(2020, 0, 6),
|
||||
form: { date: new Date(2020, 0, 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', () => {
|
||||
@ -153,10 +179,22 @@ describe('ContributionForm', () => {
|
||||
|
||||
describe('month before', () => {
|
||||
beforeEach(async () => {
|
||||
// console.log('in january date – wrapper.vm.minimalDate:', wrapper.vm.minimalDate)
|
||||
await wrapper
|
||||
.findComponent({ name: 'BFormDatepicker' })
|
||||
.vm.$emit('input', wrapper.vm.minimalDate)
|
||||
// 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, 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', () => {
|
||||
|
||||
@ -133,16 +133,9 @@ export default {
|
||||
computed: {
|
||||
minimalDate() {
|
||||
// sets the date to the 1st of the previous month
|
||||
const month = this.maximalDate.getMonth()
|
||||
const year = this.maximalDate.getFullYear()
|
||||
return new Date(year + (month === 0 ? -1 : 0), month === 0 ? 11 : month - 1, 1)
|
||||
|
||||
// // const date = new Date().setMonth(this.maximalDate.getMonth() - 1)
|
||||
// console.log(new Date('Mon Jan 10 2022 16:32:58 GMT+0100'))
|
||||
// const date = new Date('Mon Jan 10 2022 16:32:58 GMT+0100').setMonth(this.maximalDate.getMonth() - 1)
|
||||
// // console.log(date.toISOString())
|
||||
// console.log(new Date(date.getFullYear(), date.getMonth(), 1))
|
||||
// return new Date(date.getFullYear(), date.getMonth(), 1)
|
||||
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)
|
||||
},
|
||||
disabled() {
|
||||
return (
|
||||
@ -157,10 +150,9 @@ export default {
|
||||
},
|
||||
isThisMonth() {
|
||||
const formDate = new Date(this.form.date)
|
||||
const actualDate = new Date()
|
||||
return (
|
||||
formDate.getFullYear() === actualDate.getFullYear() &&
|
||||
formDate.getMonth() === actualDate.getMonth()
|
||||
formDate.getFullYear() === this.maximalDate.getFullYear() &&
|
||||
formDate.getMonth() === this.maximalDate.getMonth()
|
||||
)
|
||||
},
|
||||
maxGddLastMonth() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user