forked from diorahman/appearin-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
171 lines (143 loc) · 5.74 KB
/
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
describe("AppearIn", function () {
var AppearIn = require('./index-browser');
var assert = require("assert");
var appearin;
var roomName = "/sly-koala";
var roomNameWithoutPrependingSlash = "cool-panda";
var BASE_URL = "https://appear.in";
beforeEach(function () {
appearin = new AppearIn({ debug: true });
});
describe("isWebRtcCompatible", function () {
it("should return true only if the browser is WebRTC compatible", function () {
// This test in itself is a bit weird, since it requires actually
// testing if the browser is WebRTC compatible...
// In reality this test here is much worse than the test in the test suite
if (window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.RTCPeerConnection) {
assert.ok(appearin.isWebRtcCompatible());
} else {
assert.ok(!appearin.isWebRtcCompatible());
}
});
});
describe("getRandomRoomName", function () {
it("should support promises", function (done) {
appearin.getRandomRoomName().then(function () { done(); });
});
it("should support callbacks", function (done) {
appearin.getRandomRoomName(function () {
done();
});
});
it("should return a random room name", function (done) {
appearin.getRandomRoomName().then(function (roomName) {
assert.ok(roomName);
assert.ok(typeof roomName === "string");
done();
});
});
it("should return a room name with a leading slash", function (done) {
appearin.getRandomRoomName().then(function (roomName) {
assert.ok(roomName[0] === "/");
done();
});
});
});
describe("addRoomToIframe", function () {
var iframe;
beforeEach(function () {
iframe = document.createElement("iframe");
});
it("should throw if all parameters are missing", function () {
try {
appearin.addRoomToIframe();
} catch(e) {
return;
}
throw new Error("should not get here");
});
it("should throw if the iframe parameter is undefined", function () {
try {
appearin.addRoomToIframe(undefined, roomName);
} catch(e) {
return;
}
throw new Error("should not get here");
});
it("should throw if the roomName parameter is missing", function () {
try {
appearin.addRoomToIframe(iframe);
} catch(e) {
return;
}
throw new Error("should not get here");
});
// use lodash.iselement
it("should throw if the passed element is not an iframe");
it("should attach the room to the iframe element", function () {
appearin.addRoomToIframe(iframe, roomName);
assert.ok(iframe.src);
});
it("should attach a room name with a prepending slash correctly", function () {
appearin.addRoomToIframe(iframe, roomName);
assert.ok(iframe.src === BASE_URL + roomName);
});
it("should attach a room name without a prepending slash correctly", function () {
appearin.addRoomToIframe(iframe, roomNameWithoutPrependingSlash);
assert.ok(iframe.src === BASE_URL + "/" + roomNameWithoutPrependingSlash);
});
});
describe("addRoomToElementById", function () {
var wrapperElement = document.createElement("div");
document.body.appendChild(wrapperElement);
var iframe;
beforeEach(function () {
wrapperElement.innerHTML = "";
iframe = document.createElement("iframe");
iframe.id = "appearin-iframe";
wrapperElement.appendChild(iframe);
});
it("should throw if all parameters are missing", function () {
try {
appearin.addRoomToElementById();
} catch(e) {
return;
}
throw new Error("should not get here");
});
it("should throw if the id parameter is undefined", function () {
try {
appearin.addRoomToElementById(undefined, roomName);
} catch(e) {
return;
}
throw new Error("should not get here");
});
it("should throw if the roomName parameter is missing", function () {
try {
appearin.addRoomToElementById(iframe.id);
} catch(e) {
return;
}
throw new Error("should not get here");
});
it("should return if the element does not exist", function () {
// maybe this should throw instead to keep consistent?
appearin.addRoomToElementById("iframe-id-does-not-exist", roomName);
assert.ok(iframe.src === "");
});
it("should add the room to the iframe", function () {
appearin.addRoomToElementById(iframe.id, roomName);
assert.ok(iframe.src === BASE_URL + roomName);
});
it("should handle roomNames with prepending slash", function () {
appearin.addRoomToElementById(iframe.id, roomName);
assert.ok(iframe.src === BASE_URL + roomName);
});
it("should handle room names without prepending slash", function () {
appearin.addRoomToElementById(iframe.id, roomNameWithoutPrependingSlash);
assert.ok(iframe.src === BASE_URL + "/" + roomNameWithoutPrependingSlash);
});
});
});