-
Notifications
You must be signed in to change notification settings - Fork 0
/
ts_test.test.js
43 lines (37 loc) · 1.73 KB
/
ts_test.test.js
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
const { addTimeSlot, delTimeSlot, dumpTimeSlots } = require('./ts_test');
describe('Time Slot Management', () => {
let slot;
beforeEach(() => {
slot = {
"label": "test",
"receiver": "test",
"start": 0,
"end": 0
};
});
afterEach(() => {
dumpTimeSlots(); // Reset the time slots after each test
});
test('Adding a time slot', () => {
const uuid = addTimeSlot(slot);
expect(uuid).toBeTruthy(); // Ensure a valid UUID is returned
expect(slot.id).toBe(uuid); // Ensure the slot's ID is set correctly
expect(gtimeslots.length).toBe(1); // Ensure the slot is added to the time slots array
});
test('Deleting a time slot', () => {
const uuid = addTimeSlot(slot);
delTimeSlot(uuid);
expect(gtimeslots.length).toBe(0); // Ensure the slot is removed from the time slots array
});
test('Dumping time slots', () => {
const consoleSpy = jest.spyOn(console, 'log');
addTimeSlot(slot);
dumpTimeSlots();
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining(slot.id)); // Ensure the slot's ID is logged
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining(slot.label)); // Ensure the slot's label is logged
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining(slot.created.toString())); // Ensure the slot's created timestamp is logged
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining(slot.receiver)); // Ensure the slot's receiver is logged
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining(slot.start.toString())); // Ensure the slot's start timestamp is logged
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining(slot.end.toString())); // Ensure the slot's end timestamp is logged
});
});