@@ -1161,6 +1161,179 @@ describe.each([
11611161 } ,
11621162 )
11631163
1164+ describe ( "B2C (non-B2B) Enrollment" , ( ) => {
1165+ test . each ( ENROLLMENT_TRIGGERS ) (
1166+ "Clicking $trigger on non-B2B course opens CourseEnrollmentDialog" ,
1167+ async ( { trigger } ) => {
1168+ const userData = mitxUser ( )
1169+ setMockResponse . get ( mitxonline . urls . userMe . get ( ) , userData )
1170+
1171+ const run = mitxonline . factories . courses . courseRun ( {
1172+ b2b_contract : null , // Non-B2B course
1173+ is_enrollable : true ,
1174+ } )
1175+ const course = dashboardCourse ( {
1176+ courseruns : [ run ] ,
1177+ next_run_id : run . id ,
1178+ } )
1179+
1180+ renderWithProviders (
1181+ < DashboardCard
1182+ resource = { { type : DashboardType . Course , data : course } }
1183+ /> ,
1184+ )
1185+
1186+ const card = getCard ( )
1187+ const triggerElement =
1188+ trigger === "button"
1189+ ? within ( card ) . getByTestId ( "courseware-button" )
1190+ : within ( card ) . getByText ( course . title )
1191+
1192+ await user . click ( triggerElement )
1193+
1194+ // Should open the CourseEnrollmentDialog, not JustInTimeDialog
1195+ await screen . findByRole ( "dialog" , { name : course . title } )
1196+ expect (
1197+ screen . queryByRole ( "dialog" , { name : "Just a Few More Details" } ) ,
1198+ ) . not . toBeInTheDocument ( )
1199+ } ,
1200+ )
1201+ } )
1202+
1203+ describe ( "Verified Program Enrollment" , ( ) => {
1204+ test . each ( ENROLLMENT_TRIGGERS ) (
1205+ "Clicking $trigger on course in verified program does one-click enrollment" ,
1206+ async ( { trigger } ) => {
1207+ const userData = mitxUser ( )
1208+ setMockResponse . get ( mitxonline . urls . userMe . get ( ) , userData )
1209+
1210+ const run = mitxonline . factories . courses . courseRun ( {
1211+ b2b_contract : null ,
1212+ is_enrollable : true ,
1213+ courseware_url : faker . internet . url ( ) ,
1214+ } )
1215+ const course = dashboardCourse ( {
1216+ courseruns : [ run ] ,
1217+ next_run_id : run . id ,
1218+ } )
1219+
1220+ const programEnrollment =
1221+ mitxonline . factories . enrollment . programEnrollmentV3 ( {
1222+ enrollment_mode : "verified" ,
1223+ } )
1224+
1225+ // Mock the enrollment endpoint
1226+ setMockResponse . post ( mitxonline . urls . enrollment . enrollmentsListV1 ( ) , { } )
1227+
1228+ renderWithProviders (
1229+ < DashboardCard
1230+ resource = { { type : DashboardType . Course , data : course } }
1231+ programEnrollment = { programEnrollment }
1232+ /> ,
1233+ )
1234+
1235+ const card = getCard ( )
1236+ const triggerElement =
1237+ trigger === "button"
1238+ ? within ( card ) . getByTestId ( "courseware-button" )
1239+ : within ( card ) . getByText ( course . title )
1240+
1241+ await user . click ( triggerElement )
1242+
1243+ // Should call enrollment endpoint
1244+ await waitFor ( ( ) => {
1245+ expect ( mockAxiosInstance . request ) . toHaveBeenCalledWith (
1246+ expect . objectContaining ( {
1247+ method : "POST" ,
1248+ url : mitxonline . urls . enrollment . enrollmentsListV1 ( ) ,
1249+ } ) ,
1250+ )
1251+ } )
1252+
1253+ expect (
1254+ screen . queryByRole ( "dialog" , { name : course . title } ) ,
1255+ ) . not . toBeInTheDocument ( )
1256+ expect (
1257+ screen . queryByRole ( "dialog" , { name : "Just a Few More Details" } ) ,
1258+ ) . not . toBeInTheDocument ( )
1259+ } ,
1260+ )
1261+
1262+ test ( "Audit program enrollment opens CourseEnrollmentDialog" , async ( ) => {
1263+ const userData = mitxUser ( )
1264+ setMockResponse . get ( mitxonline . urls . userMe . get ( ) , userData )
1265+
1266+ const run = mitxonline . factories . courses . courseRun ( {
1267+ b2b_contract : null ,
1268+ is_enrollable : true ,
1269+ } )
1270+ const course = dashboardCourse ( {
1271+ courseruns : [ run ] ,
1272+ next_run_id : run . id ,
1273+ } )
1274+
1275+ const programEnrollment =
1276+ mitxonline . factories . enrollment . programEnrollmentV3 ( {
1277+ enrollment_mode : "audit" , // Audit, not verified
1278+ } )
1279+
1280+ renderWithProviders (
1281+ < DashboardCard
1282+ resource = { { type : DashboardType . Course , data : course } }
1283+ programEnrollment = { programEnrollment }
1284+ /> ,
1285+ )
1286+
1287+ const card = getCard ( )
1288+ const button = within ( card ) . getByTestId ( "courseware-button" )
1289+
1290+ await user . click ( button )
1291+
1292+ // Should open the CourseEnrollmentDialog for audit enrollments
1293+ await screen . findByRole ( "dialog" , { name : course . title } )
1294+ } )
1295+ } )
1296+
1297+ describe ( "CourseEnrollmentDialog" , ( ) => {
1298+ test ( "shows course runs as options in dialog" , async ( ) => {
1299+ const userData = mitxUser ( )
1300+ setMockResponse . get ( mitxonline . urls . userMe . get ( ) , userData )
1301+
1302+ const run1 = mitxonline . factories . courses . courseRun ( {
1303+ b2b_contract : null ,
1304+ is_enrollable : true ,
1305+ title : "Fall 2025" ,
1306+ } )
1307+ const run2 = mitxonline . factories . courses . courseRun ( {
1308+ b2b_contract : null ,
1309+ is_enrollable : true ,
1310+ title : "Spring 2026" ,
1311+ } )
1312+ const course = dashboardCourse ( {
1313+ title : "Test Course Title" ,
1314+ courseruns : [ run1 , run2 ] ,
1315+ next_run_id : run1 . id ,
1316+ } )
1317+
1318+ renderWithProviders (
1319+ < DashboardCard
1320+ resource = { { type : DashboardType . Course , data : course } }
1321+ /> ,
1322+ )
1323+
1324+ const card = getCard ( )
1325+ const startButton = within ( card ) . getByTestId ( "courseware-button" )
1326+ await user . click ( startButton )
1327+
1328+ const dialog = await screen . findByRole ( "dialog" , {
1329+ name : "Test Course Title" ,
1330+ } )
1331+
1332+ // Dialog should show course runs as options
1333+ expect ( within ( dialog ) . getByText ( "Choose a date:" ) ) . toBeInTheDocument ( )
1334+ } )
1335+ } )
1336+
11641337 describe ( "Stacked Variant" , ( ) => {
11651338 test ( "applies stacked variant styling" , ( ) => {
11661339 setupUserApis ( )
0 commit comments