Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Commit e456782

Browse files
committed
Revert "try fix RoomHeader tests again by also mocking useParticipants"
This reverts commit f83093c.
1 parent f83093c commit e456782

2 files changed

Lines changed: 14 additions & 31 deletions

File tree

src/hooks/useCall.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ export const useConnectionState = (call: Call | null): ConnectionState =>
4242
);
4343

4444
export const useParticipants = (call: Call | null): Map<RoomMember, Set<string>> => {
45+
const participants = call?.participants;
4546
return useTypedEventEmitterState(
4647
call ?? undefined,
4748
CallEvent.Participants,
48-
useCallback((state) => state ?? call?.participants ?? new Map(), [call]),
49+
useCallback((state) => state ?? participants ?? new Map(), [participants]),
4950
);
5051
};
5152

test/unit-tests/components/views/rooms/RoomHeader/RoomHeader-test.tsx

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -554,19 +554,15 @@ describe("RoomHeader", () => {
554554
});
555555

556556
it("join button is shown if there is an ongoing call", async () => {
557-
const members = mockRoomMembers(room, 3);
558-
const participants = mockParticipants(members);
559-
jest.spyOn(UseCall, "useParticipants").mockReturnValue(participants);
557+
mockRoomMembers(room, 3);
560558
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
561559
render(<RoomHeader room={room} />, getWrapper());
562560
const joinButton = getByLabelText(document.body, "Join");
563561
expect(joinButton).not.toHaveAttribute("aria-disabled", "true");
564562
});
565563

566564
it("join button is disabled if there is an other ongoing call", async () => {
567-
const members = mockRoomMembers(room, 3);
568-
const participants = mockParticipants(members);
569-
jest.spyOn(UseCall, "useParticipants").mockReturnValue(participants);
565+
mockRoomMembers(room, 3);
570566
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
571567
jest.spyOn(CallStore.prototype, "connectedCalls", "get").mockReturnValue(
572568
new Set([{ roomId: "some_other_room" } as Call]),
@@ -586,9 +582,7 @@ describe("RoomHeader", () => {
586582
});
587583

588584
it("close lobby button is shown if there is an ongoing call but we are viewing the lobby", async () => {
589-
const members = mockRoomMembers(room, 3);
590-
const participants = mockParticipants(members);
591-
jest.spyOn(UseCall, "useParticipants").mockReturnValue(participants);
585+
mockRoomMembers(room, 3);
592586
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
593587
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
594588

@@ -798,32 +792,20 @@ describe("RoomHeader", () => {
798792
/**
799793
*
800794
* @param count the number of users to create
801-
* @returns the created members
802795
*/
803796
function mockRoomMembers(room: Room, count: number) {
804797
const members = Array(count)
805798
.fill(0)
806-
.map((_, index) => {
807-
const userId = `@user-${index}:example.org`;
808-
const member = new RoomMember(room.roomId, userId);
809-
member.name = `Member ${index}`;
810-
member.rawDisplayName = `Member ${index}`;
811-
member.membership = KnownMembership.Join;
812-
member.getAvatarUrl = () => `mxc://avatar.url/user-${index}.png`;
813-
member.getMxcAvatarUrl = () => `mxc://avatar.url/user-${index}.png`;
814-
return member;
815-
});
799+
.map((_, index) => ({
800+
userId: `@user-${index}:example.org`,
801+
name: `Member ${index}`,
802+
rawDisplayName: `Member ${index}`,
803+
roomId: room.roomId,
804+
membership: KnownMembership.Join,
805+
getAvatarUrl: () => `mxc://avatar.url/user-${index}.png`,
806+
getMxcAvatarUrl: () => `mxc://avatar.url/user-${index}.png`,
807+
}));
816808

817809
room.currentState.setJoinedMemberCount(members.length);
818810
room.getJoinedMembers = jest.fn().mockReturnValue(members);
819-
return members;
820-
}
821-
822-
/**
823-
* Creates a participants map from room members
824-
* @param members the room members to convert to participants
825-
* @returns Map of participants with device sets
826-
*/
827-
function mockParticipants(members: RoomMember[]): Map<RoomMember, Set<string>> {
828-
return new Map(members.map((member, index) => [member, new Set([`device${index + 1}`])]));
829811
}

0 commit comments

Comments
 (0)