-
Notifications
You must be signed in to change notification settings - Fork 843
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
[EuiContextMenuPanel] Convert flakey Jest focus/keyboard tests to Cypress #5261
Conversation
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.
Hey y'all! After some evaluation I decided to split my Jest->Cypress flaky test work into a separate PR from my Jest+Cypress code coverage work. Hopefully this should be easier to follow along.
In case you're curious, I went ahead and did the coverage %s on this change in #5262 - it went up a little from converting to Cypress! 😄
it('is set on the first focusable element by default if there are no items and hasFocus is true', () => { | ||
mount( | ||
<EuiContextMenuPanel> | ||
<button data-test-subj="button">Hello world</button> |
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 added Hello world
text here to make the button focus more obvious in the Cypress browser real-time preview
cy.wait(100); // Intermittent flake workaround: without this, the first downarrow key does not always focus into the menu items as expected | ||
}); | ||
|
||
it('focuses the panel by default', () => { |
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.
FUN FACT: Did you know that if you blindly copy/paste Jest tests into Cypress and don't remove the async
from it('focuses the panel by default', async () => {
, you will get a bunch of indecipherable warnings and all your tests will pass on group run even when they shouldn't? 🤦♀️ ☠️
Posting this so others hopefully don't make the same mistake as me in the future lol
.type('{downarrow}') | ||
.type('{leftarrow}') | ||
.then(() => { | ||
expect(showPreviousPanelHandler).to.be.called; |
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.
NB: expect
gets called immediately where as cy.
commands are async promises, so we have to put the stub expect in a then
chain for the test to pass as expected
it('up arrow key wraps to last menu item', async () => { | ||
component.simulate('keydown', { key: keys.ARROW_DOWN }); | ||
component.simulate('keydown', { key: keys.ARROW_UP }); | ||
|
||
await tick(20); | ||
expect(findTestSubject(component, 'itemC').getDOMNode()).toBe( | ||
document.activeElement | ||
); | ||
}); |
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 test felt redundant to me with lines 364-371 so I removed it in favor of just one test 🤷♀️
Preview documentation changes for this PR: https://eui.elastic.co/pr_5261/ |
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.
LGTM! So great to have this option now.
Ran the tests a few times locally with no flakiness
Wahoo! Thanks Greg! |
Summary
I brought up recently in Slack that I was seeing intermittent failures from
EuiContextMenuPanel
's focus/keyboard behavior tests. I saw them again last week on a random PR and got annoyed enough to convert them to Cypress, which should (fingers crossed) have fewer flaking issues with focus behavior.QA
yarn test-cypress-dev
context_menu_panel.spec.tsx
NB: I did initially encounter intermittent failures with the
down arrow key focuses the first menu item
andsubsequently, down arrow key focuses the next menu item
tests. Adding acy.wait()
of 100 milliseconds seemed to fix those intermittent failures. I reran approx tests 10x locally with no intermittent failures after that, although only the CI gods will know after this if we still get flakes 😅Checklist
No changelog, internal/dev only change