Fix types for MockRTCSession

This commit is contained in:
Hugh Nimmo-Smith
2024-12-06 17:10:25 +00:00
parent 9da1c83847
commit 596a574254
5 changed files with 27 additions and 65 deletions

View File

@@ -10,7 +10,6 @@ import { expect, test } from "vitest";
import { TooltipProvider } from "@vector-im/compound-web";
import { userEvent } from "@testing-library/user-event";
import { ReactNode } from "react";
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
import {
MockRoom,
@@ -30,7 +29,7 @@ const membership: Record<string, string> = {
function TestComponent({
rtcSession,
}: {
rtcSession: MatrixRTCSession;
rtcSession: MockRTCSession;
}): ReactNode {
return (
<TooltipProvider>
@@ -46,7 +45,7 @@ test("Can open menu", async () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { getByLabelText, container } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
<TestComponent rtcSession={rtcSession} />,
);
await user.click(getByLabelText("common.reactions"));
expect(container).toMatchSnapshot();
@@ -57,7 +56,7 @@ test("Can raise hand", async () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { getByLabelText, container } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
<TestComponent rtcSession={rtcSession} />,
);
await user.click(getByLabelText("common.reactions"));
await user.click(getByLabelText("action.raise_hand"));
@@ -82,7 +81,7 @@ test("Can lower hand", async () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { getByLabelText, container } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
<TestComponent rtcSession={rtcSession} />,
);
const reactionEvent = room.testSendHandRaise(memberEventAlice, membership);
await user.click(getByLabelText("common.reactions"));
@@ -96,7 +95,7 @@ test("Can react with emoji", async () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { getByLabelText, getByText } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
<TestComponent rtcSession={rtcSession} />,
);
await user.click(getByLabelText("common.reactions"));
await user.click(getByText("🐶"));
@@ -121,7 +120,7 @@ test("Can fully expand emoji picker", async () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { getByText, container, getByLabelText } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
<TestComponent rtcSession={rtcSession} />,
);
await user.click(getByLabelText("common.reactions"));
await user.click(getByLabelText("action.show_more"));
@@ -149,7 +148,7 @@ test("Can close reaction dialog", async () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { getByLabelText, container } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
<TestComponent rtcSession={rtcSession} />,
);
await user.click(getByLabelText("common.reactions"));
await user.click(getByLabelText("action.show_more"));

View File

@@ -18,7 +18,6 @@ import {
import { TooltipProvider } from "@vector-im/compound-web";
import { act, ReactNode } from "react";
import { afterEach } from "node:test";
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
import {
MockRoom,
@@ -49,7 +48,7 @@ const membership: Record<string, string> = {
function TestComponent({
rtcSession,
}: {
rtcSession: MatrixRTCSession;
rtcSession: MockRTCSession;
}): ReactNode {
return (
<TooltipProvider>
@@ -92,9 +91,7 @@ test("preloads all audio elements", () => {
new MockRoom(memberUserIdAlice),
membership,
);
render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
render(<TestComponent rtcSession={rtcSession} />);
expect(prefetchSounds).toHaveBeenCalledOnce();
});
@@ -102,9 +99,7 @@ test("will play an audio sound when there is a reaction", () => {
playReactionsSound.setValue(true);
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
render(<TestComponent rtcSession={rtcSession} />);
// Find the first reaction with a sound effect
const chosenReaction = ReactionSet.find((r) => !!r.sound);
@@ -123,9 +118,7 @@ test("will play the generic audio sound when there is soundless reaction", () =>
playReactionsSound.setValue(true);
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
render(<TestComponent rtcSession={rtcSession} />);
// Find the first reaction with a sound effect
const chosenReaction = ReactionSet.find((r) => !r.sound);
@@ -145,9 +138,7 @@ test("will play multiple audio sounds when there are multiple different reaction
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
render(<TestComponent rtcSession={rtcSession} />);
// Find the first reaction with a sound effect
const [reaction1, reaction2] = ReactionSet.filter((r) => !!r.sound);

View File

@@ -40,9 +40,7 @@ function TestComponent({
}): ReactNode {
return (
<TooltipProvider>
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<ReactionsOverlay />
</TestReactionsWrapper>
</TooltipProvider>
@@ -59,9 +57,7 @@ test("defaults to showing no reactions", () => {
new MockRoom(memberUserIdAlice),
membership,
);
const { container } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
const { container } = render(<TestComponent rtcSession={rtcSession} />);
expect(container.getElementsByTagName("span")).toHaveLength(0);
});
@@ -70,9 +66,7 @@ test("shows a reaction when sent", () => {
const reaction = ReactionSet[0];
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { getByRole } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
const { getByRole } = render(<TestComponent rtcSession={rtcSession} />);
act(() => {
room.testSendReaction(memberEventAlice, reaction, membership);
});
@@ -86,9 +80,7 @@ test("shows two of the same reaction when sent", () => {
const reaction = ReactionSet[0];
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { getAllByRole } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
const { getAllByRole } = render(<TestComponent rtcSession={rtcSession} />);
act(() => {
room.testSendReaction(memberEventAlice, reaction, membership);
});
@@ -103,9 +95,7 @@ test("shows two different reactions when sent", () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const [reactionA, reactionB] = ReactionSet;
const { getAllByRole } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
const { getAllByRole } = render(<TestComponent rtcSession={rtcSession} />);
act(() => {
room.testSendReaction(memberEventAlice, reactionA, membership);
});
@@ -125,8 +115,6 @@ test("hides reactions when reaction animations are disabled", () => {
act(() => {
room.testSendReaction(memberEventAlice, reaction, membership);
});
const { container } = render(
<TestComponent rtcSession={rtcSession as unknown as MatrixRTCSession} />,
);
const { container } = render(<TestComponent rtcSession={rtcSession} />);
expect(container.getElementsByTagName("span")).toHaveLength(0);
});

View File

@@ -60,9 +60,7 @@ describe("useReactions", () => {
membership,
);
const { queryByRole } = render(
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent />
</TestReactionsWrapper>,
);
@@ -72,9 +70,7 @@ describe("useReactions", () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render(
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent />
</TestReactionsWrapper>,
);
@@ -87,9 +83,7 @@ describe("useReactions", () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render(
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent />
</TestReactionsWrapper>,
);
@@ -113,9 +107,7 @@ describe("useReactions", () => {
]);
const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render(
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent />
</TestReactionsWrapper>,
);
@@ -129,9 +121,7 @@ describe("useReactions", () => {
]);
const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render(
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent />
</TestReactionsWrapper>,
);
@@ -145,9 +135,7 @@ describe("useReactions", () => {
]);
const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render(
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent />
</TestReactionsWrapper>,
);
@@ -165,9 +153,7 @@ describe("useReactions", () => {
]);
const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render(
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent />
</TestReactionsWrapper>,
);
@@ -177,9 +163,7 @@ describe("useReactions", () => {
const room = new MockRoom(memberUserIdAlice);
const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render(
<TestReactionsWrapper
rtcSession={rtcSession as unknown as MatrixRTCSession}
>
<TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent />
</TestReactionsWrapper>,
);

View File

@@ -32,7 +32,7 @@ export const TestReactionsWrapper = ({
rtcSession,
children,
}: PropsWithChildren<{
rtcSession: MatrixRTCSession;
rtcSession: MockRTCSession | MatrixRTCSession;
}>): ReactNode => {
return (
<ReactionsProvider rtcSession={rtcSession as unknown as MatrixRTCSession}>