@@ -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 >
0 commit comments