Skip to content

fix: Flaky JS test: ProgramAsCoursePage 'Enroll CTA posts program enrollment' times out on Loading button - #3672

Merged
ahtesham-quraish merged 2 commits into
mainfrom
ahtesham/flaky-test-fix
Jul 27, 2026
Merged

fix: Flaky JS test: ProgramAsCoursePage 'Enroll CTA posts program enrollment' times out on Loading button#3672
ahtesham-quraish merged 2 commits into
mainfrom
ahtesham/flaky-test-fix

Conversation

@ahtesham-quraish

@ahtesham-quraish ahtesham-quraish commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

https://github.com/mitodl/hq/issues/12456

Problem

Enroll CTA posts program enrollment intermittently failed in CI with
Unable to find role="button" and name "Start Learning" — the button was still
in its loading state (aria-label="Loading"). Re-running passed: a timing flake.

Root cause

The "Start Learning" button is gated by isStatusLoading, which stays true
until the program-enrollment status query (GET /api/v3/program_enrollments/)
resolves — until then the button has no "Start Learning" name. findAllByRole
only retries for Testing Library's default ~1s, so under CI load the query
sometimes hadn't resolved in time.

Fix

Added a shared ENROLL_STATUS_TIMEOUT constant and passed it as the waitFor
timeout on the three findAllByRole("Start Learning") call sites, so they retry
until the button leaves its loading state. No overhead on the fast path.

Also pinned show_stay_updated: true in the "Shows Stay Updated button" test —
the factory now emits a random value, making that assertion ~50% flaky (matches
the CoursePage/ProgramPage updates).

Testing

Reproduced the flake locally (delayed status query) and confirmed the fix;
all ProgramAsCoursePage.test.tsx tests pass.

Copilot AI review requested due to automatic review settings July 24, 2026 09:44
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

OpenAPI Changes

No changes detected

View full changelog

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a flaky frontend test in the Next.js main workspace where the “Start Learning” enroll CTA can remain in a transient “Loading” accessible state long enough to exceed Testing Library’s default async timeout under CI load.

Changes:

  • Adds a dedicated ENROLL_STATUS_TIMEOUT constant to give enrollment-status-driven UI more time to settle in tests.
  • Updates three screen.findAllByRole("button", { name: "Start Learning" }) calls to use the extended timeout, reducing timing-related failures.

@ahtesham-quraish ahtesham-quraish added the Needs Review An open Pull Request that is ready for review label Jul 24, 2026
@gumaerc gumaerc self-assigned this Jul 24, 2026

@gumaerc gumaerc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This looks good and solves the problem by adding extra timeout, which is fine. You may want to update the PR description before merging, it looks like there's some stale comments in there?

Also pinned show_stay_updated: true in the "Shows Stay Updated button" test —
the factory now emits a random value, making that assertion ~50% flaky (matches
the CoursePage/ProgramPage updates).

})
const makePage = factories.pages.programPageItem

// The enroll button renders with aria-label="Loading" (and no "Start Learning"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment could be made more concise, all that really needs to be said is that enrollment tests take more time and we need to wait for them.

@ahtesham-quraish
ahtesham-quraish force-pushed the ahtesham/flaky-test-fix branch from efae35a to c28f039 Compare July 27, 2026 07:17
@ahtesham-quraish
ahtesham-quraish merged commit 63f1a8a into main Jul 27, 2026
13 checks passed
@ahtesham-quraish
ahtesham-quraish deleted the ahtesham/flaky-test-fix branch July 27, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review An open Pull Request that is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants