-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.ts
156 lines (135 loc) · 4.72 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { describe } from '@jest/globals';
import { Schedule } from './index';
import { Calendar } from './types';
const calendar: Calendar = [
{ day: 'Sunday', timeRange: [], classes: [] },
{
day: 'Monday',
timeRange: [
{ start: { hour: 9, minute: 30 }, end: { hour: 10, minute: 30 } },
{ start: { hour: 11, minute: 30 }, end: { hour: 12, minute: 30 } },
{ start: { hour: 13, minute: 30 }, end: { hour: 14, minute: 30 } }
],
classes: ['A', 'B', 'C']
},
{
day: 'Tuesday',
timeRange: [{ start: { hour: 9, minute: 30 }, end: { hour: 10, minute: 30 } }],
classes: ['D']
},
{
day: 'Wednesday',
timeRange: [{ start: { hour: 9, minute: 30 }, end: { hour: 10, minute: 30 } }],
classes: ['E']
},
{
day: 'Thursday',
timeRange: [{ start: { hour: 9, minute: 30 }, end: { hour: 10, minute: 30 } }],
classes: ['F']
},
{
day: 'Friday',
timeRange: [{ start: { hour: 9, minute: 30 }, end: { hour: 10, minute: 30 } }],
classes: ['G']
},
{ day: 'Saturday', timeRange: [], classes: [] }
];
const schedule = new Schedule(calendar);
describe('Main suite', () => {
it('should be array of classes', () => {
expect(schedule.getClassTable()).toEqual([[], ['A', 'B', 'C'], ['D'], ['E'], ['F'], ['G'], []]);
});
});
describe('Get Period number', () => {
it('should return a number for any time', () => {
expect(typeof schedule.getPeriodNumber()).toBe(typeof 1);
});
it('should return 0 for the first period (9:40)', () => {
const firstPeriodTime = new Date();
firstPeriodTime.setFullYear(2021, 5, 28); // Monday
firstPeriodTime.setHours(9, 40);
expect(schedule.getPeriodNumber(firstPeriodTime)).toBe(0);
});
it('should return 2 for the 3rd period (13:40)', () => {
const lastHour = new Date();
lastHour.setFullYear(2021, 5, 28);
lastHour.setHours(13, 40);
expect(schedule.getPeriodNumber(lastHour)).toBe(2);
});
it('should return -4 (break) on Monday 13:00', () => {
const breakTime = new Date();
breakTime.setFullYear(2021, 5, 28);
breakTime.setHours(13, 0);
expect(schedule.getPeriodNumber(breakTime)).toBe(-4);
});
it('should return -3 (no classes) on Sunday', () => {
const sunday = new Date();
sunday.setFullYear(2021, 5, 27);
sunday.setHours(9, 30);
expect(schedule.getPeriodNumber(sunday)).toBe(-3);
});
it('should return -2 (ended) at evening', () => {
const evening = new Date();
evening.setFullYear(2021, 5, 28);
evening.setHours(18, 30);
expect(schedule.getPeriodNumber(evening)).toBe(-2);
});
it('should return -1 (yet to start) on early morning', () => {
const earlyMorning = new Date();
earlyMorning.setFullYear(2021, 5, 28);
earlyMorning.setHours(7, 30);
expect(schedule.getPeriodNumber(earlyMorning)).toBe(-1);
});
});
describe('Get Classes', () => {
it('should return an array', () => {
expect(Array.isArray(schedule.getClasses())).toBe(true);
});
it('should return ["A", "B", "C"] for Day 1', () => {
expect(schedule.getClasses(1)).toEqual(['A', 'B', 'C']);
});
it('should return ["D"] for Tuesday (Date)', () => {
const tuesday = new Date();
tuesday.setFullYear(2021, 5, 29);
expect(schedule.getClasses(tuesday)).toEqual(['D']);
});
});
describe('Get Class', () => {
it('should return a string', () => {
expect(typeof schedule.getClass()).toBe(typeof 'a');
});
it('should be "G" for Day #5 1st period', () => {
expect(schedule.getClass(0, 5)).toBe('G');
});
it('should be "B" for Monday 2nd period', () => {
const mon2nd = new Date();
mon2nd.setFullYear(2021, 5, 28);
expect(schedule.getClass(1, mon2nd)).toBe('B');
});
});
describe('Get Class by Day', () => {
it('should return an array', () => {
expect(Array.isArray(schedule.getClassByDay('Sunday'))).toBe(true);
});
it('should return an array of objects with properties: day, timeRange and classes', () => {
const sundayTTObj = schedule.getClassByDay('Sunday')[0];
expect(sundayTTObj).toHaveProperty('day', 'Sunday');
expect(sundayTTObj).toHaveProperty('timeRange');
expect(sundayTTObj).toHaveProperty('classes');
});
});
describe('Get Current Class', () => {
it('should return a string', () => {
expect(typeof schedule.getCurrentClass()).toBe(typeof 'String');
});
});
describe('Get Next class', () => {
it('should return a string', () => {
expect(typeof schedule.getNextClass()).toBe(typeof 'String');
});
});
describe('Get Later class', () => {
it('should return a string', () => {
expect(typeof schedule.getLaterClass()).toBe(typeof 'String');
});
});