Files
element-call/src/room/ReactionsOverlay.test.tsx

125 lines
3.6 KiB
TypeScript
Raw Normal View History

2024-11-11 12:07:02 +00:00
/*
Copyright 2024 New Vector Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
2024-11-11 12:07:02 +00:00
Please see LICENSE in the repository root for full details.
*/
import { render } from "@testing-library/react";
import { expect, test, afterEach, vi } from "vitest";
import { act } from "react";
2024-11-11 12:07:02 +00:00
2024-11-11 12:09:26 +00:00
import { showReactions } from "../settings/settings";
2024-11-11 12:07:02 +00:00
import { ReactionsOverlay } from "./ReactionsOverlay";
import { ReactionSet } from "../reactions";
import {
local,
alice,
aliceRtcMember,
bobRtcMember,
} from "../utils/test-fixtures";
import { getBasicCallViewModelEnvironment } from "../utils/test-viewmodel";
2026-01-22 19:38:39 +01:00
import { initializeWidget } from "../widget";
initializeWidget();
2024-11-11 12:07:02 +00:00
vi.mock("livekit-client/e2ee-worker?worker");
2024-11-11 12:07:02 +00:00
afterEach(() => {
showReactions.setValue(showReactions.defaultValue);
});
test("defaults to showing no reactions", () => {
showReactions.setValue(true);
const { vm } = getBasicCallViewModelEnvironment([local, alice]);
const { container } = render(<ReactionsOverlay vm={vm} />);
2024-11-11 12:09:26 +00:00
expect(container.getElementsByTagName("span")).toHaveLength(0);
2024-11-11 12:07:02 +00:00
});
test("shows a reaction when sent", () => {
showReactions.setValue(true);
const { vm, reactionsSubject$ } = getBasicCallViewModelEnvironment([
local,
alice,
]);
const { getByRole } = render(<ReactionsOverlay vm={vm} />);
2024-11-11 12:07:02 +00:00
const reaction = ReactionSet[0];
2024-11-11 12:09:26 +00:00
act(() => {
reactionsSubject$.next({
[aliceRtcMember.deviceId]: {
reactionOption: reaction,
expireAfter: new Date(0),
},
});
2024-11-11 12:09:26 +00:00
});
const span = getByRole("presentation");
expect(getByRole("presentation")).toBeTruthy();
2024-11-11 12:07:02 +00:00
expect(span.innerHTML).toEqual(reaction.emoji);
});
test("shows two of the same reaction when sent", () => {
showReactions.setValue(true);
2024-11-11 12:09:26 +00:00
const reaction = ReactionSet[0];
const { vm, reactionsSubject$ } = getBasicCallViewModelEnvironment([
local,
alice,
]);
const { getAllByRole } = render(<ReactionsOverlay vm={vm} />);
2024-11-11 12:09:26 +00:00
act(() => {
reactionsSubject$.next({
[aliceRtcMember.deviceId]: {
reactionOption: reaction,
expireAfter: new Date(0),
},
[bobRtcMember.deviceId]: {
reactionOption: reaction,
expireAfter: new Date(0),
},
});
2024-11-11 12:09:26 +00:00
});
expect(getAllByRole("presentation")).toHaveLength(2);
2024-11-11 12:07:02 +00:00
});
test("shows two different reactions when sent", () => {
showReactions.setValue(true);
const [reactionA, reactionB] = ReactionSet;
const { vm, reactionsSubject$ } = getBasicCallViewModelEnvironment([
local,
alice,
]);
const { getAllByRole } = render(<ReactionsOverlay vm={vm} />);
2024-11-11 12:09:26 +00:00
act(() => {
reactionsSubject$.next({
[aliceRtcMember.deviceId]: {
reactionOption: reactionA,
expireAfter: new Date(0),
},
[bobRtcMember.deviceId]: {
reactionOption: reactionB,
expireAfter: new Date(0),
},
});
2024-11-11 12:09:26 +00:00
});
const [reactionElementA, reactionElementB] = getAllByRole("presentation");
2024-11-11 12:07:02 +00:00
expect(reactionElementA.innerHTML).toEqual(reactionA.emoji);
expect(reactionElementB.innerHTML).toEqual(reactionB.emoji);
});
test("hides reactions when reaction animations are disabled", () => {
showReactions.setValue(false);
const reaction = ReactionSet[0];
const { vm, reactionsSubject$ } = getBasicCallViewModelEnvironment([
local,
alice,
]);
const { container } = render(<ReactionsOverlay vm={vm} />);
2024-11-11 12:09:26 +00:00
act(() => {
reactionsSubject$.next({
[aliceRtcMember.deviceId]: {
reactionOption: reaction,
expireAfter: new Date(0),
},
});
2024-11-11 12:09:26 +00:00
});
expect(container.getElementsByTagName("span")).toHaveLength(0);
});