mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-29 21:15:19 +00:00
Refactor config mocking to shared function
This commit is contained in:
@@ -11,14 +11,13 @@ import { beforeEach } from "vitest";
|
|||||||
import { render, screen } from "@testing-library/react";
|
import { render, screen } from "@testing-library/react";
|
||||||
import { MemoryRouter } from "react-router-dom";
|
import { MemoryRouter } from "react-router-dom";
|
||||||
|
|
||||||
import { Config } from "../config/Config";
|
|
||||||
import { DEFAULT_CONFIG } from "../config/ConfigOptions";
|
|
||||||
import { useMuteStates } from "./MuteStates";
|
import { useMuteStates } from "./MuteStates";
|
||||||
import {
|
import {
|
||||||
MediaDevice,
|
MediaDevice,
|
||||||
MediaDevices,
|
MediaDevices,
|
||||||
MediaDevicesContext,
|
MediaDevicesContext,
|
||||||
} from "../livekit/MediaDevicesContext";
|
} from "../livekit/MediaDevicesContext";
|
||||||
|
import { mockConfig } from "../utils/test";
|
||||||
|
|
||||||
function TestComponent(): ReactNode {
|
function TestComponent(): ReactNode {
|
||||||
const muteStates = useMuteStates();
|
const muteStates = useMuteStates();
|
||||||
@@ -106,9 +105,7 @@ describe("useMuteStates", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("disabled when no input devices", () => {
|
it("disabled when no input devices", () => {
|
||||||
vi.spyOn(Config, "get").mockReturnValue({
|
mockConfig();
|
||||||
...DEFAULT_CONFIG,
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
@@ -127,9 +124,7 @@ describe("useMuteStates", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should be enabled by default", () => {
|
it("should be enabled by default", () => {
|
||||||
vi.spyOn(Config, "get").mockReturnValue({
|
mockConfig();
|
||||||
...DEFAULT_CONFIG,
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
@@ -143,8 +138,7 @@ describe("useMuteStates", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("uses defaults from config", () => {
|
it("uses defaults from config", () => {
|
||||||
vi.spyOn(Config, "get").mockReturnValue({
|
mockConfig({
|
||||||
...DEFAULT_CONFIG,
|
|
||||||
media_devices: {
|
media_devices: {
|
||||||
enable_audio: false,
|
enable_audio: false,
|
||||||
enable_video: false,
|
enable_video: false,
|
||||||
@@ -163,9 +157,7 @@ describe("useMuteStates", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("skipLobby mutes inputs", () => {
|
it("skipLobby mutes inputs", () => {
|
||||||
vi.spyOn(Config, "get").mockReturnValue({
|
mockConfig();
|
||||||
...DEFAULT_CONFIG,
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<MemoryRouter initialEntries={["/room/?skipLobby=true"]}>
|
<MemoryRouter initialEntries={["/room/?skipLobby=true"]}>
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
|||||||
import { expect, test, vi } from "vitest";
|
import { expect, test, vi } from "vitest";
|
||||||
|
|
||||||
import { enterRTCSession } from "../src/rtcSessionHelpers";
|
import { enterRTCSession } from "../src/rtcSessionHelpers";
|
||||||
import { Config } from "../src/config/Config";
|
import { mockConfig } from "./utils/test";
|
||||||
import { DEFAULT_CONFIG } from "./config/ConfigOptions";
|
|
||||||
|
|
||||||
test("It joins the correct Session", async () => {
|
test("It joins the correct Session", async () => {
|
||||||
const focusFromOlderMembership = {
|
const focusFromOlderMembership = {
|
||||||
@@ -34,8 +33,7 @@ test("It joins the correct Session", async () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.spyOn(Config, "get").mockReturnValue({
|
mockConfig({
|
||||||
...DEFAULT_CONFIG,
|
|
||||||
livekit: { livekit_service_url: "http://my-default-service-url.com" },
|
livekit: { livekit_service_url: "http://my-default-service-url.com" },
|
||||||
});
|
});
|
||||||
const mockedSession = vi.mocked({
|
const mockedSession = vi.mocked({
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import {
|
|||||||
RemoteUserMediaViewModel,
|
RemoteUserMediaViewModel,
|
||||||
} from "../state/MediaViewModel";
|
} from "../state/MediaViewModel";
|
||||||
import { E2eeType } from "../e2ee/e2eeType";
|
import { E2eeType } from "../e2ee/e2eeType";
|
||||||
|
import { DEFAULT_CONFIG, ResolvedConfigOptions } from "../config/ConfigOptions";
|
||||||
|
import { Config } from "../config/Config";
|
||||||
|
|
||||||
export function withFakeTimers(continuation: () => void): void {
|
export function withFakeTimers(continuation: () => void): void {
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
@@ -197,3 +199,10 @@ export async function withRemoteMedia(
|
|||||||
vm.destroy();
|
vm.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function mockConfig(config: Partial<ResolvedConfigOptions> = {}): void {
|
||||||
|
vi.spyOn(Config, "get").mockReturnValue({
|
||||||
|
...DEFAULT_CONFIG,
|
||||||
|
...config,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user