Skip to content
18 changes: 9 additions & 9 deletions website/src/actions/timetables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ describe('fillTimetableBlanks', () => {
test('do nothing if timetable is already full', () => {
const timetable = {
CS1010S: {
Lecture: '1',
Tutorial: '1',
Recitation: '1',
Lecture: ['1'],
Tutorial: ['1'],
Recitation: ['1'],
},
};

Expand All @@ -76,8 +76,8 @@ describe('fillTimetableBlanks', () => {
test('fill missing lessons with randomly generated modules', () => {
const timetable = {
CS1010S: {
Lecture: '1',
Tutorial: '1',
Lecture: ['1'],
Tutorial: ['1'],
},
CS3216: {},
};
Expand All @@ -95,9 +95,9 @@ describe('fillTimetableBlanks', () => {
semester,
moduleCode: 'CS1010S',
lessonConfig: {
Lecture: '1',
Tutorial: '1',
Recitation: expect.any(String),
Lecture: ['1'],
Tutorial: ['1'],
Recitation: expect.any(Array),
},
},
});
Expand All @@ -108,7 +108,7 @@ describe('fillTimetableBlanks', () => {
semester,
moduleCode: 'CS3216',
lessonConfig: {
Lecture: '1',
Lecture: ['1'],
},
},
});
Expand Down
24 changes: 12 additions & 12 deletions website/src/reducers/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ const exportData: ExportData = {
semester: 1,
timetable: {
CS3216: {
Lecture: '1',
Lecture: ['1'],
},
CS1010S: {
Lecture: '1',
Tutorial: '3',
Recitation: '2',
Lecture: ['1'],
Tutorial: ['3'],
Recitation: ['2'],
},
PC1222: {
Lecture: '1',
Tutorial: '3',
Lecture: ['1'],
Tutorial: ['3'],
},
},
colors: {
Expand Down Expand Up @@ -47,16 +47,16 @@ test('reducers should set export data state', () => {
lessons: {
[1]: {
CS3216: {
Lecture: '1',
Lecture: ['1'],
},
CS1010S: {
Lecture: '1',
Tutorial: '3',
Recitation: '2',
Lecture: ['1'],
Tutorial: ['3'],
Recitation: ['2'],
},
PC1222: {
Lecture: '1',
Tutorial: '3',
Lecture: ['1'],
Tutorial: ['3'],
},
},
},
Expand Down
32 changes: 16 additions & 16 deletions website/src/reducers/timetables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,41 +125,41 @@ describe('lesson reducer', () => {
lessons: {
[1]: {
CS1010S: {
Lecture: '1',
Recitation: '2',
Lecture: ['1'],
Recitation: ['2'],
},
CS3216: {
Lecture: '1',
Lecture: ['1'],
},
},
[2]: {
CS3217: {
Lecture: '1',
Lecture: ['1'],
},
},
},
},
setLessonConfig(1, 'CS1010S', {
Lecture: '2',
Recitation: '3',
Tutorial: '4',
Lecture: ['2'],
Recitation: ['3'],
Tutorial: ['4'],
}),
),
).toMatchObject({
lessons: {
[1]: {
CS1010S: {
Lecture: '2',
Recitation: '3',
Tutorial: '4',
Lecture: ['2'],
Recitation: ['3'],
Tutorial: ['4'],
},
CS3216: {
Lecture: '1',
Lecture: ['1'],
},
},
[2]: {
CS3217: {
Lecture: '1',
Lecture: ['1'],
},
},
},
Expand All @@ -172,7 +172,7 @@ describe('stateReconciler', () => {
'2015/2016': {
[1]: {
GET1006: {
Lecture: '1',
Lecture: ['1'],
},
},
},
Expand All @@ -181,13 +181,13 @@ describe('stateReconciler', () => {
const oldLessons = {
[1]: {
CS1010S: {
Lecture: '1',
Recitation: '2',
Lecture: ['1'],
Recitation: ['2'],
},
},
[2]: {
CS3217: {
Lecture: '1',
Lecture: ['1'],
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion website/src/reducers/timetables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function moduleLessonConfig(
if (!(classNo && lessonType)) return state;
return {
...state,
[lessonType]: classNo,
[lessonType]: [classNo],
};
}
case SET_LESSON_CONFIG:
Expand Down
2 changes: 1 addition & 1 deletion website/src/types/timetables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ClassNo, LessonType, ModuleCode, ModuleTitle, RawLesson } from './modul

// ModuleLessonConfig is a mapping of lessonType to ClassNo for a module.
export type ModuleLessonConfig = {
[lessonType: string]: ClassNo;
[lessonType: string]: ClassNo[];
};

// SemTimetableConfig is the timetable data for each semester.
Expand Down
66 changes: 33 additions & 33 deletions website/src/utils/timetables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ test('hydrateSemTimetableWithLessons should replace ClassNo with lessons', () =>
const modules: ModulesMap = { [moduleCode]: CS1010S };
const config: SemTimetableConfig = {
[moduleCode]: {
Tutorial: '8',
Recitation: '4',
Lecture: '1',
Tutorial: ['8'],
Recitation: ['4'],
Lecture: ['1'],
},
};

Expand Down Expand Up @@ -385,15 +385,15 @@ test('timetable serialization/deserialization', () => {
{},
{ CS1010S: {} },
{
GER1000: { Tutorial: 'B01' },
GER1000: { Tutorial: ['B01'] },
},
{
CS2104: { Lecture: '1', Tutorial: '2' },
CS2105: { Lecture: '1', Tutorial: '1' },
CS2107: { Lecture: '1', Tutorial: '8' },
CS4212: { Lecture: '1', Tutorial: '1' },
CS4243: { Laboratory: '2', Lecture: '1' },
GER1000: { Tutorial: 'B01' },
CS2104: { Lecture: ['1'], Tutorial: ['2'] },
CS2105: { Lecture: ['1'], Tutorial: ['1'] },
CS2107: { Lecture: ['1'], Tutorial: ['8'] },
CS4212: { Lecture: ['1'], Tutorial: ['1'] },
CS4243: { Laboratory: ['2'], Lecture: ['1'] },
GER1000: { Tutorial: ['B01'] },
},
];

Expand All @@ -406,8 +406,8 @@ test('deserializing edge cases', () => {
// Duplicate module code
expect(deserializeTimetable('CS1010S=LEC:01&CS1010S=REC:11')).toEqual({
CS1010S: {
Lecture: '01',
Recitation: '11',
Lecture: ['01'],
Recitation: ['11'],
},
});

Expand All @@ -416,7 +416,7 @@ test('deserializing edge cases', () => {
CS1010S: {},
CS3217: {},
CS2105: {
Lecture: '1',
Lecture: ['1'],
},
});
});
Expand All @@ -428,42 +428,42 @@ test('isSameTimetableConfig', () => {
// Change lessonType order
expect(
isSameTimetableConfig(
{ CS2104: { Tutorial: '1', Lecture: '2' } },
{ CS2104: { Lecture: '2', Tutorial: '1' } },
{ CS2104: { Tutorial: ['1'], Lecture: ['2'] } },
{ CS2104: { Lecture: ['2'], Tutorial: ['1'] } },
),
).toBe(true);

// Change module order
expect(
isSameTimetableConfig(
{
CS2104: { Lecture: '1', Tutorial: '2' },
CS2105: { Lecture: '1', Tutorial: '1' },
CS2104: { Lecture: ['1'], Tutorial: ['2'] },
CS2105: { Lecture: ['1'], Tutorial: ['1'] },
},
{
CS2105: { Lecture: '1', Tutorial: '1' },
CS2104: { Lecture: '1', Tutorial: '2' },
CS2105: { Lecture: ['1'], Tutorial: ['1'] },
CS2104: { Lecture: ['1'], Tutorial: ['2'] },
},
),
).toBe(true);

// Different values
expect(
isSameTimetableConfig(
{ CS2104: { Lecture: '1', Tutorial: '2' } },
{ CS2104: { Lecture: '2', Tutorial: '1' } },
{ CS2104: { Lecture: ['1'], Tutorial: ['2'] } },
{ CS2104: { Lecture: ['2'], Tutorial: ['1'] } },
),
).toBe(false);

// One is subset of the other
expect(
isSameTimetableConfig(
{
CS2104: { Tutorial: '1', Lecture: '2' },
CS2104: { Tutorial: ['1'], Lecture: ['2'] },
},
{
CS2104: { Tutorial: '1', Lecture: '2' },
CS2105: { Lecture: '1', Tutorial: '1' },
CS2104: { Tutorial: ['1'], Lecture: ['2'] },
CS2105: { Lecture: ['1'], Tutorial: ['1'] },
},
),
).toBe(false);
Expand Down Expand Up @@ -499,9 +499,9 @@ describe(validateTimetableModules, () => {
describe('validateModuleLessons', () => {
const semester: Semester = 1;
const lessons: ModuleLessonConfig = {
Lecture: '1',
Recitation: '10',
Tutorial: '11',
Lecture: ['1'],
Recitation: ['10'],
Tutorial: ['11'],
};

test('should leave valid lessons untouched', () => {
Expand All @@ -514,7 +514,7 @@ describe('validateModuleLessons', () => {
semester,
{
...lessons,
Laboratory: '2', // CS1010S has no lab
Laboratory: ['2'], // CS1010S has no lab
},
CS1010S,
),
Expand All @@ -527,7 +527,7 @@ describe('validateModuleLessons', () => {
semester,
{
...lessons,
Lecture: '2', // CS1010S has no Lecture 2
Lecture: ['2'], // CS1010S has no Lecture 2
},
CS1010S,
),
Expand All @@ -539,15 +539,15 @@ describe('validateModuleLessons', () => {
validateModuleLessons(
semester,
{
Tutorial: '10',
Tutorial: ['10'],
},
CS1010S,
),
).toEqual([
{
Lecture: '1',
Recitation: '1',
Tutorial: '10',
Lecture: ['1'],
Recitation: ['1'],
Tutorial: ['10'],
},
['Lecture', 'Recitation'],
]);
Expand Down
Loading