Remove rerender

This commit is contained in:
Half-Shot
2024-10-31 15:24:44 +00:00
parent 2d95d4ff36
commit 7229f4bf1b

View File

@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
Please see LICENSE in the repository root for full details. Please see LICENSE in the repository root for full details.
*/ */
import { render } from "@testing-library/react"; import { act, render } from "@testing-library/react";
import { FC, ReactNode } from "react"; import { FC, ReactNode } from "react";
import { describe, expect, test } from "vitest"; import { describe, expect, test } from "vitest";
import { import {
@@ -164,45 +164,44 @@ describe("useReactions", () => {
); );
expect(queryByRole("list")?.children).to.have.lengthOf(0); expect(queryByRole("list")?.children).to.have.lengthOf(0);
}); });
test("handles own raised hand", () => { test("handles own raised hand", async () => {
const room = new MockRoom(); const room = new MockRoom();
const rtcSession = new MockRTCSession(room); const rtcSession = new MockRTCSession(room);
const { queryByText, rerender } = render( const { queryByText } = render(
<TestComponentWrapper rtcSession={rtcSession} />, <TestComponentWrapper rtcSession={rtcSession} />,
); );
room.testSendReaction(memberEventAlice); await act(() => room.testSendReaction(memberEventAlice));
rerender(<TestComponentWrapper rtcSession={rtcSession} />);
expect(queryByText("Local reaction")).toBeTruthy(); expect(queryByText("Local reaction")).toBeTruthy();
}); });
test("handles incoming raised hand", () => { test("handles incoming raised hand", async () => {
const room = new MockRoom(); const room = new MockRoom();
const rtcSession = new MockRTCSession(room); const rtcSession = new MockRTCSession(room);
const { queryByRole, rerender } = render( const { queryByRole } = render(
<TestComponentWrapper rtcSession={rtcSession} />, <TestComponentWrapper rtcSession={rtcSession} />,
); );
room.testSendReaction(memberEventAlice); await act(() => room.testSendReaction(memberEventAlice));
rerender(<TestComponentWrapper rtcSession={rtcSession} />);
expect(queryByRole("list")?.children).to.have.lengthOf(1); expect(queryByRole("list")?.children).to.have.lengthOf(1);
room.testSendReaction(memberEventBob); await act(() => room.testSendReaction(memberEventBob));
rerender(<TestComponentWrapper rtcSession={rtcSession} />);
expect(queryByRole("list")?.children).to.have.lengthOf(2); expect(queryByRole("list")?.children).to.have.lengthOf(2);
}); });
test("handles incoming unraised hand", () => { test("handles incoming unraised hand", async () => {
const room = new MockRoom(); const room = new MockRoom();
const rtcSession = new MockRTCSession(room); const rtcSession = new MockRTCSession(room);
const { queryByRole, rerender } = render( const { queryByRole } = render(
<TestComponentWrapper rtcSession={rtcSession} />, <TestComponentWrapper rtcSession={rtcSession} />,
); );
const reactionEventId = room.testSendReaction(memberEventAlice); const reactionEventId = await act(() =>
rerender(<TestComponentWrapper rtcSession={rtcSession} />); room.testSendReaction(memberEventAlice),
expect(queryByRole("list")?.children).to.have.lengthOf(1); );
room.emit( expect(queryByRole("list")?.children).to.have.lengthOf(1);
RoomEvent.Redaction, await act(() =>
createRedaction(memberUserIdAlice, reactionEventId), room.emit(
room, RoomEvent.Redaction,
undefined, createRedaction(memberUserIdAlice, reactionEventId),
room,
undefined,
),
); );
rerender(<TestComponentWrapper rtcSession={rtcSession} />);
expect(queryByRole("list")?.children).to.have.lengthOf(0); expect(queryByRole("list")?.children).to.have.lengthOf(0);
}); });
test("handles loading prior raised hand events", () => { test("handles loading prior raised hand events", () => {
@@ -215,28 +214,28 @@ describe("useReactions", () => {
}); });
// If the membership event changes for a user, we want to remove // If the membership event changes for a user, we want to remove
// the raised hand event. // the raised hand event.
test("will remove reaction when a member leaves the call", () => { test("will remove reaction when a member leaves the call", async () => {
const room = new MockRoom([createReaction(memberEventAlice)]); const room = new MockRoom([createReaction(memberEventAlice)]);
const rtcSession = new MockRTCSession(room); const rtcSession = new MockRTCSession(room);
const { queryByRole, rerender } = render( const { queryByRole } = render(
<TestComponentWrapper rtcSession={rtcSession} />, <TestComponentWrapper rtcSession={rtcSession} />,
); );
expect(queryByRole("list")?.children).to.have.lengthOf(1); expect(queryByRole("list")?.children).to.have.lengthOf(1);
rtcSession.testRemoveMember(memberUserIdAlice); await act(() => rtcSession.testRemoveMember(memberUserIdAlice));
rerender(<TestComponentWrapper rtcSession={rtcSession} />);
expect(queryByRole("list")?.children).to.have.lengthOf(0); expect(queryByRole("list")?.children).to.have.lengthOf(0);
}); });
test("will remove reaction when a member joins via a new event", () => { test("will remove reaction when a member joins via a new event", async () => {
const room = new MockRoom([createReaction(memberEventAlice)]); const room = new MockRoom([createReaction(memberEventAlice)]);
const rtcSession = new MockRTCSession(room); const rtcSession = new MockRTCSession(room);
const { queryByRole, rerender } = render( const { queryByRole } = render(
<TestComponentWrapper rtcSession={rtcSession} />, <TestComponentWrapper rtcSession={rtcSession} />,
); );
expect(queryByRole("list")?.children).to.have.lengthOf(1); expect(queryByRole("list")?.children).to.have.lengthOf(1);
// Simulate leaving and rejoining // Simulate leaving and rejoining
rtcSession.testRemoveMember(memberUserIdAlice); await act(() => {
rtcSession.testAddMember(memberUserIdAlice); rtcSession.testRemoveMember(memberUserIdAlice);
rerender(<TestComponentWrapper rtcSession={rtcSession} />); rtcSession.testAddMember(memberUserIdAlice);
});
expect(queryByRole("list")?.children).to.have.lengthOf(0); expect(queryByRole("list")?.children).to.have.lengthOf(0);
}); });
}); });