2024-09-06 17:27:08 -04:00
|
|
|
/*
|
2024-09-10 17:46:40 -04:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2024-09-06 17:27:08 -04:00
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-10 17:46:40 -04:00
|
|
|
Please see LICENSE in the repository root for full details.
|
2024-09-06 17:27:08 -04:00
|
|
|
*/
|
|
|
|
|
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type RemoteTrackPublication } from "livekit-client";
|
2024-09-06 17:27:08 -04:00
|
|
|
import { test, expect } from "vitest";
|
2026-03-16 13:12:49 +01:00
|
|
|
import { act, render, screen } from "@testing-library/react";
|
2024-09-06 17:27:08 -04:00
|
|
|
import { axe } from "vitest-axe";
|
2025-03-13 13:58:43 +01:00
|
|
|
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
|
2026-03-16 13:12:49 +01:00
|
|
|
import { BehaviorSubject } from "rxjs";
|
2024-09-06 17:27:08 -04:00
|
|
|
|
|
|
|
|
import { GridTile } from "./GridTile";
|
2025-12-10 17:16:38 -05:00
|
|
|
import {
|
|
|
|
|
mockRtcMembership,
|
2026-02-25 14:02:59 +01:00
|
|
|
mockRemoteMedia,
|
2025-12-10 17:16:38 -05:00
|
|
|
mockRemoteParticipant,
|
|
|
|
|
} from "../utils/test";
|
2024-11-06 04:36:48 -05:00
|
|
|
import { GridTileViewModel } from "../state/TileViewModel";
|
2024-12-19 15:54:28 +00:00
|
|
|
import { ReactionsSenderProvider } from "../reactions/useReactionsSender";
|
2025-11-07 14:04:40 +01:00
|
|
|
import type { CallViewModel } from "../state/CallViewModel/CallViewModel";
|
2025-06-18 18:33:35 -04:00
|
|
|
import { constant } from "../state/Behavior";
|
2026-03-16 13:12:49 +01:00
|
|
|
import {
|
|
|
|
|
createRingingMedia,
|
|
|
|
|
type RingingMediaViewModel,
|
|
|
|
|
} from "../state/media/RingingMediaViewModel";
|
|
|
|
|
import { type MuteStates } from "../state/MuteStates";
|
2024-09-06 17:27:08 -04:00
|
|
|
|
2024-11-06 04:36:48 -05:00
|
|
|
global.IntersectionObserver = class MockIntersectionObserver {
|
|
|
|
|
public observe(): void {}
|
|
|
|
|
public unobserve(): void {}
|
|
|
|
|
public disconnect(): void {}
|
|
|
|
|
} as unknown as typeof IntersectionObserver;
|
|
|
|
|
|
2026-03-16 13:12:49 +01:00
|
|
|
const fakeRtcSession = {
|
|
|
|
|
on: () => {},
|
|
|
|
|
off: () => {},
|
|
|
|
|
room: {
|
|
|
|
|
on: () => {},
|
|
|
|
|
off: () => {},
|
|
|
|
|
client: {
|
|
|
|
|
getUserId: () => null,
|
|
|
|
|
getDeviceId: () => null,
|
|
|
|
|
on: () => {},
|
|
|
|
|
off: () => {},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
memberships: [],
|
|
|
|
|
} as unknown as MatrixRTCSession;
|
|
|
|
|
|
|
|
|
|
const callVm = {
|
|
|
|
|
reactions$: constant({}),
|
|
|
|
|
handsRaised$: constant({}),
|
|
|
|
|
} as Partial<CallViewModel> as CallViewModel;
|
|
|
|
|
|
2024-09-06 17:27:08 -04:00
|
|
|
test("GridTile is accessible", async () => {
|
2026-02-25 14:02:59 +01:00
|
|
|
const vm = mockRemoteMedia(
|
2024-12-06 12:28:37 +01:00
|
|
|
mockRtcMembership("@alice:example.org", "AAAA"),
|
2024-09-06 17:27:08 -04:00
|
|
|
{
|
|
|
|
|
rawDisplayName: "Alice",
|
|
|
|
|
getMxcAvatarUrl: () => "mxc://adfsg",
|
|
|
|
|
},
|
2025-12-10 17:16:38 -05:00
|
|
|
mockRemoteParticipant({
|
2024-09-06 17:27:08 -04:00
|
|
|
setVolume() {},
|
|
|
|
|
getTrackPublication: () =>
|
|
|
|
|
({}) as Partial<RemoteTrackPublication> as RemoteTrackPublication,
|
2025-12-10 17:16:38 -05:00
|
|
|
}),
|
2025-10-17 12:34:06 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { container } = render(
|
2026-03-16 13:12:49 +01:00
|
|
|
<ReactionsSenderProvider vm={callVm} rtcSession={fakeRtcSession}>
|
2025-10-17 12:34:06 -04:00
|
|
|
<GridTile
|
|
|
|
|
vm={new GridTileViewModel(constant(vm))}
|
|
|
|
|
onOpenProfile={() => {}}
|
|
|
|
|
targetWidth={300}
|
|
|
|
|
targetHeight={200}
|
|
|
|
|
showSpeakingIndicators
|
2026-04-23 17:03:35 +02:00
|
|
|
showNameTags
|
2026-03-16 13:12:49 +01:00
|
|
|
focusable
|
2025-10-17 12:34:06 -04:00
|
|
|
/>
|
|
|
|
|
</ReactionsSenderProvider>,
|
2024-09-06 17:27:08 -04:00
|
|
|
);
|
2025-10-17 12:34:06 -04:00
|
|
|
expect(await axe(container)).toHaveNoViolations();
|
|
|
|
|
// Name should be visible
|
|
|
|
|
screen.getByText("Alice");
|
2024-09-06 17:27:08 -04:00
|
|
|
});
|
2026-03-16 13:12:49 +01:00
|
|
|
|
|
|
|
|
test("GridTile displays ringing media", async () => {
|
|
|
|
|
const pickupState$ = new BehaviorSubject<
|
|
|
|
|
RingingMediaViewModel["pickupState$"]["value"]
|
|
|
|
|
>("ringing");
|
|
|
|
|
const vm = createRingingMedia({
|
|
|
|
|
pickupState$,
|
|
|
|
|
muteStates: {
|
|
|
|
|
video: { enabled$: constant(false) },
|
|
|
|
|
} as unknown as MuteStates,
|
|
|
|
|
id: "test",
|
|
|
|
|
userId: "@alice:example.org",
|
|
|
|
|
displayName$: constant("Alice"),
|
|
|
|
|
mxcAvatarUrl$: constant(undefined),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<ReactionsSenderProvider vm={callVm} rtcSession={fakeRtcSession}>
|
|
|
|
|
<GridTile
|
|
|
|
|
vm={new GridTileViewModel(constant(vm))}
|
|
|
|
|
onOpenProfile={() => {}}
|
|
|
|
|
targetWidth={300}
|
|
|
|
|
targetHeight={200}
|
|
|
|
|
showSpeakingIndicators
|
2026-04-23 17:03:35 +02:00
|
|
|
showNameTags
|
2026-03-16 13:12:49 +01:00
|
|
|
focusable
|
|
|
|
|
/>
|
|
|
|
|
</ReactionsSenderProvider>,
|
|
|
|
|
);
|
|
|
|
|
expect(await axe(container)).toHaveNoViolations();
|
|
|
|
|
// Name and status should be visible
|
|
|
|
|
screen.getByText("Alice");
|
|
|
|
|
screen.getByText("Calling…");
|
|
|
|
|
|
|
|
|
|
// Alice declines the call
|
|
|
|
|
act(() => pickupState$.next("decline"));
|
|
|
|
|
screen.getByText("Call ended");
|
|
|
|
|
});
|