Skip to content

Commit 176c26c

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

File tree

2 files changed

+590
-0
lines changed

2 files changed

+590
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 parts of the env that contains changing values
16+
vi.stubEnv("npm_node_execpath", "/test/path");
17+
vi.stubEnv("TINYPOOL_WORKER_ID", "111");
18+
vi.stubEnv("VITEST_WORKER_ID", "111");
19+
vi.stubEnv("VITEST_WORKER_ID", "111");
20+
vi.stubEnv("BERRY_BIN_FOLDER", "/test/path");
21+
vi.stubEnv("PATH", "/test/path;/test/path");
22+
vi.stubEnv("npm_execpath", "/test/path");
23+
24+
// Mock url params hook to avoid environment-dependent snapshot churn.
25+
vi.mock("../UrlParams", () => ({
26+
useUrlParams: (): { mocked: boolean; answer: number } => ({
27+
mocked: true,
28+
answer: 42,
29+
}),
30+
}));
31+
32+
// Provide a minimal mock of a Livekit Room structure used by the component.
33+
function createMockLivekitRoom(
34+
wsUrl: string,
35+
serverInfo: object,
36+
metadata: string,
37+
): { isLocal: boolean; url: string; room: LivekitRoom } {
38+
const mockRoom = {
39+
serverInfo,
40+
metadata,
41+
engine: { client: { ws: { url: wsUrl } } },
42+
} as unknown as LivekitRoom;
43+
44+
return {
45+
isLocal: true,
46+
url: wsUrl,
47+
room: mockRoom,
48+
};
49+
}
50+
51+
// Minimal MatrixClient mock with only the methods used by the component.
52+
function createMockMatrixClient(): MatrixClient {
53+
return {
54+
doesServerSupportUnstableFeature: vi.fn().mockResolvedValue(true), // ensure stickyEventsSupported eventually becomes true
55+
getCrypto: (): { getVersion: () => string } | undefined => ({
56+
getVersion: () => "crypto-1.0.0",
57+
}),
58+
getUserId: () => "@alice:example.org",
59+
getDeviceId: () => "DEVICE123",
60+
} as unknown as MatrixClient;
61+
}
62+
63+
describe("DeveloperSettingsTab", () => {
64+
it("renders and matches snapshot", async () => {
65+
const client = createMockMatrixClient();
66+
67+
const livekitRooms: {
68+
room: LivekitRoom;
69+
url: string;
70+
isLocal?: boolean;
71+
}[] = [
72+
createMockLivekitRoom(
73+
"wss://local-sfu.example.org",
74+
{ region: "local", version: "1.2.3" },
75+
"local-metadata",
76+
),
77+
{
78+
isLocal: false,
79+
url: "wss://remote-sfu.example.org",
80+
room: {
81+
serverInfo: { region: "remote", version: "4.5.6" },
82+
metadata: "remote-metadata",
83+
engine: { client: { ws: { url: "wss://remote-sfu.example.org" } } },
84+
} as unknown as LivekitRoom,
85+
},
86+
];
87+
88+
const { container } = render(
89+
<DeveloperSettingsTab client={client} livekitRooms={livekitRooms} />,
90+
);
91+
92+
// Wait for the async sticky events feature check to resolve so the final UI
93+
// (e.g. enabled Matrix_2_0 radio button) appears deterministically.
94+
await waitFor(() =>
95+
expect(client.doesServerSupportUnstableFeature).toHaveBeenCalled(),
96+
);
97+
98+
expect(container).toMatchSnapshot();
99+
});
100+
});

0 commit comments

Comments
 (0)