Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaboleken committed Dec 5, 2024
1 parent 6623d92 commit eb6673d
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/test/js/media_manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,67 @@ describe("MediaManager", function () {
});
*/

it("should handle null onEndedCallback gracefully", async function () {

var adaptor = new WebRTCAdaptor({
websocketURL: "ws://localhost",
mediaConstraints: {
video: "dummy",
audio: "dummy"
},
initializeComponents: false
});

var mediaManager = new MediaManager({
userParameters: {
mediaConstraints: {
video: false,
audio: true,
}
},
webRTCAdaptor: adaptor,

callback: (info, obj) => {
adaptor.notifyEventListeners(info, obj)
},
callbackError: (error, message) => {
adaptor.notifyErrorEventListeners(error, message)
},
getSender: (streamId, type) => {
return adaptor.getSender(streamId, type)
},
});

adaptor.mediaManager = mediaManager;

await adaptor.initialize();

// Create a mock video track
const mockVideoTrack = {
kind: "video",
enabled: true,
stop: sinon.fake(), // Mock the `stop` method
addEventListener: sinon.fake(),
removeEventListener: sinon.fake(),
onended: sinon.fake(),
};

// Create a desktop stream
const stream = new MediaStream();

// Create a fake `MediaStream` and add the mock video track
const cameraStream = new MediaStream();
cameraStream.getVideoTracks = () => [mockVideoTrack]; // Override `getVideoTracks`

sinon.stub(navigator.mediaDevices, 'getUserMedia').resolves(cameraStream);

await mediaManager.setDesktopwithCameraSource(stream, "streamId", null);

expect(mediaManager.desktopStream).to.equal(stream);
expect(mediaManager.smallVideoTrack).to.equal(mockVideoTrack);
navigator.mediaDevices.getUserMedia.restore();
});
});

});

0 comments on commit eb6673d

Please sign in to comment.