Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
56d688b
feat: display child programs in program requirement sections
ChristopherChudzicki Mar 16, 2026
e21413c
refactor: extract getIdsFromReqTree, remove duplicated helpers, fix t…
ChristopherChudzicki Mar 16, 2026
fb47cd7
feat: add price and certificate display to MitxOnlineProgramCard
ChristopherChudzicki Mar 17, 2026
33979b1
fix: use correct price sources for course and program cards
ChristopherChudzicki Mar 17, 2026
d0af82c
refactor: get course price from next run's product directly
ChristopherChudzicki Mar 17, 2026
5814b5d
fix: use enrollment type to determine price display on cards
ChristopherChudzicki Mar 17, 2026
92f2fba
refactor: unify MitxOnlineCourseCard and MitxOnlineProgramCard
ChristopherChudzicki Mar 17, 2026
27d8233
fix: address code review feedback
ChristopherChudzicki Mar 18, 2026
f3f6c7e
fix: pluralization bug with mixed course/program nouns
ChristopherChudzicki Mar 18, 2026
fd8228c
test: use renderWithProviders in MitxOnlineResourceCard tests
ChristopherChudzicki Mar 18, 2026
1829491
refactor: rename getItemNoun to getRequirementItemNoun, use in Produc…
ChristopherChudzicki Mar 18, 2026
bf84087
refactor: always use "courses" in completion/summary text
ChristopherChudzicki Mar 18, 2026
40b4bb4
docs: improve comments explaining "courses" text limitation
ChristopherChudzicki Mar 18, 2026
6f3c8f3
refactor: use min/max price for course and program cards
ChristopherChudzicki Mar 18, 2026
ebbd3d4
fix: address review feedback — use shared formatPrice, improve tests
ChristopherChudzicki Mar 18, 2026
3d0b6e1
feat: pass certificate_type to card as certificateTypeName
ChristopherChudzicki Mar 18, 2026
7012dd7
test: replace waitFor+getBy with findBy in new tests
ChristopherChudzicki Mar 18, 2026
c920b41
fix: prefer product price over min/max when min equals max
ChristopherChudzicki Mar 18, 2026
dd5ec0b
feat: add start date display to program cards in MitxOnlineResourceCard
ChristopherChudzicki Mar 18, 2026
50d9444
refactor: extract CardData type and improve async test assertions
ChristopherChudzicki Mar 18, 2026
c004424
refactor: unify getBestRunForCourse and getBestRun into common/mitxon…
ChristopherChudzicki Mar 18, 2026
28a7da2
refactor: move price derivation into extractCardData
ChristopherChudzicki Mar 19, 2026
28133bb
rename coursePrice->resourcePrice
ChristopherChudzicki Mar 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ const DashboardCard: React.FC<DashboardCardProps> = ({
const title = getTitle(resource)
const courseRun =
resource.type === DashboardType.Course
? getBestRun(resource.data, contractId)
? getBestRun(resource.data, { enrollableOnly: true, contractId })
: undefined
const enrollmentRun =
resource.type === DashboardType.CourseRunEnrollment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe("helpers", () => {
next_run_id: null,
})

const result = getBestRun(course, contractId)
const result = getBestRun(course, { contractId })
expect(result).toEqual(run2)
})

Expand All @@ -192,7 +192,7 @@ describe("helpers", () => {
next_run_id: 2,
})

const result = getBestRun(course, contractId)
const result = getBestRun(course, { contractId })
expect(result).toEqual(run2)
})

Expand All @@ -207,11 +207,11 @@ describe("helpers", () => {
next_run_id: null,
})

const result = getBestRun(course, 100)
const result = getBestRun(course, { contractId: 100 })
expect(result).toBeUndefined()
})

test("returns undefined when no runs are enrollable", () => {
test("returns undefined when no runs are enrollable (enrollableOnly)", () => {
const run1 = factories.courses.courseRun({
id: 1,
is_enrollable: false,
Expand All @@ -229,11 +229,11 @@ describe("helpers", () => {
next_run_id: null,
})

const result = getBestRun(course)
const result = getBestRun(course, { enrollableOnly: true })
expect(result).toBeUndefined()
})

test("skips unenrollable runs when selecting default", () => {
test("skips unenrollable runs when enrollableOnly", () => {
const run1 = factories.courses.courseRun({
id: 1,
is_enrollable: false,
Expand All @@ -247,11 +247,11 @@ describe("helpers", () => {
next_run_id: null,
})

const result = getBestRun(course)
const result = getBestRun(course, { enrollableOnly: true })
expect(result).toEqual(run2)
})

test("prefers enrollable runs when others are not", () => {
test("prefers enrollable runs when enrollableOnly", () => {
const run1 = factories.courses.courseRun({
id: 1,
is_enrollable: true,
Expand All @@ -265,7 +265,7 @@ describe("helpers", () => {
next_run_id: null,
})

const result = getBestRun(course)
const result = getBestRun(course, { enrollableOnly: true })
expect(result).toEqual(run1)
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
CourseRunEnrollmentV3,
CourseRunV2,
CourseWithCourseRunsSerializerV2,
} from "@mitodl/mitxonline-api-axios/v2"
import { getBestRun } from "@/common/mitxonline"
export { getBestRun }

const ResourceType = {
Contract: "contract",
Expand Down Expand Up @@ -37,25 +38,6 @@ const filterEnrollmentsByOrganization = (
)
}

/**
* Helper to get the "best" run for a course (the next_run_id if available)
* If contractId is provided, prefer runs matching that contract
*/
const getBestRun = (
course: CourseWithCourseRunsSerializerV2,
contractId?: number,
): CourseRunV2 | undefined => {
if (!course.courseruns || course.courseruns.length === 0) return undefined

const candidateRuns = course.courseruns
.filter((run) => run.is_enrollable)
.filter((run) => !contractId || run.b2b_contract === contractId)
if (candidateRuns.length === 0) return undefined
const nextRun = candidateRuns.find((run) => run.id === course.next_run_id)

return nextRun ?? candidateRuns[0]
}

/**
* Selects the best enrollment from multiple enrollments for the same course.
* Priority:
Expand Down Expand Up @@ -102,7 +84,6 @@ export {
ResourceType,
EnrollmentStatus,
filterEnrollmentsByOrganization,
getBestRun,
selectBestEnrollment,
getKey,
getEnrollmentStatus,
Expand Down
149 changes: 0 additions & 149 deletions frontends/main/src/app-pages/ProductPages/MitxOnlineCourseCard.tsx

This file was deleted.

Loading
Loading