Fix tests

This commit is contained in:
Half-Shot 2024-11-12 17:10:26 +00:00
parent 7a05ad9f79
commit 1d685bc44e
2 changed files with 8 additions and 9 deletions

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 { findByRole, getByRole, render } from "@testing-library/react";
import { act, FC } from "react"; import { act, FC } from "react";
import { describe, expect, test } from "vitest"; import { describe, expect, test } from "vitest";
import { RoomEvent } from "matrix-js-sdk/src/matrix"; import { RoomEvent } from "matrix-js-sdk/src/matrix";
@ -43,7 +43,7 @@ const TestComponent: FC = () => {
<div> <div>
<ul> <ul>
{Object.entries(raisedHands).map(([userId, date]) => ( {Object.entries(raisedHands).map(([userId, date]) => (
<li key={userId}> <li role="listitem" key={userId}>
<span>{userId}</span> <span>{userId}</span>
<time>{date.getTime()}</time> <time>{date.getTime()}</time>
</li> </li>
@ -106,12 +106,12 @@ describe("useReactions", () => {
createHandRaisedReaction(memberEventAlice, membership), createHandRaisedReaction(memberEventAlice, membership),
]); ]);
const rtcSession = new MockRTCSession(room, membership); const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render( const { findByRole } = render(
<TestReactionsWrapper rtcSession={rtcSession}> <TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent /> <TestComponent />
</TestReactionsWrapper>, </TestReactionsWrapper>,
); );
expect(queryByRole("list")?.children).to.have.lengthOf(1); expect(findByRole("listitem")).toBeTruthy();
}); });
// 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.
@ -120,12 +120,12 @@ describe("useReactions", () => {
createHandRaisedReaction(memberEventAlice, membership), createHandRaisedReaction(memberEventAlice, membership),
]); ]);
const rtcSession = new MockRTCSession(room, membership); const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render( const { findByRole, queryByRole } = render(
<TestReactionsWrapper rtcSession={rtcSession}> <TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent /> <TestComponent />
</TestReactionsWrapper>, </TestReactionsWrapper>,
); );
expect(queryByRole("list")?.children).to.have.lengthOf(1); expect(findByRole("listitem")).toBeTruthy();
act(() => rtcSession.testRemoveMember(memberUserIdAlice)); act(() => rtcSession.testRemoveMember(memberUserIdAlice));
expect(queryByRole("list")?.children).to.have.lengthOf(0); expect(queryByRole("list")?.children).to.have.lengthOf(0);
}); });
@ -134,12 +134,12 @@ describe("useReactions", () => {
createHandRaisedReaction(memberEventAlice, membership), createHandRaisedReaction(memberEventAlice, membership),
]); ]);
const rtcSession = new MockRTCSession(room, membership); const rtcSession = new MockRTCSession(room, membership);
const { queryByRole } = render( const { queryByRole, findByRole } = render(
<TestReactionsWrapper rtcSession={rtcSession}> <TestReactionsWrapper rtcSession={rtcSession}>
<TestComponent /> <TestComponent />
</TestReactionsWrapper>, </TestReactionsWrapper>,
); );
expect(queryByRole("list")?.children).to.have.lengthOf(1); expect(findByRole("listitem")).toBeTruthy();
// Simulate leaving and rejoining // Simulate leaving and rejoining
act(() => { act(() => {
rtcSession.testRemoveMember(memberUserIdAlice); rtcSession.testRemoveMember(memberUserIdAlice);

View File

@ -143,7 +143,6 @@ export const ReactionsProvider = ({
); );
allEvents = res.chunk.map((e) => new MatrixEvent(e)); allEvents = res.chunk.map((e) => new MatrixEvent(e));
} }
return allEvents.find( return allEvents.find(
(reaction) => (reaction) =>
reaction.event.sender === expectedSender && reaction.event.sender === expectedSender &&