Skip to content
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
2 changes: 1 addition & 1 deletion client/src/entities/teacher-reported-today.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const LessonRow = ({ row, showDate, until }) => {
);
};

// A lesson from the lessonTimes setting that had no report while later lessons that day did.
// A lesson from the lessonTimes setting that had no report while a later lesson that day did.
const GapRow = ({ gap, showDate }) => (
<Box sx={{ px: 2, py: 0.75, borderTop: 1, borderColor: 'divider' }}>
<Box sx={{ display: 'grid', gridTemplateColumns: showDate ? '96px minmax(0, 1fr)' : '48px minmax(0, 1fr)', gap: 1.5, alignItems: 'center', px: 1, py: 0.5, border: '1px dashed', borderColor: 'text.disabled', borderRadius: 1, color: 'text.secondary' }}>
Expand Down
12 changes: 5 additions & 7 deletions client/src/utils/lessonGaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const getPeriodIndex = (row, periods) => {
return periods.findLastIndex((period) => period.startMinutes <= minutes);
};

// The class's lessons with an empty slot ({ isGap: true, period, reportDate }) before each reported lesson
// that comes after one or more unreported lessons of the same day. Nothing is added after the last report of the day.
// The class's lessons with an empty slot ({ isGap: true, period, reportDate }) for each unreported lesson of the day
// that comes before a reported one (including lessons before the first report). Nothing is added after the last report of the day.
// A lesson is placed by the time it was reported, so a report entered late counts for the lesson it was entered in.
export function withLessonGaps(lessons, lessonTimes) {
if (!Array.isArray(lessonTimes) || !lessonTimes.length) {
Expand All @@ -58,11 +58,9 @@ export function withLessonGaps(lessons, lessonTimes) {
const index = getPeriodIndex(row, periods);
const lastIndex = lastIndexByDate.get(reportDate) ?? -1;
if (index > lastIndex) {
if (lastIndex >= 0) {
periods.slice(lastIndex + 1, index).forEach((period) => {
result.push({ isGap: true, id: `gap_${reportDate}_${period.number}`, reportDate: row.reportDate, period });
});
}
periods.slice(lastIndex + 1, index).forEach((period) => {
result.push({ isGap: true, id: `gap_${reportDate}_${period.number}`, reportDate: row.reportDate, period });
});
lastIndexByDate.set(reportDate, index);
}
result.push(row);
Expand Down
19 changes: 15 additions & 4 deletions client/src/utils/lessonGaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,25 @@ describe('withLessonGaps', () => {
});

it('counts a report in the break for the lesson before it', () => {
// 09:35 is the break after lesson 2, 09:50 is lesson 3: nothing skipped.
const result = withLessonGaps([lesson(1, '2026-10-14T05:50:00Z'), lesson(2, '2026-10-14T06:35:00Z'), lesson(3, '2026-10-14T06:50:00Z')], lessonTimes);
// 08:40 is lesson 1, 09:35 is the break after lesson 2, 09:50 is lesson 3: nothing skipped.
const result = withLessonGaps([lesson(1, '2026-10-14T05:40:00Z'), lesson(2, '2026-10-14T06:35:00Z'), lesson(3, '2026-10-14T06:50:00Z')], lessonTimes);
expect(result.some((row) => row.isGap)).toBe(false);
});

it('adds nothing before the first or after the last report of the day', () => {
it('adds an empty slot for each unreported lesson before the first report of the day', () => {
// 09:50 is lesson 3: lessons 1-2 were skipped.
const result = withLessonGaps([lesson(1, '2026-10-14T06:50:00Z')], lessonTimes);
expect(result).toEqual([lesson(1, '2026-10-14T06:50:00Z')]);
expect(result.map((row) => (row.isGap ? `gap${row.period.number}` : row.id))).toEqual(['gap1', 'gap2', 1]);
});

it('adds nothing after the last report of the day', () => {
const result = withLessonGaps([lesson(1, '2026-10-14T05:10:00Z')], lessonTimes);
expect(result).toEqual([lesson(1, '2026-10-14T05:10:00Z')]);
});

it('adds nothing for a report before the first lesson', () => {
const result = withLessonGaps([lesson(1, '2026-10-14T04:30:00Z')], lessonTimes);
expect(result.some((row) => row.isGap)).toBe(false);
});

it('does not add a slot between two reports of the same lesson', () => {
Expand Down
Loading