Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:issue with meeting dates extending beyond the ending date. #6028

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/assets/javascripts/utils/course_date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ const CourseDateUtils = {
for (const week of range(0, (courseWeeks - 1), true)) {
weekStart = addWeeks(startOfWeek(toDate(course.timeline_start)), week);

let weekendDate = endOfWeek(toDate(weekStart));
if (isAfter(weekendDate, toDate(course.end))) {
weekendDate = toDate(course.end);
}

// Account for the first partial week, which may not have 7 days.
let firstDayOfWeek;
if (week === 0) {
Expand All @@ -153,7 +158,7 @@ const CourseDateUtils = {
// eslint-disable-next-line no-restricted-syntax
for (const i of range(firstDayOfWeek, 6, true)) {
const day = addDays(weekStart, i);
if (course && this.courseMeets(course.weekdays, i, format(day, 'yyyyMMdd'), exceptions)) {
if (course && this.courseMeets(course.weekdays, i, format(day, 'yyyyMMdd'), exceptions) && !isAfter(day, weekendDate)) {
ms.push(format(day, 'EEEE (MM/dd)'));
}
}
Expand Down
20 changes: 16 additions & 4 deletions spec/features/course_overview_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,36 @@
end

context 'when course starts in future' do
let(:timeline_start) { '2025-02-11'.to_date + 2.weeks } # a Tuesday

let(:course_start) { '2025-02-11'.to_date }
let(:course_end) { course_start + 6.months }
let(:timeline_start) { '2025-02-11'.to_date + 2.weeks }
let(:timeline_end) { course_end.to_date }

before do
course.update(timeline_start:)
visit "/courses/#{course.slug}"
sleep 1
end

it 'displays week activity for the first week' do
within '.course__this-week' do
expect(page).to have_content('First Active Week')
expect(page).to have_content content
end
within '.week-range' do
expect(page).to have_content(timeline_start.beginning_of_week(:sunday).strftime('%m/%d'))
# Class normally meets on Sun, W, Sat, but timeline starts on Tuesday.
end
within '.margin-bottom' do
meeting_dates = [
Date.parse('2025-02-23'), # Sunday (02/23)
Date.parse('2025-02-26'), # Wednesday (02/26)
Date.parse('2025-03-01') # Saturday (03/01)
]

meeting_dates.each do |meeting_date|
expect(meeting_date).to be_between(timeline_start, timeline_end).or be_between(course_start, course_end)
end

expect(page).to have_content('Meetings: Wednesday (02/26), Saturday (03/01)')
end
within '.week-index' do
Expand Down
Loading