Skip to content

Commit 92034aa

Browse files
committed
try mocking useCall rather than just useParticipantCount
1 parent fb502a6 commit 92034aa

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ describe("RoomHeader", () => {
9696

9797
setCardSpy = jest.spyOn(RightPanelStore.instance, "setCard");
9898
jest.spyOn(ShieldUtils, "shieldStatusForRoom").mockResolvedValue(ShieldUtils.E2EStatus.Normal);
99+
100+
// Mock useCall to return a Call object with stable participants to prevent React dependency errors
101+
jest.spyOn(UseCall, 'useCall').mockReturnValue(createMockCall());
99102
});
100103

101104
afterEach(() => {
@@ -555,15 +558,17 @@ describe("RoomHeader", () => {
555558

556559
it("join button is shown if there is an ongoing call", async () => {
557560
mockRoomMembers(room, 3);
558-
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
561+
// Mock a call with 3 participants instead of mocking useParticipantCount
562+
jest.spyOn(UseCall, 'useCall').mockReturnValue(createMockCall(ROOM_ID, 3));
559563
render(<RoomHeader room={room} />, getWrapper());
560564
const joinButton = getByLabelText(document.body, "Join");
561565
expect(joinButton).not.toHaveAttribute("aria-disabled", "true");
562566
});
563567

564568
it("join button is disabled if there is an other ongoing call", async () => {
565569
mockRoomMembers(room, 3);
566-
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
570+
// Mock a call with 3 participants instead of mocking useParticipantCount
571+
jest.spyOn(UseCall, 'useCall').mockReturnValue(createMockCall(ROOM_ID, 3));
567572
jest.spyOn(CallStore.prototype, "connectedCalls", "get").mockReturnValue(
568573
new Set([{ roomId: "some_other_room" } as Call]),
569574
);
@@ -583,7 +588,8 @@ describe("RoomHeader", () => {
583588

584589
it("close lobby button is shown if there is an ongoing call but we are viewing the lobby", async () => {
585590
mockRoomMembers(room, 3);
586-
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
591+
// Mock a call with 3 participants instead of mocking useParticipantCount
592+
jest.spyOn(UseCall, 'useCall').mockReturnValue(createMockCall(ROOM_ID, 3));
587593
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
588594

589595
render(<RoomHeader room={room} />, getWrapper());
@@ -789,6 +795,34 @@ describe("RoomHeader", () => {
789795
});
790796
});
791797

798+
/**
799+
* Creates a mock Call object with stable participants to prevent React dependency errors
800+
*/
801+
function createMockCall(roomId: string = "!1:example.org", participantCount: number = 0): Call {
802+
const participants = new Map();
803+
804+
// Create mock participants with devices
805+
for (let i = 0; i < participantCount; i++) {
806+
const mockMember = {
807+
userId: `@user-${i}:example.org`,
808+
name: `Member ${i}`,
809+
} as RoomMember;
810+
811+
const deviceSet = new Set([`device-${i}`]);
812+
participants.set(mockMember, deviceSet);
813+
}
814+
815+
return {
816+
roomId,
817+
participants,
818+
widget: { id: "test-widget" },
819+
connectionState: "disconnected",
820+
on: jest.fn(),
821+
off: jest.fn(),
822+
emit: jest.fn(),
823+
} as unknown as Call;
824+
}
825+
792826
/**
793827
*
794828
* @param count the number of users to create

0 commit comments

Comments
 (0)