Commit 22e41c18 authored by Tom Jorquera's avatar Tom Jorquera
Browse files

Fix erroneous test for disconnection

parent 379ddb2c
Pipeline #4152 passed with stage
in 39 seconds
......@@ -117,6 +117,13 @@ describe('client/robot without init', () => {
});
describe('client/robot', () => {
const WebRTCAdapterMock = {
registeredFunc: null,
addDisconnectCallback: f => {
WebRTCAdapterMock.registeredFunc = f;
}
};
beforeEach(() => {
global.MediaRecorder = function (stream) {
const res = {
......@@ -162,11 +169,7 @@ describe('client/robot', () => {
disconnect: () => {
global.isDisconnected = true;
},
getWebRTCAdapter: () => ({
addDisconnectCallback: () => {
global.isReconnected = true;
}
})
getWebRTCAdapter: () => WebRTCAdapterMock
};
global.robotLib = {
......@@ -231,9 +234,24 @@ describe('client/robot', () => {
expect(global.isDisconnected).toBe(false);
});
test('should trigger when robot is disconnect', () => {
global.robotController.getWebRTCAdapter().addDisconnectCallback();
expect(global.isReconnected).toBe(true);
test('should trigger clearCOnnection when robot is disconnected', () => {
// Mock robot.clearConnection for this test
// Note: since robot is not cleanly reinitialized between each test
// (due to `require` not working as expected), we need to restore
// clearConnection at the end of the test.
let disconnected = false;
const oldClearConnection = global.robot.clearConnection;
global.robot.clearConnection = () => {
disconnected = true;
};
expect(WebRTCAdapterMock.registeredFunc).not.toBeNull();
// Trigger disconnection
WebRTCAdapterMock.registeredFunc();
expect(disconnected).toBeTruthy();
// Restore clearConnection
global.robot.clearConnection = oldClearConnection;
});
test('should clear the connection', () => {
......
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