-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add TestFormatDateHelperElapsed #359
Conversation
@mickael-menu PTAL when you have a chance. Thank you! |
a3de276
to
92245d0
Compare
hey @julio-lopez this test fix got addressed in #374. It all happened in a hurry and your contribution must've just been overlooked as your (this) initial PR is now a few months old. Our bad! #374 only addressed an elapsed time of a year, and yours is hours/minutes/seconds. I'm not sure how robust that test needs to be, but perhaps if the change from #374 does need to be extended, it might be more safe to make one singular case for elapsed: year, day, hour, minute, second. So as to cover all time bases. |
@julio-lopez makes sense. I pad a pr to your branch with some extra tidying and focussed your tests on edge cases (ticking over from one elapsed time measure to the next) Also refactored the test addition from #374 into the Merging my branch, should also update this PR with the current state of zk-org/zk/main as there have been some other changes there since your commits. |
}, | ||
{ | ||
elapsed: 7 * 24 * time.Hour, | ||
want: "1 week ago", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add one please that includes "last week", which I think should also work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zalegrala Can you provide the test case please? FWICT, the result for < 7 days is the number of days, for 7 days is 1 week ago, and for >7 days it is 2 weeks.
I added the case for 2 weeks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
elapsed: 7 * 24 * time.Hour,
want: "last week",
},
I believe this should pass without code changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is that specific test case, and it produces "1 week ago"
.
What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh maybe I misunderstand. I thought the underlying library that was doing the transformation from string to date is what is being tested here. Feel free to proceed if the test case I mentioned above doesn't add additional coverage. The last week
text is what is being used in some of my templates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's actually the other way around. The library is calculating the elapsed time and then returning a string.
We're just testing that each possible span of elapsed time, returns the correct string (i.e., elapsed time in natural language)
92245d0
to
b13e027
Compare
@tjex Thanks for the feedback.
I added and modified the tests as you suggested.
Factored it out in a separate test. In general, it'd make sense to keep the changes self contained, although, in this case these two changes are highly related.
Merging the PTAL. Thanks. |
b13e027
to
dd91eca
Compare
@tjex Anything else that needs to be changed in order to merge this test? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks great :) Thanks very much @julio-lopez
Adds a stable test for the
elapsed
template function.