fix unit test for "should recognize dates of the month in the past but next month" #1131
No reviewers
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#1131
Loading…
Reference in New Issue
No description provided.
Delete Branch "dpschen/frontend:feature/fix-parsedate-unit-test-for-december"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This fixes the test.
But I'm not sure what the test ist supposed to test?
@ -310,3 +311,3 @@
}
if (date < new Date()) {
if (date < now) {
Using one date for whole function, since time can pass in between
@ -210,2 +210,3 @@
expect(result.date.getDate()).toBe(date.getDate())
expect(result.date.getMonth()).toBe(result.date.getDate() === 31 ? date.getMonth() + 2 : date.getMonth() + 1)
const nextMonthWithDate = result.date.getDate() === 31
The modulo ensures that we always have a month value between 0 and 11.
Not sure if that's the best method or if there are some quirks that would make it better to use date-fns addMonths method instead.
As long as the test passes I'd say it should be fine. We'll see :)
@ -208,7 +208,11 @@ describe('Parse Task Text', () => {
Regarding the line:
(not sure why I'm only able to comment a few lines above my change, but not there anymore)
For me it's not clear what that has to do with the stated goal of the test 'should recognize dates of the month in the past but next month'.
The resulting numer that is used via
date.getDate()
seems to be the index of the day of "yesterday" (since it's started from 0).Why not just start from today?
I the test ran yesterday it should (in the best case) also run today?
The test checks that dates (only the day) that would be in the past (before today) automatically get moved to the next month. Eg if we have the 2nd today and I create a task "do stuff on the 1st" I want the task to be created with a due date of the first but of next month, not this month.
The need for it came from my first naive Implementation where I would create a new date object (which uses today by default) and then only set the day to the one the parser found.
The wording could probably be improved on this one.
Hi dpschen!
Thank you for creating a PR!
I've deployed the changes of this PR on a preview environment under this URL: https://1131-featurefix-parsedate-unit-test-for-december--vikunja-frontend-preview.netlify.app
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!
@ -299,2 +299,3 @@
const date = new Date()
const now = new Date()
const date = new Date(now)
Maybe better to use
new Date(+now)
? Not sure – I didn't do a lot of date related stuff.I think both are fine.