mirror of
https://github.com/vector-im/element-call.git
synced 2026-07-12 18:39:19 +00:00
Fix mocks
This commit is contained in:
@@ -8,14 +8,17 @@ Please see LICENSE in the repository root for full details.
|
|||||||
import { expect, test, vi } from "vitest";
|
import { expect, test, vi } from "vitest";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
mockMembership,
|
||||||
withLocalMedia,
|
withLocalMedia,
|
||||||
withRemoteMedia,
|
withRemoteMedia,
|
||||||
withTestScheduler,
|
withTestScheduler,
|
||||||
} from "../utils/test";
|
} from "../utils/test";
|
||||||
|
|
||||||
|
const rtcMembership = mockMembership("@alice:example.org", "AAAA");
|
||||||
|
|
||||||
test("control a participant's volume", async () => {
|
test("control a participant's volume", async () => {
|
||||||
const setVolumeSpy = vi.fn();
|
const setVolumeSpy = vi.fn();
|
||||||
await withRemoteMedia({}, { setVolume: setVolumeSpy }, (vm) =>
|
await withRemoteMedia(rtcMembership, {}, { setVolume: setVolumeSpy }, (vm) =>
|
||||||
withTestScheduler(({ expectObservable, schedule }) => {
|
withTestScheduler(({ expectObservable, schedule }) => {
|
||||||
schedule("-ab---c---d|", {
|
schedule("-ab---c---d|", {
|
||||||
a() {
|
a() {
|
||||||
@@ -60,7 +63,7 @@ test("control a participant's volume", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("toggle fit/contain for a participant's video", async () => {
|
test("toggle fit/contain for a participant's video", async () => {
|
||||||
await withRemoteMedia({}, {}, (vm) =>
|
await withRemoteMedia(rtcMembership, {}, {}, (vm) =>
|
||||||
withTestScheduler(({ expectObservable, schedule }) => {
|
withTestScheduler(({ expectObservable, schedule }) => {
|
||||||
schedule("-ab|", {
|
schedule("-ab|", {
|
||||||
a: () => vm.toggleFitContain(),
|
a: () => vm.toggleFitContain(),
|
||||||
@@ -76,17 +79,21 @@ test("toggle fit/contain for a participant's video", async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("local media remembers whether it should always be shown", async () => {
|
test("local media remembers whether it should always be shown", async () => {
|
||||||
await withLocalMedia({}, (vm) =>
|
await withLocalMedia(rtcMembership, {}, (vm) =>
|
||||||
withTestScheduler(({ expectObservable, schedule }) => {
|
withTestScheduler(({ expectObservable, schedule }) => {
|
||||||
schedule("-a|", { a: () => vm.setAlwaysShow(false) });
|
schedule("-a|", { a: () => vm.setAlwaysShow(false) });
|
||||||
expectObservable(vm.alwaysShow).toBe("ab", { a: true, b: false });
|
expectObservable(vm.alwaysShow).toBe("ab", { a: true, b: false });
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
// Next local media should start out *not* always shown
|
// Next local media should start out *not* always shown
|
||||||
await withLocalMedia({}, (vm) =>
|
await withLocalMedia(
|
||||||
withTestScheduler(({ expectObservable, schedule }) => {
|
rtcMembership,
|
||||||
schedule("-a|", { a: () => vm.setAlwaysShow(true) });
|
|
||||||
expectObservable(vm.alwaysShow).toBe("ab", { a: false, b: true });
|
{},
|
||||||
}),
|
(vm) =>
|
||||||
|
withTestScheduler(({ expectObservable, schedule }) => {
|
||||||
|
schedule("-a|", { a: () => vm.setAlwaysShow(true) });
|
||||||
|
expectObservable(vm.alwaysShow).toBe("ab", { a: false, b: true });
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { of } from "rxjs";
|
|||||||
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
|
||||||
|
|
||||||
import { GridTile } from "./GridTile";
|
import { GridTile } from "./GridTile";
|
||||||
import { withRemoteMedia } from "../utils/test";
|
import { mockMembership, withRemoteMedia } from "../utils/test";
|
||||||
import { GridTileViewModel } from "../state/TileViewModel";
|
import { GridTileViewModel } from "../state/TileViewModel";
|
||||||
import { ReactionsProvider } from "../useReactions";
|
import { ReactionsProvider } from "../useReactions";
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ global.IntersectionObserver = class MockIntersectionObserver {
|
|||||||
|
|
||||||
test("GridTile is accessible", async () => {
|
test("GridTile is accessible", async () => {
|
||||||
await withRemoteMedia(
|
await withRemoteMedia(
|
||||||
|
mockMembership("@alice:example.org", "AAAA"),
|
||||||
{
|
{
|
||||||
rawDisplayName: "Alice",
|
rawDisplayName: "Alice",
|
||||||
getMxcAvatarUrl: () => "mxc://adfsg",
|
getMxcAvatarUrl: () => "mxc://adfsg",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import userEvent from "@testing-library/user-event";
|
|||||||
import { of } from "rxjs";
|
import { of } from "rxjs";
|
||||||
|
|
||||||
import { SpotlightTile } from "./SpotlightTile";
|
import { SpotlightTile } from "./SpotlightTile";
|
||||||
import { withLocalMedia, withRemoteMedia } from "../utils/test";
|
import { mockMembership, withLocalMedia, withRemoteMedia } from "../utils/test";
|
||||||
import { SpotlightTileViewModel } from "../state/TileViewModel";
|
import { SpotlightTileViewModel } from "../state/TileViewModel";
|
||||||
|
|
||||||
global.IntersectionObserver = class MockIntersectionObserver {
|
global.IntersectionObserver = class MockIntersectionObserver {
|
||||||
@@ -22,6 +22,7 @@ global.IntersectionObserver = class MockIntersectionObserver {
|
|||||||
|
|
||||||
test("SpotlightTile is accessible", async () => {
|
test("SpotlightTile is accessible", async () => {
|
||||||
await withRemoteMedia(
|
await withRemoteMedia(
|
||||||
|
mockMembership("@alice:example.org", "AAAA"),
|
||||||
{
|
{
|
||||||
rawDisplayName: "Alice",
|
rawDisplayName: "Alice",
|
||||||
getMxcAvatarUrl: () => "mxc://adfsg",
|
getMxcAvatarUrl: () => "mxc://adfsg",
|
||||||
@@ -29,6 +30,7 @@ test("SpotlightTile is accessible", async () => {
|
|||||||
{},
|
{},
|
||||||
async (vm1) => {
|
async (vm1) => {
|
||||||
await withLocalMedia(
|
await withLocalMedia(
|
||||||
|
mockMembership("@bob:example.org", "BBBB"),
|
||||||
{
|
{
|
||||||
rawDisplayName: "Bob",
|
rawDisplayName: "Bob",
|
||||||
getMxcAvatarUrl: () => "mxc://dlskf",
|
getMxcAvatarUrl: () => "mxc://dlskf",
|
||||||
|
|||||||
@@ -173,13 +173,14 @@ export function mockLocalParticipant(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function withLocalMedia(
|
export async function withLocalMedia(
|
||||||
member: Partial<RoomMember>,
|
localRtcMember: CallMembership,
|
||||||
|
roomMember: Partial<RoomMember>,
|
||||||
continuation: (vm: LocalUserMediaViewModel) => void | Promise<void>,
|
continuation: (vm: LocalUserMediaViewModel) => void | Promise<void>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const localParticipant = mockLocalParticipant({});
|
const localParticipant = mockLocalParticipant({});
|
||||||
const vm = new LocalUserMediaViewModel(
|
const vm = new LocalUserMediaViewModel(
|
||||||
"local",
|
"local",
|
||||||
mockRoomMember(member),
|
mockRoomMember(localRtcMember, roomMember),
|
||||||
of(localParticipant),
|
of(localParticipant),
|
||||||
{
|
{
|
||||||
kind: E2eeType.PER_PARTICIPANT,
|
kind: E2eeType.PER_PARTICIPANT,
|
||||||
@@ -207,14 +208,15 @@ export function mockRemoteParticipant(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function withRemoteMedia(
|
export async function withRemoteMedia(
|
||||||
member: Partial<RoomMember>,
|
localRtcMember: CallMembership,
|
||||||
|
roomMember: Partial<RoomMember>,
|
||||||
participant: Partial<RemoteParticipant>,
|
participant: Partial<RemoteParticipant>,
|
||||||
continuation: (vm: RemoteUserMediaViewModel) => void | Promise<void>,
|
continuation: (vm: RemoteUserMediaViewModel) => void | Promise<void>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const remoteParticipant = mockRemoteParticipant(participant);
|
const remoteParticipant = mockRemoteParticipant(participant);
|
||||||
const vm = new RemoteUserMediaViewModel(
|
const vm = new RemoteUserMediaViewModel(
|
||||||
"remote",
|
"remote",
|
||||||
mockRoomMember(member),
|
mockRoomMember(localRtcMember, roomMember),
|
||||||
of(remoteParticipant),
|
of(remoteParticipant),
|
||||||
{
|
{
|
||||||
kind: E2eeType.PER_PARTICIPANT,
|
kind: E2eeType.PER_PARTICIPANT,
|
||||||
|
|||||||
Reference in New Issue
Block a user