From 89cabf9fa296e533264a20f35fe3c40705a9d188 Mon Sep 17 00:00:00 2001 From: Ryan Emmick Date: Mon, 10 Aug 2026 11:41:26 -0500 Subject: [PATCH] test: cover rageshake media quality metadata and preset edge cases --- src/livekit/options.test.ts | 37 +++++++++++++++- src/settings/useSubmitRageshake.test.tsx | 56 ++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/src/livekit/options.test.ts b/src/livekit/options.test.ts index cea3d9132..03134f0ce 100644 --- a/src/livekit/options.test.ts +++ b/src/livekit/options.test.ts @@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details. */ import { describe, expect, it, vi } from "vitest"; -import { VideoPresets } from "livekit-client"; +import { VideoPresets, type VideoPreset } from "livekit-client"; import { buildLiveKitOptions, getLiveKitOptions } from "./options"; import { Config } from "../config/Config"; @@ -101,6 +101,41 @@ describe("buildLiveKitOptions", () => { }); }); + it("maps low resolutions to the closest preset, rounding up", () => { + const expectations: [number, VideoPreset][] = [ + [180, VideoPresets.h180], + [360, VideoPresets.h360], + [480, VideoPresets.h540], + [540, VideoPresets.h540], + [720, VideoPresets.h720], + ]; + for (const [height, preset] of expectations) { + const opts = buildLiveKitOptions({ video: { max_resolution: height } }); + expect(opts.videoCaptureDefaults?.resolution).toEqual(preset.resolution); + } + }); + + it("screen share layers fall back to max_framerate, then 30", () => { + const fromMax = buildLiveKitOptions({ + screen_share: { + max_framerate: 15, + simulcast_layers: [{ height: 540, bitrate: 1_000_000 }], + }, + }); + expect( + fromMax.publishDefaults?.screenShareSimulcastLayers?.[0], + ).toMatchObject({ encoding: { maxFramerate: 15 } }); + + const fromDefault = buildLiveKitOptions({ + screen_share: { + simulcast_layers: [{ height: 540, bitrate: 1_000_000 }], + }, + }); + expect( + fromDefault.publishDefaults?.screenShareSimulcastLayers?.[0], + ).toMatchObject({ encoding: { maxFramerate: 30 } }); + }); + it("applies custom video simulcast layers", () => { const opts = buildLiveKitOptions({ video: { diff --git a/src/settings/useSubmitRageshake.test.tsx b/src/settings/useSubmitRageshake.test.tsx index b5d075532..396b04316 100644 --- a/src/settings/useSubmitRageshake.test.tsx +++ b/src/settings/useSubmitRageshake.test.tsx @@ -22,6 +22,8 @@ import { useSubmitRageshake, getRageshakeSubmitUrl } from "./submit-rageshake"; import { ClientContextProvider } from "../ClientContext"; import { getUrlParams } from "../UrlParams"; import { mockConfig } from "../utils/test"; +import { DEFAULT_CONFIG } from "../config/ConfigOptions"; +import { advancedCamera, advancedScreenShare } from "./settings"; vi.mock("../UrlParams", () => ({ getUrlParams: vi.fn() })); @@ -201,6 +203,60 @@ describe("useSubmitRageshake", () => { }); }); + describe("media quality metadata", () => { + const submitAndGetBody = async (): Promise => { + const fetchFn = vi.fn().mockResolvedValue({ + status: 200, + }); + vi.stubGlobal("fetch", fetchFn); + + renderWithMockClient(() => "https://rageshake.localhost/foo", false); + screen.getByTestId("submit").click(); + await waitFor(() => { + expect(screen.getByTestId("sent").textContent).toBe("true"); + }); + return fetchFn.mock.calls[0][1].body as FormData; + }; + + beforeEach(() => { + vi.unstubAllGlobals(); + }); + + afterEach(() => { + advancedCamera.setValue(advancedCamera.defaultValue); + advancedScreenShare.setValue(advancedScreenShare.defaultValue); + vi.clearAllMocks(); + }); + + it("omits media quality fields when config and settings are default", async () => { + mockConfig({}); + const body = await submitAndGetBody(); + expect(body.get("custom_media_quality_in_config")).toBeNull(); + expect(body.get("devTools_advancedCameraSettings")).toBeNull(); + expect(body.get("devTools_advancedScreenShareSetting")).toBeNull(); + }); + + it("includes custom_media_quality_in_config when media_quality differs from default", async () => { + mockConfig({ + media_quality: { + ...DEFAULT_CONFIG.media_quality, + video_codec: "h264", + }, + }); + const body = await submitAndGetBody(); + expect(body.get("custom_media_quality_in_config")).toBe("true"); + }); + + it("includes devTools flags when advanced media settings are enabled", async () => { + mockConfig({}); + advancedCamera.setValue(true); + advancedScreenShare.setValue(true); + const body = await submitAndGetBody(); + expect(body.get("devTools_advancedCameraSettings")).toBe("true"); + expect(body.get("devTools_advancedScreenShareSetting")).toBe("true"); + }); + }); + describe("when rageshake is not available", () => { it("starts unsent", () => { renderWithMockClient(() => undefined, false);