Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import * as ShieldUtils from "../../../../../../src/utils/ShieldUtils";
import { Container, WidgetLayoutStore } from "../../../../../../src/stores/widgets/WidgetLayoutStore";
import MatrixClientContext from "../../../../../../src/contexts/MatrixClientContext";
import { _t } from "../../../../../../src/languageHandler";
import * as UseCall from "../../../../../../src/hooks/useCall";
import { SdkContextClass } from "../../../../../../src/contexts/SDKContext";
import WidgetStore, { type IApp } from "../../../../../../src/stores/WidgetStore";
import { UIFeature } from "../../../../../../src/settings/UIFeature";
Expand Down Expand Up @@ -96,6 +95,10 @@ describe("RoomHeader", () => {

setCardSpy = jest.spyOn(RightPanelStore.instance, "setCard");
jest.spyOn(ShieldUtils, "shieldStatusForRoom").mockResolvedValue(ShieldUtils.E2EStatus.Normal);

// Mock CallStore.instance.getCall to return null by default
// Individual tests can override this when they need a specific Call object
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(null);
});

afterEach(() => {
Expand Down Expand Up @@ -555,15 +558,17 @@ describe("RoomHeader", () => {

it("join button is shown if there is an ongoing call", async () => {
mockRoomMembers(room, 3);
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
// Mock CallStore to return a call with 3 participants
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(createMockCall(ROOM_ID, 3));
render(<RoomHeader room={room} />, getWrapper());
const joinButton = getByLabelText(document.body, "Join");
expect(joinButton).not.toHaveAttribute("aria-disabled", "true");
});

it("join button is disabled if there is an other ongoing call", async () => {
mockRoomMembers(room, 3);
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
// Mock CallStore to return a call with 3 participants
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(createMockCall(ROOM_ID, 3));
jest.spyOn(CallStore.prototype, "connectedCalls", "get").mockReturnValue(
new Set([{ roomId: "some_other_room" } as Call]),
);
Expand All @@ -583,7 +588,8 @@ describe("RoomHeader", () => {

it("close lobby button is shown if there is an ongoing call but we are viewing the lobby", async () => {
mockRoomMembers(room, 3);
jest.spyOn(UseCall, "useParticipantCount").mockReturnValue(3);
// Mock CallStore to return a call with 3 participants
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(createMockCall(ROOM_ID, 3));
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);

render(<RoomHeader room={room} />, getWrapper());
Expand Down Expand Up @@ -789,6 +795,34 @@ describe("RoomHeader", () => {
});
});

/**
* Creates a mock Call object with stable participants to prevent React dependency errors
*/
function createMockCall(roomId: string = "!1:example.org", participantCount: number = 0): Call {
const participants = new Map();

// Create mock participants with devices
for (let i = 0; i < participantCount; i++) {
const mockMember = {
userId: `@user-${i}:example.org`,
name: `Member ${i}`,
} as RoomMember;

const deviceSet = new Set([`device-${i}`]);
participants.set(mockMember, deviceSet);
}

return {
roomId,
participants,
widget: { id: "test-widget" },
connectionState: "disconnected",
on: jest.fn(),
off: jest.fn(),
emit: jest.fn(),
} as unknown as Call;
}

/**
*
* @param count the number of users to create
Expand Down
Loading