Skip to content

fix: dashboard card courserun association#3365

Open
gumaerc wants to merge 1 commit into
mainfrom
cg/dashboard-always-display-completed-enrollments
Open

fix: dashboard card courserun association#3365
gumaerc wants to merge 1 commit into
mainfrom
cg/dashboard-always-display-completed-enrollments

Conversation

@gumaerc
Copy link
Copy Markdown
Contributor

@gumaerc gumaerc commented May 20, 2026

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/11387

Description (What does it do?)

This fixes a dashboard regression where a learner could appear unenrolled from a course after a newer run supplanted the run they were actually enrolled in.

The dashboard card selection logic was only treating an enrollment as relevant when its run id was still present in the course's current courseruns payload. In the B2B contract case from the linked issue, that meant older enrolled runs could be dropped from the card context once a newer run became the current/default run, which also hid certificate/completion context.

This change updates the legacy dashboard enrollment selection logic to associate enrollments to a course by course id first, with the existing run-id match kept as a fallback. That allows the dashboard to continue surfacing a learner's real enrolled run even when the course payload only lists a newer run.

A regression test was added for the exact failure mode: an older enrolled run should still be selected when the course payload only contains the newer supplanting run.

How can this be tested?

Automated testing:

  • Ran docker compose exec watch yarn test frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/model/dashboardViewModel.test.ts
  • Verified the new regression test passes
  • Confirmed the touched files have no TypeScript diagnostics

Manual testing:

  1. Set up a B2B contract with a course run and a learner attached to the contract.
  2. Enroll the learner in the original contract run and confirm the dashboard shows the course as enrolled.
  3. Create a newer run that supplants the original run.
  4. Reload the dashboard.
  5. Confirm the learner still sees the course as enrolled via their existing run, rather than appearing unenrolled.
  6. If the learner has a passing grade/certificate on the original run, confirm that status still appears on the dashboard after the newer run is created.
  7. Switch back to main and verify that you can reproduce the original bug

Reviewer validation:

  1. Review the update to the dashboard enrollment selection logic in dashboardViewModel.ts.
  2. Review the added regression coverage in dashboardViewModel.test.ts.
  3. Reproduce the B2B scenario above, or rely on the focused unit test that covers the same failure mode.

Copilot AI review requested due to automatic review settings May 20, 2026 21:45
@gumaerc gumaerc added the Needs Review An open Pull Request that is ready for review label May 20, 2026
@github-actions
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).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a dashboard regression where a learner could appear unenrolled (and lose completion/certificate context) after a newer course run supplanted the run they were actually enrolled in, by updating the legacy dashboard enrollment-selection logic to match enrollments to courses by course id (with run-id matching retained as a fallback).

Changes:

  • Add a helper (enrollmentBelongsToCourse) that associates an enrollment to a course by course.id first, falling back to legacy run-id matching.
  • Update pickDisplayedEnrollmentForLegacyDashboard to use the new course-matching helper.
  • Add a regression test covering the “older enrolled run, newer run only in course payload” scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/model/dashboardViewModel.ts Adjusts legacy enrollment-to-course matching to prefer course-id association, avoiding false “unenrolled” display when runs are supplanted.
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/model/dashboardViewModel.test.ts Adds focused regression coverage ensuring older enrolled runs are still selected when the course payload only includes the newer run.

@gumaerc gumaerc changed the title fix run matching fix: dashboard card courserun association May 20, 2026
@zamanafzal zamanafzal self-assigned this May 21, 2026
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