From c3cd6248aec39deca82d37f31cc3b21321ae9b56 Mon Sep 17 00:00:00 2001 From: Timo K Date: Tue, 12 May 2026 13:14:34 +0200 Subject: [PATCH] simple lobby snapshot tests (we dont want this to get too invested as we plan to refactor the lobby( --- src/room/LobbyView.test.tsx | 100 ++ .../__snapshots__/LobbyView.test.tsx.snap | 950 ++++++++++++++++++ 2 files changed, 1050 insertions(+) create mode 100644 src/room/LobbyView.test.tsx create mode 100644 src/room/__snapshots__/LobbyView.test.tsx.snap diff --git a/src/room/LobbyView.test.tsx b/src/room/LobbyView.test.tsx new file mode 100644 index 00000000..1df74257 --- /dev/null +++ b/src/room/LobbyView.test.tsx @@ -0,0 +1,100 @@ +/* +Copyright 2025 New Vector Ltd. + +SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial +Please see LICENSE in the repository root for full details. +*/ + +import { describe, expect, it, vi } from "vitest"; +import { render } from "@testing-library/react"; +import { BrowserRouter } from "react-router-dom"; +import { TooltipProvider } from "@vector-im/compound-web"; +import { type MatrixClient } from "matrix-js-sdk"; + +import { LobbyView } from "./LobbyView"; +import { E2eeType } from "../e2ee/e2eeType"; +import { mockMediaDevices, mockMuteStates } from "../utils/test"; +import { MediaDevicesContext } from "../MediaDevicesContext"; +import { type ProcessorState } from "../livekit/TrackProcessorContext"; +import { type EncryptionSystem } from "../e2ee/sharedKeyManagement"; + +vi.mock("@livekit/components-react", () => ({ + usePreviewTracks: (): unknown[] => [], +})); + +vi.mock("../livekit/TrackProcessorContext", () => ({ + useTrackProcessor: (): ProcessorState => ({ + supported: false, + processor: undefined, + }), + useTrackProcessorSync: (): void => {}, +})); + +vi.mock("react-use-measure", () => ({ + default: (): [() => void, object] => [(): void => {}, {}], +})); + +vi.mock("../settings/SettingsModal", () => ({ + SettingsModal: (): null => null, + defaultSettingsTab: "general", +})); + +const mockClient = { + getUserId: () => "@user:example.org", + getDeviceId: () => "DEVICE", +} as Partial as MatrixClient; + +const matrixInfo = { + userId: "@user:example.org", + displayName: "Test User", + avatarUrl: "", + roomId: "!room:example.org", + roomName: "Test Room", + roomAlias: null, + roomAvatar: null, + e2eeSystem: { kind: E2eeType.NONE } satisfies EncryptionSystem, +}; + +function renderLobbyView( + props: Partial[0]> = {}, +): ReturnType { + const mediaDevices = mockMediaDevices({}); + const muteStates = mockMuteStates(); + + return render( + + + + {}} + confineToRoom={false} + hideHeader={false} + participantCount={3} + onShareClick={null} + {...props} + /> + + + , + ); +} + +describe("LobbyView", () => { + it("renders with header and participant count", () => { + const { container } = renderLobbyView(); + expect(container).toMatchSnapshot(); + }); + + it("renders without header", () => { + const { container } = renderLobbyView({ hideHeader: true }); + expect(container).toMatchSnapshot(); + }); + + it("renders with waiting for invite state", () => { + const { container } = renderLobbyView({ waitingForInvite: true }); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/src/room/__snapshots__/LobbyView.test.tsx.snap b/src/room/__snapshots__/LobbyView.test.tsx.snap new file mode 100644 index 00000000..28ca1c97 --- /dev/null +++ b/src/room/__snapshots__/LobbyView.test.tsx.snap @@ -0,0 +1,950 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`LobbyView > renders with header and participant count 1`] = ` +
+
+
+ +
+
+
+
+ + Back to recents + +
+ +
+
+`; + +exports[`LobbyView > renders with waiting for invite state 1`] = ` +
+
+
+ +
+
+
+
+ + Back to recents + +
+ +
+
+`; + +exports[`LobbyView > renders without header 1`] = ` +
+
+
+
+
+ + Back to recents + +
+ +
+
+`;