Skip to content

Commit 0f8cb97

Browse files
authored
website: timetables: Fix deserialization of TA courses in share link (#4214)
Currently, the `deserializeTa` function does not correctly parse share links with multiple TA-ed courses. Fix it and add some unit tests for the function. Fixes #4171
1 parent 1c4eb5a commit 0f8cb97

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

website/src/utils/timetables.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
areOtherClassesAvailable,
3434
arrangeLessonsForWeek,
3535
arrangeLessonsWithinDay,
36+
deserializeTa,
3637
deserializeTimetable,
3738
doLessonsOverlap,
3839
findExamClashes,
@@ -678,3 +679,17 @@ describe(getEndTimeAsDate, () => {
678679
expect(getEndTimeAsDate(lesson, date)).toEqual(new Date(2018, 5, 10, 10, 45));
679680
});
680681
});
682+
683+
describe(deserializeTa, () => {
684+
test('should deserialize TA modules string into object', () => {
685+
expect(deserializeTa('?')).toEqual({});
686+
expect(deserializeTa('?CS1010S=REC:1,TUT:8')).toEqual({});
687+
expect(deserializeTa('?CS1010S=REC:1,TUT:8&ta=CS3210(TUT:02)')).toEqual({
688+
CS3210: [['Tutorial', '02']],
689+
});
690+
expect(deserializeTa('?CS1010S=REC:1,TUT:8&ta=CS3210(TUT:02),CS3219(TUT:15)')).toEqual({
691+
CS3210: [['Tutorial', '02']],
692+
CS3219: [['Tutorial', '15']],
693+
});
694+
});
695+
});

website/src/utils/timetables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ export function deserializeTa(serialized: string): TaModulesConfig {
625625
// If user manually enters multiple TA query keys, use latest one
626626
const ta = Array.isArray(params.ta) ? last(params.ta) : params.ta;
627627
if (!ta) return deserialized;
628-
ta.split(`)${LESSON_SEP}`).forEach((moduleConfig) => {
628+
ta.split(LESSON_SEP).forEach((moduleConfig) => {
629629
const moduleCodeMatches = moduleConfig.match(/(.*)\(/);
630630
if (moduleCodeMatches === null) {
631631
return;

0 commit comments

Comments
 (0)