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:
@@ -33,6 +33,7 @@ import { type IConfigOptions } from "../../../../../src/IConfigOptions";
|
||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
||||
import { type IProfileInfo } from "../../../../../src/hooks/useProfileInfo";
|
||||
import { DirectoryMember, startDmOnFirstMessage } from "../../../../../src/utils/direct-messages";
|
||||
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||
|
||||
const mockGetAccessToken = jest.fn().mockResolvedValue("getAccessToken");
|
||||
jest.mock("../../../../../src/IdentityAuthClient", () =>
|
||||
@@ -94,6 +95,7 @@ const bobProfileInfo: IProfileInfo = {
|
||||
describe("InviteDialog", () => {
|
||||
let mockClient: Mocked<MatrixClient>;
|
||||
let room: Room;
|
||||
let sdkContext: TestSDKContext;
|
||||
|
||||
filterConsole(
|
||||
"Error retrieving profile for userId @carol:example.com",
|
||||
@@ -178,13 +180,15 @@ describe("InviteDialog", () => {
|
||||
mockClient.getRooms.mockReturnValue([room]);
|
||||
mockClient.getRoom.mockReturnValue(room);
|
||||
|
||||
SDKContextClass.instance.client = mockClient;
|
||||
sdkContext = new TestSDKContext();
|
||||
// @ts-ignore UserMenuViewModel uses SDKContext in the constructor
|
||||
SDKContextClass.instance = sdkContext;
|
||||
sdkContext._client = mockClient;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await clearAllModals();
|
||||
SDKContextClass.instance.onLoggedOut();
|
||||
SDKContextClass.instance.client = undefined;
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
||||
@@ -24,7 +24,7 @@ import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext
|
||||
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||
import { UIFeature } from "../../../../../src/settings/UIFeature";
|
||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
||||
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||
|
||||
describe("<RoomSettingsDialog />", () => {
|
||||
const userId = "@alice:server.org";
|
||||
@@ -44,7 +44,7 @@ describe("<RoomSettingsDialog />", () => {
|
||||
const room2 = new Room("!room2:server.org", mockClient, userId);
|
||||
room2.name = "Another Room";
|
||||
|
||||
let sdkContext: SDKContextClass;
|
||||
let sdkContext: TestSDKContext;
|
||||
|
||||
jest.spyOn(SettingsStore, "getValue");
|
||||
|
||||
@@ -57,8 +57,8 @@ describe("<RoomSettingsDialog />", () => {
|
||||
return null;
|
||||
});
|
||||
|
||||
sdkContext = new SDKContextClass();
|
||||
sdkContext.client = mockClient;
|
||||
sdkContext = new TestSDKContext();
|
||||
sdkContext._client = mockClient;
|
||||
|
||||
jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
} from "../../../../test-utils";
|
||||
import { UIFeature } from "../../../../../src/settings/UIFeature";
|
||||
import { SettingLevel } from "../../../../../src/settings/SettingLevel";
|
||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
||||
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||
import { type FeatureSettingKey } from "../../../../../src/settings/Settings.tsx";
|
||||
import { mockOpenIdConfiguration } from "../../../../test-utils/oidc.ts";
|
||||
|
||||
@@ -57,7 +57,7 @@ describe("<UserSettingsDialog />", () => {
|
||||
const mockSettingsStore = mocked(SettingsStore);
|
||||
let mockClient!: MockedObject<MatrixClient>;
|
||||
|
||||
let sdkContext: SDKContextClass;
|
||||
let sdkContext: TestSDKContext;
|
||||
const defaultProps = { onFinished: jest.fn() };
|
||||
const getComponent = (
|
||||
props: Partial<typeof defaultProps & { initialTabId?: UserTab; props: Record<string, any> }> = {},
|
||||
@@ -76,8 +76,8 @@ describe("<UserSettingsDialog />", () => {
|
||||
getMediaConfig: jest.fn(),
|
||||
getAuthMetadata: jest.fn().mockResolvedValue(mockOpenIdConfiguration()),
|
||||
});
|
||||
sdkContext = new SDKContextClass();
|
||||
sdkContext.client = mockClient;
|
||||
sdkContext = new TestSDKContext();
|
||||
sdkContext._client = mockClient;
|
||||
mockSettingsStore.getValue.mockReturnValue(false);
|
||||
mockSettingsStore.getValueAt.mockReturnValue(false);
|
||||
mockSettingsStore.getFeatureSettingNames.mockReturnValue([]);
|
||||
|
||||
Reference in New Issue
Block a user