From 89347dde0f5b148e2c0274d698b1d0938f3698a8 Mon Sep 17 00:00:00 2001 From: Josh <44883293+josh-bagwell@users.noreply.github.com> Date: Wed, 27 Nov 2024 10:39:43 -0700 Subject: [PATCH] test: Resolve Cypress Flaky fixes (#3034) Fixes: #2900 This is adding fixes for the Cypress flaky specs that were caused from the [Webpack Upgrade](https://github.com/Workday/canvas-kit/pull/2674). This is addressing Flaky results for Cypress. A test is considered to be flaky when it can pass and fail across multiple retry attempts without any code changes. For example, a test is executed and fails, then the test is executed again, without any change to the code, but this time it passes. See more about Flaky [here](https://docs.cypress.io/cloud/features/flaky-test-management). A Flaky result only happens in the CI and not in local since running Cypress locally only gives `pass` or `fail` results. We had recently switched from E2E tests (end-to-end) to Component tests when upgrading [Storybook](https://github.com/Workday/canvas-kit/pull/2674) and this had created flaky results on some of our components. We think this may be due to the nature of the Component runner as it is so much quicker than E2E. Due to it's nature of being much quicker, it resulted in flaky results due to our components not being to move as quick as the component runner. There may be times where the Component runner would move quicker than an item being focused in a menu or an item switching focus from one item to the next. To address the Flaky issues, there have been updates made to some Component Specs: - Be more explicit with contexts (making sure that each line could be something that a user would do) - Rely on the use of `findByRole()` instead of using `get()`. This allows us to be more specific about what element it is grabbing - Removing deeply nested contexts and moving out to it's own context. This way we are not using more `beforeEach` than is needed and improves legibility. [category:Test] --- .github/workflows/pull-request.yml | 2 +- .github/workflows/scorecard.yml | 2 +- cypress/component/Breadcrumbs.spec.tsx | 328 +++-- cypress/component/Menu.spec.tsx | 63 +- cypress/component/Modal.spec.tsx | 38 +- cypress/component/Popup.spec.tsx | 31 +- cypress/component/SelectPreview.spec.tsx | 1113 +++++++++-------- cypress/component/Tabs.spec.tsx | 6 +- .../stories/examples/Top Label/Alert.tsx | 2 +- .../stories/Breadcrumbs.stories.ts | 1 + .../breadcrumbs/stories/examples/Overflow.tsx | 17 +- modules/react/modal/stories/Modal.stories.ts | 4 + .../modal/stories/examples/IframeTest.tsx | 5 +- .../examples/PopupWithFallbackPlacements.tsx | 155 ++- 14 files changed, 911 insertions(+), 856 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 5289963d65..f304b21554 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -93,7 +93,7 @@ jobs: strategy: fail-fast: false matrix: - containers: [1, 2, 3, 4] + containers: [1, 2, 3, 4, 5] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 79aa48b280..d145c5a1cf 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -10,7 +10,7 @@ on: # To guarantee Maintained check is occasionally updated. See # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained schedule: - - cron: '18 21 * * 4' + - cron: '36 23 * * 1' push: branches: [ "master" ] diff --git a/cypress/component/Breadcrumbs.spec.tsx b/cypress/component/Breadcrumbs.spec.tsx index ce9d3ad57b..1566eadf9c 100644 --- a/cypress/component/Breadcrumbs.spec.tsx +++ b/cypress/component/Breadcrumbs.spec.tsx @@ -2,36 +2,10 @@ import * as React from 'react'; import {Basic} from '../../modules/react/breadcrumbs/stories/examples/Basic'; import {OverflowBreadcrumbs} from '../../modules/react/breadcrumbs/stories/examples/Overflow'; -function getBreadcrumbsNav() { - return cy.findByRole('navigation'); -} - -function getBreadcrumbsList() { - return cy.findByRole('list'); -} - function getAllBreadcrumbsLink(number?: number) { return number ? cy.findAllByRole('link').eq(number) : cy.findAllByRole('link'); } -function getDropdownButton() { - return cy.findByLabelText('More links'); -} - -function getDropdownMenu() { - return cy.findByRole('menu'); -} - -function getDropdownMenuItem(number?: number) { - return number ? cy.findAllByRole('menuitem').eq(number) : cy.findAllByRole('menuitem'); -} - -function openDropdownMenu() { - const dropdownButton = getDropdownButton(); - dropdownButton.focus(); - dropdownButton.realType('{enter}'); -} - describe('Breadcrumbs', () => { context('given the [Components/Navigation/Breadcrumbs, Basic] example is rendered', () => { beforeEach(() => { @@ -43,7 +17,7 @@ describe('Breadcrumbs', () => { }); it('should have an element with a role of "navigation"', () => { - getBreadcrumbsNav().should('be.visible'); + cy.findByRole('navigation').should('be.visible'); }); it('should have an element with a label of "Breadcrumbs"', () => { @@ -51,15 +25,15 @@ describe('Breadcrumbs', () => { }); it('should have a role of "list" on the