@@ -6,6 +6,7 @@ import { formatRunDate } from "ol-utilities"
66import invariant from "tiny-invariant"
77import user from "@testing-library/user-event"
88import { renderWithTheme } from "../../test-utils"
9+ import { AvailabilityEnum } from "api"
910import { factories } from "api/test-utils"
1011
1112// This is a pipe followed by a zero-width space
@@ -125,7 +126,12 @@ describe("Learning resource info section start date", () => {
125126 const course = courses . free . dated
126127 const run = course . runs ?. [ 0 ]
127128 invariant ( run )
128- const runDate = formatRunDate ( run , false )
129+ const runDate = formatRunDate (
130+ run ,
131+ false ,
132+ course . availability ,
133+ course . best_run_id ,
134+ )
129135 invariant ( runDate )
130136 renderWithTheme ( < InfoSection resource = { course } /> )
131137
@@ -141,6 +147,7 @@ describe("Learning resource info section start date", () => {
141147 const enrollmentStart = daysFromToday ( 15 )
142148 const course = {
143149 ...courses . free . dated ,
150+ availability : AvailabilityEnum . Dated ,
144151 best_run_id : 1 ,
145152 runs : [
146153 {
@@ -184,6 +191,7 @@ describe("Learning resource info section start date", () => {
184191 const enrollmentStart = daysFromToday ( 40 ) // Later than start_date
185192 const course = {
186193 ...courses . free . dated ,
194+ availability : AvailabilityEnum . Dated ,
187195 best_run_id : 1 ,
188196 runs : [
189197 {
@@ -225,6 +233,7 @@ describe("Learning resource info section start date", () => {
225233 const todayDate = new Date ( ) . toISOString ( )
226234 const course = {
227235 ...courses . free . dated ,
236+ availability : AvailabilityEnum . Dated ,
228237 best_run_id : 1 ,
229238 runs : [
230239 {
@@ -275,7 +284,7 @@ describe("Learning resource info section start date", () => {
275284 ...run ,
276285 id : 1 ,
277286 start_date : null ,
278- enrollment_start : null ,
287+ end_date : null ,
279288 } ,
280289 ] ,
281290 }
@@ -290,7 +299,12 @@ describe("Learning resource info section start date", () => {
290299 const course = courses . free . anytime
291300 const run = course . runs ?. [ 0 ]
292301 invariant ( run )
293- const runDate = formatRunDate ( run , true )
302+ const runDate = formatRunDate (
303+ run ,
304+ true ,
305+ course . availability ,
306+ course . best_run_id ,
307+ )
294308 invariant ( runDate )
295309 renderWithTheme ( < InfoSection resource = { course } /> )
296310
@@ -310,7 +324,9 @@ describe("Learning resource info section start date", () => {
310324 }
311325 return 0
312326 } )
313- . map ( ( run ) => formatRunDate ( run , false ) )
327+ . map ( ( run ) =>
328+ formatRunDate ( run , false , course . availability , course . best_run_id ) ,
329+ )
314330 . slice ( 0 , 2 )
315331 . join ( SEPARATOR ) } Show more`
316332 invariant ( expectedDateText )
@@ -322,44 +338,6 @@ describe("Learning resource info section start date", () => {
322338 } )
323339 } )
324340
325- test ( "Multiple run dates with best_run_id uses best_run_id as first date" , ( ) => {
326- const firstRun = courses . multipleRuns . sameData . runs ?. [ 0 ]
327- invariant ( firstRun )
328- const bestRunStartDate = daysFromToday ( 50 )
329- const bestRunEnrollmentStart = daysFromToday ( 35 )
330- const course = {
331- ...courses . multipleRuns . sameData ,
332- best_run_id : 1 ,
333- runs : [
334- {
335- ...firstRun ,
336- id : 1 ,
337- start_date : bestRunStartDate ,
338- enrollment_start : bestRunEnrollmentStart ,
339- } ,
340- ...( courses . multipleRuns . sameData . runs ?. slice ( 1 ) ?? [ ] ) ,
341- ] ,
342- }
343- const sortedDates = course . runs
344- ?. sort ( ( a , b ) => {
345- if ( a ?. start_date && b ?. start_date ) {
346- return Date . parse ( a . start_date ) - Date . parse ( b . start_date )
347- }
348- return 0
349- } )
350- . map ( ( run ) => formatRunDate ( run , false ) )
351- . filter ( ( date ) => date !== null )
352-
353- // First date should be from best_run_id, second should be original second date
354- const expectedDateText = `${ formatTestDate ( bestRunStartDate ) } ${ SEPARATOR } ${ sortedDates ?. [ 1 ] } Show more`
355- renderWithTheme ( < InfoSection resource = { course } /> )
356-
357- const section = screen . getByTestId ( "drawer-info-items" )
358- within ( section ) . getAllByText ( ( _content , node ) => {
359- return node ?. textContent === expectedDateText || false
360- } )
361- } )
362-
363341 test ( "If data is different then dates, formats, locations and prices are not shown" , ( ) => {
364342 const course = courses . multipleRuns . differentData
365343 renderWithTheme ( < InfoSection resource = { course } /> )
@@ -382,23 +360,8 @@ describe("Learning resource info section start date", () => {
382360 expect ( runDates . children . length ) . toBe ( totalRuns + 1 )
383361 } )
384362
385- test ( "Anytime courses with best_run_id should not replace first date in 'As taught in' section" , ( ) => {
386- const firstRun = courses . free . anytime . runs ?. [ 0 ]
387- invariant ( firstRun )
388- const bestRunStartDate = daysFromToday ( 25 )
389- const bestRunEnrollmentStart = daysFromToday ( 10 )
390- const course = {
391- ...courses . free . anytime ,
392- best_run_id : 1 ,
393- runs : [
394- {
395- ...firstRun ,
396- id : 1 ,
397- start_date : bestRunStartDate ,
398- enrollment_start : bestRunEnrollmentStart ,
399- } ,
400- ] ,
401- }
363+ test ( "Anytime courses show 'Anytime' and semester/year in 'As taught in' section" , ( ) => {
364+ const course = courses . free . anytime
402365
403366 renderWithTheme ( < InfoSection resource = { course } /> )
404367
@@ -409,14 +372,17 @@ describe("Learning resource info section start date", () => {
409372
410373 within ( section ) . getByText ( "As taught in:" )
411374
412- expect (
413- within ( section ) . queryByText ( formatTestDate ( bestRunStartDate ) ) ,
414- ) . toBeNull ( )
415-
416375 const runDates = within ( section ) . getByTestId ( "drawer-run-dates" )
417376 expect ( runDates ) . toBeInTheDocument ( )
418377
419- const firstRunDate = formatRunDate ( course . runs [ 0 ] , true )
378+ const firstRun = course . runs ?. [ 0 ]
379+ invariant ( firstRun )
380+ const firstRunDate = formatRunDate (
381+ firstRun ,
382+ true ,
383+ course . availability ,
384+ course . best_run_id ,
385+ )
420386 invariant ( firstRunDate )
421387 expect ( within ( section ) . getByText ( firstRunDate ) ) . toBeInTheDocument ( )
422388 } )
0 commit comments