-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
UI: Fix flaky time-related tests #19521
Conversation
await click('[data-test-previous-year]'); | ||
} | ||
await click(find(`[data-test-calendar-month=${ARRAY_OF_MONTHS[customEndDate.getMonth()]}]`)); | ||
await click('[data-test-previous-year]'); |
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.
so much nicer 🥲
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.
Nice work on this so far! Thank you for tackling this cleanup work! Looking forward to less flaky tests 😍
UPGRADE_DATE, | ||
'MMM d, yyyy' | ||
)}. We added monthly breakdowns and mount level attribution starting in 1.10, so keep that in mind when looking at the data. Learn more here.` | ||
`Warning Vault was upgraded to 1.10.1 on Aug 1, 2022. We added monthly breakdowns and mount level attribution starting in 1.10, so keep that in mind when looking at the data. Learn more here.` | ||
); | ||
}); | ||
|
||
test('Shows empty if license start date is current month', async function (assert) { | ||
// TODO cmb update to reflect new behavior |
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.
@hellobontempo is this TODO still relevant? The tests seem to pass but I'm not sure if this meant to check more things?
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.
Oish yeah. I noticed this on my last passthrough and wondered the same thing 😅
Among the miscellany of other bugs, I don't think I ever got an answer from the backend on what the expected response in this case (or perhaps forgot to ask). Previously data wasn't available for a customer until the first completed month, but that should no longer be the case.
This test can be deleted! But a good reminder of something that should be taken into account for the latest backend work on activity log testing
await render(hbs`{{date-format this.timestampDate 'MMM d yyyy, h:mm:ss aaa' withTimeZone=true}}`); | ||
assert.dom(this.element).hasTextContaining(`${zone}`); | ||
await render( | ||
hbs`<span data-test-formatted>{{date-format this.timestampDate 'MMM d yyyy, h:mm:ss aaa' withTimeZone=this.withTimezone}}</span>` |
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.
Might have just been due to running this test locally, but I found that it was expecting "CST" and giving "CDT" (in tests run on main as well). Since the time just switched, I figured testing it this way (making sure there's the expected number of characters) ensures that daylight savings doesn't ruin this test in the future. Other suggestions welcome
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 think this makes sense!
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.
So great to see these changes. Thank you for going after this. Quick question, do you think some kind of comment like you have in the PR description can be added to the pattern doc, with a link to this PR?
Absolutely! Great idea, thanks for the review |
✨ Cleanup Date usage ✨
This has caused headaches during testing, because the value of
new Date()
constantly changes due to the nature of time. With these changes, we no longer callnew Date()
within the application, and instead call a utilitytimestamp.now()
. Under the hood, timestamp.now just returnsnew Date()
, but it can be easily stubbed within tests to make the concept of "now" within tests is consistent and much easier to test.Another change made as part of this PR is replacing all instances of
new Date()
within tests (when used to generate a UID for engine and secret paths) withuuidv4
which was added as part of 1.13.NOT part of these changes is swapping out
Date.now
throughout the codebase. This change is large enough as is, and we can revisit swapping that out at a later timeHow to review this
Obviously a lot of files were changed, but most of the changes are fairly simple swaps. I recommend reviewing the code commit by commit, to see similar changes grouped together and larger refactors separated into their own commit. EDIT things got sort of messy at the end there, trying to sort through test failures. Most of the files have 2-3 lines changed, so hopefully it's not too bad 😬
TL;DR How to test components that use time
Let's say you have a component that receives some timestamp from an API, and then renders something different depending on if the timestamp is in the past, future, close, far away, etc. Within the component, we would use
timestamp.now()
for the current time for comparison rather thannew Date()
.Then, the test might look something like this:
If you want the value of
now
to change depending on the test, you could stub within the test. Note that if you do it this way but calltimestamp.now
in thebeforeEach
hook, the value oftimestamp.now
will not be stubbed at that point, and will give you the actual current time.