forked from webex/components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoomsJSONAdapter.test.js
139 lines (114 loc) · 4.05 KB
/
RoomsJSONAdapter.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
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
import {isObservable} from 'rxjs';
import rooms from '../data/rooms';
import RoomsJSONAdapter from './RoomsJSONAdapter';
describe('Rooms JSON Adapter Interface', () => {
let roomID;
let roomsJSONAdapter;
beforeEach(() => {
[roomID] = Object.keys(rooms);
roomsJSONAdapter = new RoomsJSONAdapter(rooms);
});
afterEach(() => {
roomsJSONAdapter = null;
});
test('getRoom() returns an observable', () => {
expect(isObservable(roomsJSONAdapter.getRoom())).toBeTruthy();
});
test('getRoom() returns a room data', (done) => {
roomsJSONAdapter.getRoom(roomID).subscribe((data) => {
expect(data).toEqual(rooms[roomID]);
done();
});
});
test('getRoom() throws a proper error message', (done) => {
const wrongRoomID = 'wrongRoomID';
roomsJSONAdapter.getRoom(wrongRoomID).subscribe(
() => {},
(error) => {
expect(error.message).toBe(`Could not find room with ID "${wrongRoomID}"`);
done();
},
);
});
test('getRoom() completes the observable', (done) => {
roomsJSONAdapter.getRoom(roomID).subscribe(
() => {},
() => {},
() => {
expect(true).toBeTruthy();
done();
},
);
});
test('getRoomActivities() returns an observable', () => {
expect(isObservable(roomsJSONAdapter.getRoomActivities())).toBeTruthy();
});
test('getRoomActivities() returns an array of previous activity IDs', (done) => {
roomsJSONAdapter.getRoomActivities(roomID).subscribe((data) => {
expect(data).toEqual(rooms[`${roomID}-activities`]);
done();
});
});
test('getRoomActivities() returns an observable to an empty array for a given wrong room ID', (done) => {
const wrongRoomActivitiesID = 'wrongRoomActivitiesID';
roomsJSONAdapter.getRoomActivities(wrongRoomActivitiesID).subscribe((data) => {
expect(data).toEqual([]);
done();
});
});
test('getRoomActivities() returns objects with a date parameter for time rulers', (done) => {
const timeRulerRoomID = 'room2';
roomsJSONAdapter.getRoomActivities(timeRulerRoomID).subscribe((data) => {
expect(data[1].date).toBeDefined();
done();
});
});
test('getRoomActivities() completes the observable', (done) => {
roomsJSONAdapter.getRoomActivities(roomID).subscribe(
() => {},
() => {},
() => {
expect(true).toBeTruthy();
done();
},
);
});
test('getPreviousRoomActivities() returns an array of previous activity IDs', (done) => {
roomsJSONAdapter.getPreviousRoomActivities(roomID).subscribe((data) => {
expect(data).toEqual(rooms[`${roomID}-previous-activities`]);
done();
});
});
test('getPreviousRoomActivities() returns error on wrong room ID', (done) => {
const wrongRoomActivitiesID = 'wrongRoomActivitiesID';
const message = 'Could not find activities for room wrongRoomActivitiesID. Make sure room ID is valid!';
roomsJSONAdapter.getPreviousRoomActivities(wrongRoomActivitiesID).subscribe(
() => {},
(error) => {
expect(error.message).toEqual(message);
done();
},
);
});
test('getPreviousRoomActivities() completes the observable when there is no more data', (done) => {
// Set last searched index to last element in data
roomsJSONAdapter.lastDataIndex[roomID] = rooms[`${roomID}-previous-activities`].length;
roomsJSONAdapter.getPreviousRoomActivities(roomID).subscribe(
() => {},
() => {},
() => {
expect(true).toBeTruthy();
done();
},
);
});
test('hasMoreActivities() returns true if room has more activities to load', () => {
roomsJSONAdapter.lastDataIndex[roomID] = 2; // Arbitrary small number
expect(roomsJSONAdapter.hasMoreActivities(roomID)).toBeTruthy();
});
test('hasMoreActivities() returns false if the room has no more activities to load', () => {
// Larger than the total
roomsJSONAdapter.lastDataIndex[roomID] = rooms[`${roomID}-previous-activities`].length + 1;
expect(roomsJSONAdapter.hasMoreActivities(roomID)).toBeFalsy();
});
});