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

Fix KDateRange failing tests on prs opened on last day of the month #718

Merged

Conversation

LianaHarris360
Copy link
Member

@LianaHarris360 LianaHarris360 commented Aug 9, 2024

Description

This pull request fixes the failing KDateCalendar component tests that would occur on open pull requests on the last day of the month. This was fixed by setting dates manually in the tests. The KDateCalendar has also been updated to display the month of the property lastAllowedDate.

Issue addressed

Addresses #713

Changelog

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical and brittle code paths are covered by unit tests
  • The change is described in the changelog section above

Reviewer guidance

  • Is the code clean and well-commented?
  • Are there tests for this change?
  • Are all UI components LTR and RTL compliant (if applicable)?
  • Add other things to check for here

After review

  • The changelog item has been pasted to the CHANGELOG.md

Comments

@@ -157,8 +157,9 @@
},
numOfDays: 7,
isFirstChoice: this.selectedStartDate == null ? true : false,
activeMonth: new Date().getMonth() - 1 == -1 ? 11 : new Date().getMonth() - 1,
activeYearStart: new Date().getFullYear(),
activeMonth:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to know why 1 is subtracted from the active month. It means that the activeMonth will always be the month before the lastAllowedDate right? But if we are in January, the previous month would cause the year to also have to be reduced, but I see that activeYearStart is taken only from getFullYear.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because of how the Date() constructor in JavaScript sets the months. It uses an integer value to represent the month, beginning with 0 for January to 11 for December.

Copy link
Member

@AlexVelezLl AlexVelezLl Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, I meant what if the lastAllowedDate was for example new Date(2024, 0, 1), then activeMonth would be 11, but activeYearStart would be 2024, so the active date would be December 2024 instead of December 2023. But I looked at the code and I see that this activeYearStart value is updated in the created hook if this happens, so there is no problem.

Anyways I think we could avoid the ternary here, and the check in the created hook if we do something similar to get the previous month:

    data() {
      const previousMonth = new Date(this.lastAllowedDate);
      previousMonth.setMonth(lastAllowedDate.getMonth() - 1);
      return {
        ...,
        activeMonth: previousMonth.getMonth(),
        activeYearStart: previousMonth.getFullYear(),
      };
    },

But it is totally optional, although I think it would clarify the intention that activeMonth and activeYearStart refer to the previous month of the lastAllowedDate.

Update how KDatecalendar test case prop previousMonth is set

Co-authored-by: Alex Velez <[email protected]>
Copy link
Member

@AlexVelezLl AlexVelezLl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! And code seems to be working even if lastAllowedDate is the last day of the month.

@LianaHarris360 LianaHarris360 merged commit ce9e707 into learningequality:develop Aug 13, 2024
8 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.

KDateRange test failures: KDateRange test failure impacting month-end pull requests
2 participants