-
Notifications
You must be signed in to change notification settings - Fork 29
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
fix(app-project): test the daily stats chart #6399
fix(app-project): test the daily stats chart #6399
Conversation
6b207a8
to
56cb832
Compare
- test the daily stats chart, on the Classify page. Check that each bar has the expected day and classification count. - fix a bug thrown up by those tests, where the bar date wasn't correctly calculated as UTC. - fix a bug in the mocks, so that the current daily count matches the count for the current day.
56cb832
to
00b63d2
Compare
describe('Component > YourStats > Daily bars', function () { | ||
YourStatsStoreMock.user.personalization.stats.thisWeek.forEach(function (count, i) { | ||
it(`should have an accessible description for ${count.longLabel}`, function () { | ||
const clock = sinon.useFakeTimers(new Date('2019-10-01T19:00:00+06:00')) | ||
const YourStatsStory = composeStory(YourStats, Meta) | ||
render(<YourStatsStory />) | ||
const bar = screen.getByRole('img', { name: count.alt }) | ||
expect(bar).to.exist() | ||
clock.restore() | ||
}) |
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.
This goes into its own block so that the mocked clock doesn't interfere with other tests. For example, if you put the mocked clock into a before
block, it stops the animation in the project stats container tests, causing them to hang.
There might be some GitHub actions running for ~6 hours as a result of that.
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.
I've chosen a mocked time where the day name/number in the local clock is different from the day name/number in UTC, in order to try and trigger #2244. The local day is Tuesday 1 October but the UTC day is Wednesday 2 October. The rendered classification count should be shown for Tuesday.
@@ -14,7 +14,9 @@ function DailyClassificationsChartContainer({ | |||
}) { | |||
const TODAY = new Date() | |||
const stats = thisWeek.map(({ count: statsCount, period }) => { | |||
const day = new Date(period) |
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.
This gives the wrong day when the date is a single digit, I think because a date like 2019-10-2
isn't a valid ISO date (it should be 2019-10-02
.) Breaking the date into parts, then constructing a UTC date from year, month index, and date, seems to work better.
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.
Thanks!
I went further with this refactor and removed .defaultProps()
from YourStats and the unused, legacy mockStore
from YourStatsContainer.
I also noticed during review the YourStats component still displays "total" from |
Please request review from
@zooniverse/frontend
team or an individual member of that team.Package
Linked Issue and/or Talk Post
How to Review
This started out as replacing some tests that were removed in #5210, but those tests failed, because of bugs in the
YourStats
component. So this now:To properly test this, you should look at a project that you've classified on in the last week, preferably on more than one day, and check that the daily classification counts are assigned to the correct day.
Checklist
PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.
General
yarn panic && yarn bootstrap
ordocker-compose up --build
and FEM works as expectedGeneral UX
Example Staging Project: i-fancy-cats
Bug Fix