Skip to content

Commit 644be31

Browse files
committed
Mock the call store rather than the hook
1 parent 92034aa commit 644be31

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import * as ShieldUtils from "../../../../../../src/utils/ShieldUtils";
5252
import { Container, WidgetLayoutStore } from "../../../../../../src/stores/widgets/WidgetLayoutStore";
5353
import MatrixClientContext from "../../../../../../src/contexts/MatrixClientContext";
5454
import { _t } from "../../../../../../src/languageHandler";
55-
import * as UseCall from "../../../../../../src/hooks/useCall";
5655
import { SdkContextClass } from "../../../../../../src/contexts/SDKContext";
5756
import WidgetStore, { type IApp } from "../../../../../../src/stores/WidgetStore";
5857
import { UIFeature } from "../../../../../../src/settings/UIFeature";
@@ -97,8 +96,9 @@ describe("RoomHeader", () => {
9796
setCardSpy = jest.spyOn(RightPanelStore.instance, "setCard");
9897
jest.spyOn(ShieldUtils, "shieldStatusForRoom").mockResolvedValue(ShieldUtils.E2EStatus.Normal);
9998

100-
// Mock useCall to return a Call object with stable participants to prevent React dependency errors
101-
jest.spyOn(UseCall, 'useCall').mockReturnValue(createMockCall());
99+
// Mock CallStore.instance.getCall to return a Call object with stable participants
100+
// This prevents React dependency errors without disrupting hook execution order
101+
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(createMockCall());
102102
});
103103

104104
afterEach(() => {
@@ -558,17 +558,17 @@ describe("RoomHeader", () => {
558558

559559
it("join button is shown if there is an ongoing call", async () => {
560560
mockRoomMembers(room, 3);
561-
// Mock a call with 3 participants instead of mocking useParticipantCount
562-
jest.spyOn(UseCall, 'useCall').mockReturnValue(createMockCall(ROOM_ID, 3));
561+
// Mock CallStore to return a call with 3 participants
562+
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(createMockCall(ROOM_ID, 3));
563563
render(<RoomHeader room={room} />, getWrapper());
564564
const joinButton = getByLabelText(document.body, "Join");
565565
expect(joinButton).not.toHaveAttribute("aria-disabled", "true");
566566
});
567567

568568
it("join button is disabled if there is an other ongoing call", async () => {
569569
mockRoomMembers(room, 3);
570-
// Mock a call with 3 participants instead of mocking useParticipantCount
571-
jest.spyOn(UseCall, 'useCall').mockReturnValue(createMockCall(ROOM_ID, 3));
570+
// Mock CallStore to return a call with 3 participants
571+
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(createMockCall(ROOM_ID, 3));
572572
jest.spyOn(CallStore.prototype, "connectedCalls", "get").mockReturnValue(
573573
new Set([{ roomId: "some_other_room" } as Call]),
574574
);
@@ -588,8 +588,8 @@ describe("RoomHeader", () => {
588588

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

595595
render(<RoomHeader room={room} />, getWrapper());

0 commit comments

Comments
 (0)