Skip to content

Commit fe69436

Browse files
authored
fix CTA text logic (#2675)
* fix CTA text logic * add a test that checks for view course cta text when end date is in the past and course is not completed
1 parent a35367b commit fe69436

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/DashboardCard.test.tsx

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,23 @@ describe.each([
176176

177177
test.each([
178178
{
179-
course: pastDashboardCourse(),
179+
course: pastDashboardCourse({
180+
enrollment: { status: EnrollmentStatus.Enrolled },
181+
}),
180182
expected: { labelPrefix: "View" },
181183
case: "past",
182184
},
183185
{
184-
course: currentDashboardCourse(),
186+
course: currentDashboardCourse({
187+
enrollment: { status: EnrollmentStatus.Enrolled },
188+
}),
185189
expected: { labelPrefix: "Continue" },
186190
case: "current",
187191
},
188192
{
189-
course: futureDashboardCourse(),
193+
course: futureDashboardCourse({
194+
enrollment: { status: EnrollmentStatus.Enrolled },
195+
}),
190196
expected: { labelPrefix: "Continue" },
191197
label: "future",
192198
},
@@ -515,12 +521,12 @@ describe.each([
515521
)
516522

517523
test.each([
518-
{ status: EnrollmentStatus.Completed },
519-
{ status: EnrollmentStatus.Enrolled },
520-
{ status: EnrollmentStatus.NotEnrolled },
524+
{ status: EnrollmentStatus.Completed, expectedText: "View Course" },
525+
{ status: EnrollmentStatus.Enrolled, expectedText: "Continue Course" },
526+
{ status: EnrollmentStatus.NotEnrolled, expectedText: "Start Course" },
521527
])(
522-
"CoursewareButton switches to Enroll functionality when enrollment status is not enrolled or undefined",
523-
({ status }) => {
528+
"CoursewareButton shows correct text based on enrollment status ($status)",
529+
({ status, expectedText }) => {
524530
setupUserApis()
525531
const course = dashboardCourse()
526532
course.enrollment = {
@@ -534,18 +540,31 @@ describe.each([
534540
const card = getCard()
535541
const coursewareButton = within(card).getByTestId("courseware-button")
536542

537-
if (
538-
status === EnrollmentStatus.NotEnrolled ||
539-
status === undefined ||
540-
!course.enrollment
541-
) {
542-
expect(coursewareButton).toHaveTextContent("Start Course")
543-
} else {
544-
expect(coursewareButton).toHaveTextContent("Continue Course")
545-
}
543+
expect(coursewareButton).toHaveTextContent(expectedText)
546544
},
547545
)
548546

547+
test("CoursewareButton shows 'View Course' when course has ended even if not completed", () => {
548+
setupUserApis()
549+
const course = dashboardCourse({
550+
run: {
551+
startDate: faker.date.past().toISOString(),
552+
endDate: faker.date.past().toISOString(), // Course has ended
553+
},
554+
enrollment: {
555+
status: EnrollmentStatus.Enrolled, // User is enrolled but not completed
556+
mode: EnrollmentMode.Audit,
557+
},
558+
})
559+
renderWithProviders(
560+
<DashboardCard titleAction="marketing" dashboardResource={course} />,
561+
)
562+
const card = getCard()
563+
const coursewareButton = within(card).getByTestId("courseware-button")
564+
565+
expect(coursewareButton).toHaveTextContent("View Course")
566+
})
567+
549568
const setupEnrollmentApis = (opts: {
550569
user: ReturnType<typeof mitxUser>
551570
course: ReturnType<typeof dashboardCourse>

frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/DashboardCard.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ const getCoursewareText = ({
170170
if (!enrollmentStatus || enrollmentStatus === EnrollmentStatus.NotEnrolled) {
171171
return `Start ${courseNoun}`
172172
}
173-
if (!endDate) return `Continue ${courseNoun}`
174-
if (isInPast(endDate)) {
173+
if (
174+
(endDate && isInPast(endDate)) ||
175+
enrollmentStatus === EnrollmentStatus.Completed
176+
) {
175177
return `View ${courseNoun}`
176178
}
177179
return `Continue ${courseNoun}`

0 commit comments

Comments
 (0)