Handle SDKContextClass client initialisation internally (#34146)
* Handle SDKContextClass `client` initialisation internally Rather than via MatrixChat - this is predominantly for Lifecycle tests as they don't use a MatrixChat and it doesn't make much sense for this component to own this state. * Fix tests
This commit is contained in:
+8
-8
@@ -12,7 +12,7 @@ import { type EventTimeline, JoinRule, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { SDKContext } from "../../../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../../../src/contexts/SDKContextClass";
|
||||
import { TestSDKContext } from "../../../../TestSDKContext.ts";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../../test-utils";
|
||||
import {
|
||||
CallGuestLinkButton,
|
||||
@@ -26,7 +26,7 @@ import SettingsStore from "../../../../../../src/settings/SettingsStore";
|
||||
|
||||
describe("<CallGuestLinkButton />", () => {
|
||||
const roomId = "!room:server.org";
|
||||
let sdkContext!: SDKContextClass;
|
||||
let sdkContext!: TestSDKContext;
|
||||
let modalSpy: jest.SpyInstance;
|
||||
let modalResolve: (value: unknown[] | PromiseLike<unknown[]>) => void;
|
||||
let room: Room;
|
||||
@@ -78,8 +78,8 @@ describe("<CallGuestLinkButton />", () => {
|
||||
...mockClientMethodsUser(),
|
||||
sendStateEvent: jest.fn(),
|
||||
});
|
||||
sdkContext = new SDKContextClass();
|
||||
sdkContext.client = client;
|
||||
sdkContext = new TestSDKContext();
|
||||
sdkContext._client = client;
|
||||
const modalPromise = new Promise<unknown[]>((resolve) => {
|
||||
modalResolve = resolve;
|
||||
});
|
||||
@@ -94,7 +94,7 @@ describe("<CallGuestLinkButton />", () => {
|
||||
return oldGet(key);
|
||||
});
|
||||
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(true);
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||
jest.spyOn(sdkContext.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||
});
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
@@ -152,7 +152,7 @@ describe("<CallGuestLinkButton />", () => {
|
||||
|
||||
it("don't show external conference button if now guest spa link is configured", () => {
|
||||
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||
jest.spyOn(sdkContext.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||
|
||||
jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
|
||||
if (key === "element_call") {
|
||||
@@ -179,7 +179,7 @@ describe("<CallGuestLinkButton />", () => {
|
||||
|
||||
it("opens the share dialog with the correct share link in an encrypted room", () => {
|
||||
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||
jest.spyOn(sdkContext.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||
|
||||
getComponent(room);
|
||||
const modalSpy = jest.spyOn(Modal, "createDialog");
|
||||
@@ -201,7 +201,7 @@ describe("<CallGuestLinkButton />", () => {
|
||||
it("share dialog has correct link in an unencrypted room", () => {
|
||||
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
||||
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(false);
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||
jest.spyOn(sdkContext.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||
|
||||
getComponent(room);
|
||||
const modalSpy = jest.spyOn(Modal, "createDialog");
|
||||
|
||||
+4
-4
@@ -13,7 +13,7 @@ import { fireEvent, render, screen, waitFor } from "jest-matrix-react";
|
||||
|
||||
import { VideoRoomChatButton } from "../../../../../../src/components/views/rooms/RoomHeader/VideoRoomChatButton";
|
||||
import { SDKContext } from "../../../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../../../src/contexts/SDKContextClass";
|
||||
import { TestSDKContext } from "../../../../TestSDKContext.ts";
|
||||
import type RightPanelStore from "../../../../../../src/stores/right-panel/RightPanelStore";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../../test-utils";
|
||||
import { RoomNotificationState } from "../../../../../../src/stores/notifications/RoomNotificationState";
|
||||
@@ -23,7 +23,7 @@ import { RightPanelPhases } from "../../../../../../src/stores/right-panel/Right
|
||||
|
||||
describe("<VideoRoomChatButton />", () => {
|
||||
const roomId = "!room:server.org";
|
||||
let sdkContext!: SDKContextClass;
|
||||
let sdkContext!: TestSDKContext;
|
||||
let rightPanelStore!: MockedObject<RightPanelStore>;
|
||||
|
||||
/**
|
||||
@@ -59,8 +59,8 @@ describe("<VideoRoomChatButton />", () => {
|
||||
rightPanelStore = {
|
||||
showOrHidePhase: jest.fn(),
|
||||
} as unknown as MockedObject<RightPanelStore>;
|
||||
sdkContext = new SDKContextClass();
|
||||
sdkContext.client = client;
|
||||
sdkContext = new TestSDKContext();
|
||||
sdkContext._client = client;
|
||||
jest.spyOn(sdkContext, "rightPanelStore", "get").mockReturnValue(rightPanelStore);
|
||||
});
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ export async function renderMemberList(
|
||||
}
|
||||
|
||||
const context = new TestSDKContext();
|
||||
context.client = client;
|
||||
context._client = client;
|
||||
context.memberListStore.isPresenceEnabled = jest.fn().mockReturnValue(enablePresence);
|
||||
const root = render(
|
||||
<MatrixClientContext.Provider value={client}>
|
||||
|
||||
Reference in New Issue
Block a user