Skip to content

Commit bec7b32

Browse files
authored
fix(timetable): fix incorrect rendering of lecture slots (#3965)
1 parent 2780240 commit bec7b32

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

website/src/utils/modules.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
renderExamDuration,
1818
getExamDuration,
1919
canTa,
20+
areLessonsDuplicate,
2021
} from 'utils/modules';
2122
import { noBreak } from 'utils/react';
2223

@@ -93,6 +94,24 @@ test('areLessonsSameClass should identify lessons with different lessonType as d
9394
expect(areLessonsSameClass(mockLesson, otherLesson)).toBe(false);
9495
});
9596

97+
test(
98+
'areLessonsDuplicate should identify lessons from the same ClassNo but ' +
99+
'with different timings as non duplicates',
100+
() => {
101+
const otherLesson: Lesson = lessonWithDifferentProperty(mockLesson, 'startTime', '0000');
102+
expect(areLessonsDuplicate(mockLesson, otherLesson)).toBe(false);
103+
},
104+
);
105+
106+
test(
107+
'areLessonsDuplicate should identify lessons from the same ClassNo but ' +
108+
'with different day as non duplicates',
109+
() => {
110+
const otherLesson: Lesson = lessonWithDifferentProperty(mockLesson, 'day', 'Monday');
111+
expect(areLessonsDuplicate(mockLesson, otherLesson)).toBe(false);
112+
},
113+
);
114+
96115
test('formatExamDate should format an exam date string correctly', () => {
97116
expect(formatExamDate('2016-11-23T01:00:00.000Z')).toBe('23-Nov-2016 9:00\u00a0AM');
98117
expect(formatExamDate('2016-01-23T01:00:00.000Z')).toBe('23-Jan-2016 9:00\u00a0AM');

website/src/utils/modules.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ export function areLessonsSameClass(lesson1: Lesson, lesson2: Lesson): boolean {
4444
);
4545
}
4646

47+
// Are the two lessons exact duplicates of one another
48+
export function areLessonsDuplicate(lesson1: Lesson, lesson2: Lesson): boolean {
49+
return (
50+
lesson1.moduleCode === lesson2.moduleCode &&
51+
lesson1.classNo === lesson2.classNo &&
52+
lesson1.lessonType === lesson2.lessonType &&
53+
lesson1.day === lesson2.day &&
54+
lesson1.startTime === lesson2.startTime
55+
);
56+
}
57+
4758
/**
4859
* Convert exam in ISO format to 12-hour date/time format.
4960
*/

website/src/views/timetable/TimetableContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
resetTimetable,
2727
} from 'actions/timetables';
2828
import {
29+
areLessonsDuplicate,
2930
areLessonsSameClass,
3031
canTa,
3132
formatExamDate,
@@ -378,7 +379,7 @@ class TimetableContent extends React.Component<Props, State> {
378379

379380
// Prevent multiple versions of the same lesson
380381
if (
381-
timetableLessons.some((curLesson) => areLessonsSameClass(modifiableLesson, curLesson))
382+
timetableLessons.some((curLesson) => areLessonsDuplicate(modifiableLesson, curLesson))
382383
) {
383384
return;
384385
}

0 commit comments

Comments
 (0)