Skip to content

[EuiContextMenuPanel] Convert flakey Jest focus/keyboard tests to Cypress#5261

Merged
cee-chen merged 1 commit intoelastic:masterfrom
cee-chen:cypress-flaky-focus-test
Oct 14, 2021
Merged

[EuiContextMenuPanel] Convert flakey Jest focus/keyboard tests to Cypress#5261
cee-chen merged 1 commit intoelastic:masterfrom
cee-chen:cypress-flaky-focus-test

Conversation

@cee-chen
Copy link
Copy Markdown
Contributor

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.

screencap

QA

  • checkout this branch
  • run yarn test-cypress-dev
  • Click on context_menu_panel.spec.tsx
  • Confirm all tests pass when rerunning (hit refresh button to re-run) multiple times

NB: I did initially encounter intermittent failures with the down arrow key focuses the first menu item and subsequently, down arrow key focuses the next menu item tests. Adding a cy.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

@cee-chen cee-chen added skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) tech debt labels Oct 12, 2021
Copy link
Copy Markdown
Contributor Author

@cee-chen cee-chen left a 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>
Copy link
Copy Markdown
Contributor Author

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', () => {
Copy link
Copy Markdown
Contributor Author

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;
Copy link
Copy Markdown
Contributor Author

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

Comment on lines -383 to -391
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
);
});
Copy link
Copy Markdown
Contributor Author

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 🤷‍♀️

@kibanamachine
Copy link
Copy Markdown

Preview documentation changes for this PR: https://eui.elastic.co/pr_5261/

Copy link
Copy Markdown
Contributor

@thompsongl thompsongl left a 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

@cee-chen
Copy link
Copy Markdown
Contributor Author

Wahoo! Thanks Greg!

@cee-chen cee-chen merged commit 6cb6bf0 into elastic:master Oct 14, 2021
@cee-chen cee-chen deleted the cypress-flaky-focus-test branch October 14, 2021 19:39
ym pushed a commit to ym/eui that referenced this pull request Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) tech debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants