Skip to content

Commit

Permalink
test: get week courses
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Sep 25, 2024
1 parent 4cc05d6 commit b8ce7b7
Showing 1 changed file with 168 additions and 59 deletions.
227 changes: 168 additions & 59 deletions __tests__/calendar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,49 @@ describe('getWeekCourses', () => {
const expectedRes: WeekCourses = [
[
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'p',
classType: 'Practical',
location: 'online',
time: { start: '17:00', end: '18:00' },
classNumber: '6',
courses: [
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'p',
classType: 'Practical',
location: 'online',
classNumber: '6',
},
],
},
],
[
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
time: { start: '09:00', end: '10:00' },
classNumber: '1',
courses: [
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
classNumber: '1',
},
],
},
],
[],
[],
[
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'w',
classType: 'Workshop',
location: 'iw',
time: { start: '09:00', end: '10:00' },
classNumber: '3',
courses: [
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'w',
classType: 'Workshop',
location: 'iw',
classNumber: '3',
},
],
},
],
];
Expand Down Expand Up @@ -139,13 +151,17 @@ describe('getWeekCourses', () => {
[],
[
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
time: { start: '09:00', end: '10:00' },
classNumber: '1',
courses: [
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
classNumber: '1',
},
],
},
],
];
Expand Down Expand Up @@ -177,13 +193,17 @@ describe('getWeekCourses', () => {
const expectedRes: WeekCourses = [
[
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
time: { start: '09:00', end: '10:00' },
classNumber: '1',
courses: [
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
classNumber: '1',
},
],
},
],
[],
Expand Down Expand Up @@ -238,22 +258,30 @@ describe('getWeekCourses', () => {
const expectedRes: WeekCourses = [
[
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
time: { start: '09:00', end: '10:00' },
classNumber: '1',
courses: [
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
classNumber: '1',
},
],
},
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'p',
classType: 'Practical',
location: 'online',
time: { start: '17:00', end: '18:00' },
classNumber: '6',
courses: [
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'p',
classType: 'Practical',
location: 'online',
classNumber: '6',
},
],
},
],
[],
Expand All @@ -263,7 +291,7 @@ describe('getWeekCourses', () => {
];
expect(courses).toEqual(expectedRes);
});
it('should sort courses by duration (shortest first) in a day', () => {
it('should sort courses by duration (longest first) in a day', () => {
const enrolledCourses: Array<DetailedEnrolledCourse> = [
{
id: 'cs',
Expand All @@ -278,7 +306,7 @@ describe('getWeekCourses', () => {
location: 'online',
day: 'Monday',
date: { start: '09-09', end: '09-27' },
time: { start: '09:00', end: '12:00' },
time: { start: '09:00', end: '10:00' },
},
],
},
Expand All @@ -297,7 +325,7 @@ describe('getWeekCourses', () => {
location: 'bragg',
day: 'Monday',
date: { start: '09-09', end: '09-27' },
time: { start: '11:00', end: '12:00' },
time: { start: '09:00', end: '12:00' },
},
],
},
Expand All @@ -308,22 +336,103 @@ describe('getWeekCourses', () => {
const expectedRes: WeekCourses = [
[
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
time: { start: '11:00', end: '12:00' },
classNumber: '1',
time: { start: '09:00', end: '12:00' },
courses: [
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
classNumber: '1',
},
],
},
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'p',
classType: 'Practical',
location: 'online',
time: { start: '09:00', end: '12:00' },
classNumber: '6',
time: { start: '09:00', end: '10:00' },
courses: [
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'p',
classType: 'Practical',
location: 'online',
classNumber: '6',
},
],
},
],
[],
[],
[],
[],
];
expect(courses).toEqual(expectedRes);
});
it('should combine courses when they have the same time', () => {
const enrolledCourses: Array<DetailedEnrolledCourse> = [
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classes: [
{
type: 'Practical',
typeId: 'p',
classNumber: '6',
meetings: [
{
location: 'online',
day: 'Monday',
date: { start: '09-09', end: '09-27' },
time: { start: '09:00', end: '10:00' },
},
],
},
],
},
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classes: [
{
type: 'Lecture',
typeId: 'l',
classNumber: '1',
meetings: [
{
location: 'bragg',
day: 'Monday',
date: { start: '09-09', end: '09-27' },
time: { start: '09:00', end: '10:00' },
},
],
},
],
},
];
const courses = getWeekCourses(dayjs('2024-09-16'), enrolledCourses);
const expectedRes: WeekCourses = [
[
{
time: { start: '09:00', end: '10:00' },
courses: [
{
id: 'cs',
name: { code: 'cs', subject: 'cs', title: 'compsci' },
classTypeId: 'p',
classType: 'Practical',
location: 'online',
classNumber: '6',
},
{
id: 'm',
name: { code: 'm', subject: 'm', title: 'math' },
classTypeId: 'l',
classType: 'Lecture',
location: 'bragg',
classNumber: '1',
},
],
},
],
[],
Expand Down

0 comments on commit b8ce7b7

Please sign in to comment.