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 = { ...@@ -49,8 +49,12 @@ robotController = {
}); });
}, },
getDisconnectButton: () => {
return document.getElementsByClassName('conference-user-control-bar')[0].childNodes[0].childNodes[2].childNodes[0]; // Check issue #53
},
disconnect: () => { 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: () => {}, onAttendeePush: () => {},
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// Let's do some simple mocking of client-side services // Let's do some simple mocking of client-side services
const angular = { const angular = {
disconnected: false,
registeredEvents: {}, registeredEvents: {},
element: () => ({ element: () => ({
scope: () => ({ scope: () => ({
...@@ -10,6 +11,9 @@ const angular = { ...@@ -10,6 +11,9 @@ const angular = {
$on: (event, f) => { $on: (event, f) => {
angular.registeredEvents[event] = f; angular.registeredEvents[event] = f;
} }
},
leaveConference: () => {
angular.disconnected = true;
} }
}), }),
injector: () => ({ injector: () => ({
...@@ -65,6 +69,7 @@ describe('client/controller', () => { ...@@ -65,6 +69,7 @@ describe('client/controller', () => {
const participants = global.robotController.getParticipants(); const participants = global.robotController.getParticipants();
expect(participants).not.toEqual(expect.arrayContaining(['nostream'])); expect(participants).not.toEqual(expect.arrayContaining(['nostream']));
expect(participants).toHaveLength(3);
}); });
test('should return the Streams of the participant', () => { test('should return the Streams of the participant', () => {
...@@ -116,4 +121,10 @@ describe('client/controller', () => { ...@@ -116,4 +121,10 @@ describe('client/controller', () => {
expect(eventFired).toBe(true); 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); ...@@ -13,6 +13,7 @@ robotController.external.load(config);
robot = { robot = {
recordedParticipantsWS: {}, recordedParticipantsWS: {},
participantsMediaRecorders: {}, participantsMediaRecorders: {},
isDisconnected: false,
processAudio(stream, callback, interval) { processAudio(stream, callback, interval) {
const mediaRecorder = new MediaRecorder(stream); const mediaRecorder = new MediaRecorder(stream);
...@@ -89,8 +90,8 @@ robot = { ...@@ -89,8 +90,8 @@ robot = {
}, },
checkDisconnect() { checkDisconnect() {
if (robotController.getParticipantNumber().length === 1) { if (robotController.getParticipants().length === 1) {
robotController.disconnect(); robot.stop();
} }
}, },
...@@ -131,7 +132,12 @@ robot = { ...@@ -131,7 +132,12 @@ robot = {
} }
// Wait 5 minute before leaving a room if alone // 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', () => { ...@@ -41,6 +41,13 @@ describe('client/robot', () => {
}; };
global.MediaRecorder.instances = {}; global.MediaRecorder.instances = {};
global._setTimeoutCalls = [];
global.setTimeout = function (f, timeout) {
global._setTimeoutCalls.push([f, timeout]);
};
global.isDisconnected = false;
global.robotController = { global.robotController = {
external: { external: {
load: () => {} load: () => {}
...@@ -52,8 +59,9 @@ describe('client/robot', () => { ...@@ -52,8 +59,9 @@ describe('client/robot', () => {
'someid2' 'someid2'
], ],
getRemoteStream: id => ({type: 'RemoteStream', id}), getRemoteStream: id => ({type: 'RemoteStream', id}),
getParticipantNumber: () => 3, disconnect: () => {
disconnect: () => {} global.isDisconnected = true;
}
}; };
global.robotLib = { global.robotLib = {
...@@ -74,6 +82,11 @@ describe('client/robot', () => { ...@@ -74,6 +82,11 @@ describe('client/robot', () => {
expect(global.robot).toBeDefined(); 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`', () => { test('should return a started mediaRecorder on `processAudio`', () => {
const res = global.robot.processAudio({ const res = global.robot.processAudio({
type: 'stream' type: 'stream'
...@@ -134,6 +147,23 @@ describe('client/robot', () => { ...@@ -134,6 +147,23 @@ describe('client/robot', () => {
expect(sttMock.wsMock.status).toBe('closed'); 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', () => { test('should try to reopen a stt ws on error', () => {
global.robot.start(); 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