2024-09-06 18:31:07 -04:00
|
|
|
/*
|
2024-09-10 17:46:40 -04:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2024-09-06 18:31:07 -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 18:31:07 -04:00
|
|
|
*/
|
|
|
|
|
|
2024-09-10 17:35:50 -04:00
|
|
|
import { test, expect, vi } from "vitest";
|
|
|
|
|
import { isInaccessible, render, screen } from "@testing-library/react";
|
2024-09-06 18:31:07 -04:00
|
|
|
import { axe } from "vitest-axe";
|
2024-09-10 17:35:50 -04:00
|
|
|
import userEvent from "@testing-library/user-event";
|
2024-09-06 18:31:07 -04:00
|
|
|
|
|
|
|
|
import { SpotlightTile } from "./SpotlightTile";
|
2024-12-06 12:28:37 +01:00
|
|
|
import {
|
2025-06-12 19:16:37 -04:00
|
|
|
mockLocalParticipant,
|
|
|
|
|
mockMediaDevices,
|
2024-12-06 12:28:37 +01:00
|
|
|
mockRtcMembership,
|
2025-10-17 12:34:06 -04:00
|
|
|
createLocalMedia,
|
|
|
|
|
createRemoteMedia,
|
2025-12-10 17:16:38 -05:00
|
|
|
mockRemoteParticipant,
|
2024-12-06 12:28:37 +01:00
|
|
|
} from "../utils/test";
|
2024-11-06 04:36:48 -05:00
|
|
|
import { SpotlightTileViewModel } from "../state/TileViewModel";
|
2025-06-18 18:33:35 -04:00
|
|
|
import { constant } from "../state/Behavior";
|
2024-09-06 18:31:07 -04:00
|
|
|
|
|
|
|
|
global.IntersectionObserver = class MockIntersectionObserver {
|
|
|
|
|
public observe(): void {}
|
|
|
|
|
public unobserve(): void {}
|
|
|
|
|
} as unknown as typeof IntersectionObserver;
|
|
|
|
|
|
|
|
|
|
test("SpotlightTile is accessible", async () => {
|
2025-10-17 12:34:06 -04:00
|
|
|
const vm1 = createRemoteMedia(
|
2024-12-06 12:28:37 +01:00
|
|
|
mockRtcMembership("@alice:example.org", "AAAA"),
|
2024-09-06 18:31:07 -04:00
|
|
|
{
|
|
|
|
|
rawDisplayName: "Alice",
|
|
|
|
|
getMxcAvatarUrl: () => "mxc://adfsg",
|
|
|
|
|
},
|
2025-12-10 17:16:38 -05:00
|
|
|
mockRemoteParticipant({}),
|
2025-10-17 12:34:06 -04:00
|
|
|
);
|
2024-09-10 17:35:50 -04:00
|
|
|
|
2025-10-17 12:34:06 -04:00
|
|
|
const vm2 = createLocalMedia(
|
|
|
|
|
mockRtcMembership("@bob:example.org", "BBBB"),
|
|
|
|
|
{
|
|
|
|
|
rawDisplayName: "Bob",
|
|
|
|
|
getMxcAvatarUrl: () => "mxc://dlskf",
|
2024-09-06 18:31:07 -04:00
|
|
|
},
|
2025-10-17 12:34:06 -04:00
|
|
|
mockLocalParticipant({}),
|
|
|
|
|
mockMediaDevices({}),
|
2024-09-06 18:31:07 -04:00
|
|
|
);
|
2025-10-17 12:34:06 -04:00
|
|
|
|
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
const toggleExpanded = vi.fn();
|
|
|
|
|
const { container } = render(
|
|
|
|
|
<SpotlightTile
|
|
|
|
|
vm={new SpotlightTileViewModel(constant([vm1, vm2]), constant(false))}
|
|
|
|
|
targetWidth={300}
|
|
|
|
|
targetHeight={200}
|
|
|
|
|
expanded={false}
|
|
|
|
|
onToggleExpanded={toggleExpanded}
|
|
|
|
|
showIndicators
|
|
|
|
|
focusable={true}
|
|
|
|
|
/>,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(await axe(container)).toHaveNoViolations();
|
|
|
|
|
// Alice should be in the spotlight, with her name and avatar on the
|
|
|
|
|
// first page
|
|
|
|
|
screen.getByText("Alice");
|
|
|
|
|
const aliceAvatar = screen.getByRole("img");
|
|
|
|
|
expect(screen.queryByRole("button", { name: "common.back" })).toBe(null);
|
|
|
|
|
// Bob should be out of the spotlight, and therefore invisible
|
|
|
|
|
expect(isInaccessible(screen.getByText("Bob"))).toBe(true);
|
|
|
|
|
// Now navigate to Bob
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Next" }));
|
|
|
|
|
screen.getByText("Bob");
|
|
|
|
|
expect(screen.getByRole("img")).not.toBe(aliceAvatar);
|
|
|
|
|
expect(isInaccessible(screen.getByText("Alice"))).toBe(true);
|
|
|
|
|
// Can toggle whether the tile is expanded
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Expand" }));
|
|
|
|
|
expect(toggleExpanded).toHaveBeenCalled();
|
2024-09-06 18:31:07 -04:00
|
|
|
});
|