Commit e11eb7fd authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

Add disconnect test

parent 3d51d240
Pipeline #3627 passed with stage
in 46 seconds
......@@ -49,8 +49,12 @@ robotController = {
});
},
getDisconnectButton: () => {
return document.getElementsByClassName('conference-user-control-bar')[0].childNodes[0].childNodes[2].childNodes[0]; // Check issue #53
},
disconnect: () => {
angular.element(document.getElementsByClassName('conference-user-control-bar')[0].childNodes[0].childNodes[2].childNodes[0]).scope().leaveConference();
angular.element(robotController.getDisconnectButton()).scope().leaveConference();
},
onAttendeePush: () => {},
......
......@@ -3,6 +3,7 @@
// Let's do some simple mocking of client-side services
const angular = {
disconnected: false,
registeredEvents: {},
element: () => ({
scope: () => ({
......@@ -10,6 +11,9 @@ const angular = {
$on: (event, f) => {
angular.registeredEvents[event] = f;
}
},
leaveConference: () => {
angular.disconnected = true;
}
}),
injector: () => ({
......@@ -65,6 +69,7 @@ describe('client/controller', () => {
const participants = global.robotController.getParticipants();
expect(participants).not.toEqual(expect.arrayContaining(['nostream']));
expect(participants).toHaveLength(3);
});
test('should return the Streams of the participant', () => {
......@@ -116,4 +121,10 @@ describe('client/controller', () => {
expect(eventFired).toBe(true);
});
test('should be disconnected on disconnect', () => {
global.robotController.getDisconnectButton = () => {}; // Mock of hubl.in getDisconnectButton
global.robotController.disconnect();
expect(angular.disconnected).toBe(true);
});
});
......@@ -13,6 +13,7 @@ robotController.external.load(config);
robot = {
recordedParticipantsWS: {},
participantsMediaRecorders: {},
isDisconnected: false,
processAudio(stream, callback, interval) {
const mediaRecorder = new MediaRecorder(stream);
......@@ -89,8 +90,8 @@ robot = {
},
checkDisconnect() {
if (robotController.getParticipantNumber().length === 1) {
robotController.disconnect();
if (robotController.getParticipants().length === 1) {
robot.stop();
}
},
......@@ -131,7 +132,12 @@ robot = {
}
// Wait 5 minute before leaving a room if alone
setTimeout(robot.checkDisconnect(), 300000);
setTimeout(robot.checkDisconnect, 300000);
},
stop: () => {
robot.isDisconnected = true;
robotController.disconnect();
}
};
......
......@@ -41,6 +41,13 @@ describe('client/robot', () => {
};
global.MediaRecorder.instances = {};
global._setTimeoutCalls = [];
global.setTimeout = function (f, timeout) {
global._setTimeoutCalls.push([f, timeout]);
};
global.isDisconnected = false;
global.robotController = {
external: {
load: () => {}
......@@ -52,8 +59,9 @@ describe('client/robot', () => {
'someid2'
],
getRemoteStream: id => ({type: 'RemoteStream', id}),
getParticipantNumber: () => 3,
disconnect: () => {}
disconnect: () => {
global.isDisconnected = true;
}
};
global.robotLib = {
......@@ -74,6 +82,11 @@ describe('client/robot', () => {
expect(global.robot).toBeDefined();
});
test('should set a timeout for disconnection', () => {
global.robot.start();
expect(global._setTimeoutCalls).toEqual(expect.arrayContaining([[global.robot.checkDisconnect, 300000]]));
});
test('should return a started mediaRecorder on `processAudio`', () => {
const res = global.robot.processAudio({
type: 'stream'
......@@ -134,6 +147,23 @@ describe('client/robot', () => {
expect(sttMock.wsMock.status).toBe('closed');
});
test('should not disconnected with more than one user', () => {
global.robot.start();
global.robotController.onAttendeeRemove({}, {easyrtcid: 'someid1'});
expect(global.isDisconnected).toBe(false);
});
test('should disconnected without user', () => {
global.robotController.getParticipants = function () { // Redefine getParticipants for one user
return [global.robotController.getMyId()];
};
global.robot.start();
global.robotController.onAttendeeRemove({}, {easyrtcid: 'someid1'});
expect(global.isDisconnected).toBe(true);
});
test('should try to reopen a stt ws on error', () => {
global.robot.start();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment