-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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: update notification date tests to be timezone agnostic #27925
Merged
Prithpal-Sooriya
merged 4 commits into
develop
from
test/update-notification-date-tests-to-be-timezone-agnostic
Oct 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f52f2a8
test: update notification date tests to be timezone agnostic
Prithpal-Sooriya 2061144
Merge branch 'develop' into test/update-notification-date-tests-to-be…
Prithpal-Sooriya 6c9990d
Merge branch 'develop' into test/update-notification-date-tests-to-be…
Prithpal-Sooriya 2318281
Merge branch 'develop' into test/update-notification-date-tests-to-be…
Prithpal-Sooriya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
describe('formatMenuItemDate', () => { | ||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
jest.setSystemTime(new Date('2024-06-07T09:40:00Z')); | ||
jest.setSystemTime(new Date(Date.UTC(2024, 5, 7, 9, 40, 0))); // 2024-06-07T09:40:00Z | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main culprit. We were setting the system time to a TZ specific date. We have now changed this to a UTC (timezone agnostic) date. Hopefully this resolves issues that devs may face when running this test locally. |
||
}); | ||
|
||
afterAll(() => { | ||
|
@@ -28,7 +28,7 @@ describe('formatMenuItemDate', () => { | |
|
||
// assert 1 hour ago | ||
assertToday((testDate) => { | ||
testDate.setHours(testDate.getHours() - 1); | ||
testDate.setUTCHours(testDate.getUTCHours() - 1); | ||
return testDate; | ||
}); | ||
}); | ||
|
@@ -42,14 +42,14 @@ describe('formatMenuItemDate', () => { | |
|
||
// assert exactly 1 day ago | ||
assertYesterday((testDate) => { | ||
testDate.setDate(testDate.getDate() - 1); | ||
testDate.setUTCDate(testDate.getUTCDate() - 1); | ||
}); | ||
|
||
// assert almost a day ago, but was still yesterday | ||
// E.g. if Today way 09:40AM, but date to test was 23 hours ago (yesterday at 10:40AM), we still want to to show yesterday | ||
assertYesterday((testDate) => { | ||
testDate.setDate(testDate.getDate() - 1); | ||
testDate.setHours(testDate.getHours() + 1); | ||
testDate.setUTCDate(testDate.getUTCDate() - 1); | ||
testDate.setUTCHours(testDate.getUTCHours() + 1); | ||
}); | ||
}); | ||
|
||
|
@@ -62,18 +62,18 @@ describe('formatMenuItemDate', () => { | |
|
||
// assert exactly 1 month ago | ||
assertMonthsAgo((testDate) => { | ||
testDate.setMonth(testDate.getMonth() - 1); | ||
testDate.setUTCMonth(testDate.getUTCMonth() - 1); | ||
}); | ||
|
||
// assert 2 months ago | ||
assertMonthsAgo((testDate) => { | ||
testDate.setMonth(testDate.getMonth() - 2); | ||
testDate.setUTCMonth(testDate.getUTCMonth() - 2); | ||
}); | ||
|
||
// assert almost a month ago (where it is a new month, but not 30 days) | ||
assertMonthsAgo(() => { | ||
// jest mock date is set in july, so we will test with month may | ||
return new Date('2024-05-20T09:40:00Z'); | ||
return new Date(Date.UTC(2024, 4, 20, 9, 40, 0)); // 2024-05-20T09:40:00Z | ||
}); | ||
}); | ||
|
||
|
@@ -86,18 +86,18 @@ describe('formatMenuItemDate', () => { | |
|
||
// assert exactly 1 year ago | ||
assertYearsAgo((testDate) => { | ||
testDate.setFullYear(testDate.getFullYear() - 1); | ||
testDate.setUTCFullYear(testDate.getUTCFullYear() - 1); | ||
}); | ||
|
||
// assert 2 years ago | ||
assertYearsAgo((testDate) => { | ||
testDate.setFullYear(testDate.getFullYear() - 2); | ||
testDate.setUTCFullYear(testDate.getUTCFullYear() - 2); | ||
}); | ||
|
||
// assert almost a year ago (where it is a new year, but not 365 days ago) | ||
assertYearsAgo(() => { | ||
// jest mock date is set in 2024, so we will test with year 2023 | ||
return new Date('2023-11-20T09:40:00Z'); | ||
return new Date(Date.UTC(2023, 10, 20, 9, 40, 0)); // 2023-11-20T09:40:00Z | ||
}); | ||
}); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Unsure if this actually has an impact in tests. Can I get other devs to test with/without this environment var?
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 will keep this in the test environment for now. It does not impact any other tests.
Leaving a comment here for future devs: This can be taken out if necessary 😄