Skip to content
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

Merged
merged 4 commits into from
Jan 10, 2024

Conversation

julio-lopez
Copy link
Contributor

@julio-lopez julio-lopez commented Nov 21, 2023

Adds a stable test for the elapsed template function.

@julio-lopez
Copy link
Contributor Author

@mickael-menu PTAL when you have a chance. Thank you!

@julio-lopez julio-lopez force-pushed the fix/test-template-elapsed-date branch from a3de276 to 92245d0 Compare January 5, 2024 06:49
@julio-lopez julio-lopez changed the title fix(test): update unstable TestFormatDateHelper test: add TestFormatDateHelperElapsed Jan 5, 2024
@tjex
Copy link
Member

tjex commented Jan 5, 2024

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
Copy link
Contributor Author

@tjex The original PR had a "temporary" fix for the failing test. The fix in #374 is more robust.

This PR adds separate stable tests for other relative time units. It may be a good idea to have this test as well, but feel free to discard it if it does not add value.

@tjex
Copy link
Member

tjex commented Jan 6, 2024

@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 TestFormatDateHelperElapsed for better context.

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",
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@zalegrala zalegrala Jan 9, 2024

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Member

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)

@julio-lopez julio-lopez force-pushed the fix/test-template-elapsed-date branch from 92245d0 to b13e027 Compare January 8, 2024 23:12
@julio-lopez
Copy link
Contributor Author

julio-lopez commented Jan 8, 2024

@tjex Thanks for the feedback.

@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)

I added and modified the tests as you suggested.

Also refactored the test addition from #374 into the TestFormatDateHelperElapsed for better context.

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 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.

Merging the main branch in the PR would have worked as well. Anyway, rebased the PR on top of main with the changes you suggested in separate commits to simplify reviewing.

PTAL. Thanks.

@julio-lopez julio-lopez force-pushed the fix/test-template-elapsed-date branch from b13e027 to dd91eca Compare January 8, 2024 23:28
@julio-lopez
Copy link
Contributor Author

@tjex Anything else that needs to be changed in order to merge this test? Thanks.

Copy link
Member

@tjex tjex left a 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

@tjex tjex merged commit 5a2333d into zk-org:main Jan 10, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants