Skip to content

Commit e60bc9e

Browse files
committed
add developer tab snapshot test
1 parent a731981 commit e60bc9e

File tree

4 files changed

+537
-3
lines changed

4 files changed

+537
-3
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright 2025 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE in the repository root for full details.
6+
*/
7+
8+
import { describe, expect, it, vi } from "vitest";
9+
import { render, waitFor } from "@testing-library/react";
10+
11+
import type { MatrixClient } from "matrix-js-sdk";
12+
import type { Room as LivekitRoom } from "livekit-client";
13+
import { DeveloperSettingsTab } from "./DeveloperSettingsTab";
14+
15+
// Mock url params hook to avoid environment-dependent snapshot churn.
16+
vi.mock("../UrlParams", () => ({
17+
useUrlParams: (): { mocked: boolean; answer: number } => ({
18+
mocked: true,
19+
answer: 42,
20+
}),
21+
}));
22+
23+
// Provide a minimal mock of a Livekit Room structure used by the component.
24+
function createMockLivekitRoom(
25+
wsUrl: string,
26+
serverInfo: object,
27+
metadata: string,
28+
): { isLocal: boolean; url: string; room: LivekitRoom } {
29+
const mockRoom = {
30+
serverInfo,
31+
metadata,
32+
engine: { client: { ws: { url: wsUrl } } },
33+
} as unknown as LivekitRoom;
34+
35+
return {
36+
isLocal: true,
37+
url: wsUrl,
38+
room: mockRoom,
39+
};
40+
}
41+
42+
// Minimal MatrixClient mock with only the methods used by the component.
43+
function createMockMatrixClient(): MatrixClient {
44+
return {
45+
doesServerSupportUnstableFeature: vi.fn().mockResolvedValue(true), // ensure stickyEventsSupported eventually becomes true
46+
getCrypto: (): { getVersion: () => string } | undefined => ({
47+
getVersion: () => "crypto-1.0.0",
48+
}),
49+
getUserId: () => "@alice:example.org",
50+
getDeviceId: () => "DEVICE123",
51+
} as unknown as MatrixClient;
52+
}
53+
54+
describe("DeveloperSettingsTab", () => {
55+
it("renders and matches snapshot", async () => {
56+
const client = createMockMatrixClient();
57+
58+
const livekitRooms: {
59+
room: LivekitRoom;
60+
url: string;
61+
isLocal?: boolean;
62+
}[] = [
63+
createMockLivekitRoom(
64+
"wss://local-sfu.example.org",
65+
{ region: "local", version: "1.2.3" },
66+
"local-metadata",
67+
),
68+
{
69+
isLocal: false,
70+
url: "wss://remote-sfu.example.org",
71+
room: {
72+
serverInfo: { region: "remote", version: "4.5.6" },
73+
metadata: "remote-metadata",
74+
engine: { client: { ws: { url: "wss://remote-sfu.example.org" } } },
75+
} as unknown as LivekitRoom,
76+
},
77+
];
78+
79+
const { container } = render(
80+
<DeveloperSettingsTab
81+
client={client}
82+
livekitRooms={livekitRooms}
83+
env={{ MY_MOCK_ENV: 10, ENV: "test" } as unknown as ImportMetaEnv}
84+
/>,
85+
);
86+
87+
// Wait for the async sticky events feature check to resolve so the final UI
88+
// (e.g. enabled Matrix_2_0 radio button) appears deterministically.
89+
await waitFor(() =>
90+
expect(client.doesServerSupportUnstableFeature).toHaveBeenCalled(),
91+
);
92+
93+
expect(container).toMatchSnapshot();
94+
});
95+
});

src/settings/DeveloperSettingsTab.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ import { useUrlParams } from "../UrlParams";
4949
interface Props {
5050
client: MatrixClient;
5151
livekitRooms?: { room: LivekitRoom; url: string; isLocal?: boolean }[];
52+
env: ImportMetaEnv;
5253
}
5354

54-
export const DeveloperSettingsTab: FC<Props> = ({ client, livekitRooms }) => {
55+
export const DeveloperSettingsTab: FC<Props> = ({
56+
client,
57+
livekitRooms,
58+
env,
59+
}) => {
5560
const { t } = useTranslation();
5661
const [duplicateTiles, setDuplicateTiles] = useSetting(duplicateTilesSetting);
5762
const [debugTileLayout, setDebugTileLayout] = useSetting(
@@ -320,7 +325,7 @@ export const DeveloperSettingsTab: FC<Props> = ({ client, livekitRooms }) => {
320325
</>
321326
))}
322327
<p>{t("developer_mode.environment_variables")}</p>
323-
<pre>{JSON.stringify(import.meta.env, null, 2)}</pre>
328+
<pre>{JSON.stringify(env, null, 2)}</pre>
324329
<p>{t("developer_mode.url_params")}</p>
325330
<pre>{JSON.stringify(urlParams, null, 2)}</pre>
326331
</Form>

src/settings/SettingsModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ export const SettingsModal: FC<Props> = ({
209209
key: "developer",
210210
name: t("settings.developer_tab_title"),
211211
content: (
212-
<DeveloperSettingsTab client={client} livekitRooms={livekitRooms} />
212+
<DeveloperSettingsTab
213+
env={import.meta.env}
214+
client={client}
215+
livekitRooms={livekitRooms}
216+
/>
213217
),
214218
};
215219

0 commit comments

Comments
 (0)