Skip to content

Commit 66857c5

Browse files
committed
increase coverage
1 parent 76447bf commit 66857c5

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

tests/main.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,4 +1363,50 @@ describe("MediaMock", () => {
13631363
// Stream track deviceId should match the selected camera's deviceId
13641364
expect(videoTrack.id).toBe(primaryFrontCamera?.deviceId);
13651365
});
1366+
1367+
it("should support facingMode as object with ideal constraint", async () => {
1368+
const device = getDeviceForBrowser();
1369+
MediaMock.mock(device);
1370+
await MediaMock.setMediaURL(imageUrl);
1371+
1372+
const stream = await navigator.mediaDevices.getUserMedia({
1373+
video: { facingMode: { ideal: "environment" } },
1374+
});
1375+
expect(stream).toBeDefined();
1376+
1377+
const videoTrack = stream.getVideoTracks()[0];
1378+
1379+
// Get the last back camera (environment) from the device
1380+
const backCameras = device.mediaDeviceInfo.filter(
1381+
(d) => d.kind === "videoinput" && d.getCapabilities().facingMode?.includes("environment"),
1382+
);
1383+
const primaryBackCamera = backCameras.length > 0 ? backCameras[backCameras.length - 1] : undefined;
1384+
1385+
// Stream track label should match the selected back camera
1386+
if (primaryBackCamera) {
1387+
expect(videoTrack.label).toBe(primaryBackCamera.label);
1388+
}
1389+
});
1390+
1391+
it("should support facingMode as object with exact constraint", async () => {
1392+
const device = getDeviceForBrowser();
1393+
MediaMock.mock(device);
1394+
await MediaMock.setMediaURL(imageUrl);
1395+
1396+
const stream = await navigator.mediaDevices.getUserMedia({
1397+
video: { facingMode: { exact: "user" } },
1398+
});
1399+
expect(stream).toBeDefined();
1400+
1401+
const videoTrack = stream.getVideoTracks()[0];
1402+
1403+
// Get the last front camera (user) from the device
1404+
const frontCameras = device.mediaDeviceInfo.filter(
1405+
(d) => d.kind === "videoinput" && d.getCapabilities().facingMode?.includes("user"),
1406+
);
1407+
const primaryFrontCamera = frontCameras.length > 0 ? frontCameras[frontCameras.length - 1] : undefined;
1408+
1409+
// Stream track label should match the selected front camera
1410+
expect(videoTrack.label).toBe(primaryFrontCamera?.label);
1411+
});
13661412
});

0 commit comments

Comments
 (0)