Skip to content

Commit 9376396

Browse files
authored
don't use next_start_date for "anytime" courses & programs (#2670)
* don't use next_start_date for "anytime" courses & programs * add a test
1 parent 5204f22 commit 9376396

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

frontends/main/src/page-components/LearningResourceExpanded/InfoSection.test.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,33 @@ describe("Learning resource info section start date", () => {
226226
await user.click(showMoreLink)
227227
expect(runDates.children.length).toBe(totalRuns + 1)
228228
})
229+
230+
test("Anytime courses with next_start_date should not replace first date in 'As taught in' section", () => {
231+
const course = {
232+
...courses.free.anytime,
233+
next_start_date: "2024-03-15T00:00:00Z",
234+
}
235+
236+
renderWithTheme(<InfoSection resource={course} />)
237+
238+
const section = screen.getByTestId("drawer-info-items")
239+
240+
within(section).getByText("Starts:")
241+
within(section).getByText("Anytime")
242+
243+
within(section).getByText("As taught in:")
244+
245+
expect(within(section).queryByText("March 15, 2024")).toBeNull()
246+
247+
const runDates = within(section).getByTestId("drawer-run-dates")
248+
expect(runDates).toBeInTheDocument()
249+
250+
const firstRun = course.runs?.[0]
251+
invariant(firstRun)
252+
const firstRunDate = formatRunDate(firstRun, true)
253+
invariant(firstRunDate)
254+
expect(within(section).getByText(firstRunDate)).toBeInTheDocument()
255+
})
229256
})
230257

231258
describe("Learning resource info section format and location", () => {

frontends/main/src/page-components/LearningResourceExpanded/InfoSection.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,22 @@ const totalRunsWithDates = (resource: LearningResource) => {
180180

181181
const RunDates: React.FC<{ resource: LearningResource }> = ({ resource }) => {
182182
const [showingMore, setShowingMore] = useState(false)
183+
const anytime = showStartAnytime(resource)
183184
let sortedDates = resource.runs
184185
?.sort((a, b) => {
185186
if (a?.start_date && b?.start_date) {
186187
return Date.parse(a.start_date) - Date.parse(b.start_date)
187188
}
188189
return 0
189190
})
190-
.map((run) => formatRunDate(run, showStartAnytime(resource)))
191+
.map((run) => formatRunDate(run, anytime))
191192
.filter((date) => date !== null)
192193

193194
const nextStartDate = resource.next_start_date
194195
? formatDate(resource.next_start_date, "MMMM DD, YYYY")
195196
: null
196197

197-
if (sortedDates && nextStartDate) {
198+
if (sortedDates && nextStartDate && !anytime) {
198199
// Replace the first date with next_start_date
199200
sortedDates = [nextStartDate, ...sortedDates.slice(1)]
200201
}

0 commit comments

Comments
 (0)