Separate out SDKContext (#34053)
* Separate out SDKContext ...from SDKContextClass, as the comments hopefully explain. Also make the captitalisation consistent. * Adding the new file usually helps too * Fix import * More comment * Update the various imports of SDKContextClass * Also fix case of TestSDKContext * Update the mock
This commit is contained in:
@@ -31,7 +31,7 @@ import { SDKContext } from "../../../../src/contexts/SDKContext";
|
||||
import { StandardActions } from "../../../../src/notifications/StandardActions";
|
||||
import ResizeNotifier from "../../../../src/utils/ResizeNotifier";
|
||||
import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils";
|
||||
import { TestSdkContext } from "../../TestSdkContext";
|
||||
import { TestSDKContext } from "../../TestSDKContext";
|
||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
import { SettingLevel } from "../../../../src/settings/SettingLevel";
|
||||
@@ -80,7 +80,7 @@ describe("<LoggedInView />", () => {
|
||||
doesServerSupportExtendedProfiles: jest.fn().mockResolvedValue(true),
|
||||
});
|
||||
const mediaHandler = new MediaHandler(mockClient);
|
||||
const mockSdkContext = new TestSdkContext();
|
||||
const mockSdkContext = new TestSDKContext();
|
||||
|
||||
const defaultProps = {
|
||||
matrixClient: mockClient,
|
||||
|
||||
@@ -11,7 +11,8 @@ import { render, fireEvent } from "jest-matrix-react";
|
||||
|
||||
import MainSplit from "../../../../src/components/structures/MainSplit";
|
||||
import { PosthogAnalytics } from "../../../../src/PosthogAnalytics.ts";
|
||||
import { SDKContext, SdkContextClass } from "../../../../src/contexts/SDKContext.ts";
|
||||
import { SDKContext } from "../../../../src/contexts/SDKContext.ts";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
|
||||
describe("<MainSplit/>", () => {
|
||||
const children = (
|
||||
@@ -20,11 +21,11 @@ describe("<MainSplit/>", () => {
|
||||
</div>
|
||||
);
|
||||
const panel = <div>Right panel</div>;
|
||||
let sdkContext: SdkContextClass;
|
||||
let sdkContext: SDKContextClass;
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
sdkContext = new SdkContextClass();
|
||||
sdkContext = new SDKContextClass();
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
|
||||
@@ -70,7 +70,7 @@ import { ShareFormat } from "../../../../src/dispatcher/payloads/SharePayload.ts
|
||||
import { clearStorage } from "../../../../src/Lifecycle";
|
||||
import RoomListStore from "../../../../src/stores/room-list/RoomListStore.ts";
|
||||
import UserSettingsDialog from "../../../../src/components/views/dialogs/UserSettingsDialog.tsx";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext.ts";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import { makeDelegatedAuthConfig } from "../../../test-utils/oidc.ts";
|
||||
import { type QrLoginCredentials } from "../../../../src/components/views/auth/LoginWithQR.tsx";
|
||||
|
||||
@@ -322,24 +322,24 @@ describe("<MatrixChat />", () => {
|
||||
it("should notify resizenotifier when left panel hidden", async () => {
|
||||
getComponent();
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.resizeNotifier, "notifyLeftHandleResized");
|
||||
jest.spyOn(SDKContextClass.instance.resizeNotifier, "notifyLeftHandleResized");
|
||||
|
||||
defaultDispatcher.dispatch({ action: "hide_left_panel" });
|
||||
|
||||
await waitFor(() =>
|
||||
expect(mocked(SdkContextClass.instance.resizeNotifier.notifyLeftHandleResized)).toHaveBeenCalled(),
|
||||
expect(mocked(SDKContextClass.instance.resizeNotifier.notifyLeftHandleResized)).toHaveBeenCalled(),
|
||||
);
|
||||
});
|
||||
|
||||
it("should notify resizenotifier when left panel shown", async () => {
|
||||
getComponent();
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.resizeNotifier, "notifyLeftHandleResized");
|
||||
jest.spyOn(SDKContextClass.instance.resizeNotifier, "notifyLeftHandleResized");
|
||||
|
||||
defaultDispatcher.dispatch({ action: "show_left_panel" });
|
||||
|
||||
await waitFor(() =>
|
||||
expect(mocked(SdkContextClass.instance.resizeNotifier.notifyLeftHandleResized)).toHaveBeenCalled(),
|
||||
expect(mocked(SDKContextClass.instance.resizeNotifier.notifyLeftHandleResized)).toHaveBeenCalled(),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -823,7 +823,7 @@ describe("<MatrixChat />", () => {
|
||||
await waitFor(() =>
|
||||
expect(createDialog).toHaveBeenCalledWith(
|
||||
UserSettingsDialog,
|
||||
{ initialTabId: UserTab.SessionManager, sdkContext: expect.any(SdkContextClass) },
|
||||
{ initialTabId: UserTab.SessionManager, sdkContext: expect.any(SDKContextClass) },
|
||||
/*className=*/ undefined,
|
||||
/*isPriority=*/ false,
|
||||
/*isStatic=*/ true,
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
import type ResizeNotifier from "../../../../src/utils/ResizeNotifier";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { ScopedRoomContextProvider } from "../../../../src/contexts/ScopedRoomContext.tsx";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext.ts";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
|
||||
jest.mock("../../../../src/utils/beacon", () => ({
|
||||
useBeacon: jest.fn(),
|
||||
@@ -54,7 +54,7 @@ describe("MessagePanel", function () {
|
||||
getClientWellKnown: jest.fn().mockReturnValue({}),
|
||||
supportsThreads: jest.fn().mockReturnValue(true),
|
||||
});
|
||||
let sdkContext: SdkContextClass;
|
||||
let sdkContext: SDKContextClass;
|
||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(client);
|
||||
|
||||
const room = new Room(roomId, client, userId);
|
||||
@@ -106,7 +106,7 @@ describe("MessagePanel", function () {
|
||||
return arg === "showDisplaynameChanges";
|
||||
});
|
||||
|
||||
sdkContext = new SdkContextClass();
|
||||
sdkContext = new SDKContextClass();
|
||||
|
||||
DMRoomMap.makeShared(client);
|
||||
});
|
||||
|
||||
@@ -41,12 +41,12 @@ import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
import { type ViewRoomPayload } from "../../../../src/dispatcher/payloads/ViewRoomPayload";
|
||||
import { TestSdkContext } from "../../TestSdkContext";
|
||||
import { TestSDKContext } from "../../TestSDKContext";
|
||||
import { RoomViewStore } from "../../../../src/stores/RoomViewStore";
|
||||
import { WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
|
||||
import WidgetStore from "../../../../src/stores/WidgetStore";
|
||||
import { WidgetType } from "../../../../src/widgets/WidgetType";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import { type WidgetMessaging } from "../../../../src/stores/widgets/WidgetMessaging";
|
||||
|
||||
jest.mock("../../../../src/stores/OwnProfileStore", () => ({
|
||||
@@ -65,7 +65,7 @@ describe("PipContainer", () => {
|
||||
jest.spyOn(HTMLMediaElement.prototype, "play").mockImplementation(async () => {});
|
||||
|
||||
let user: UserEvent;
|
||||
let sdkContext: TestSdkContext;
|
||||
let sdkContext: TestSDKContext;
|
||||
let client: Mocked<MatrixClient>;
|
||||
let room: Room;
|
||||
let room2: Room;
|
||||
@@ -109,9 +109,9 @@ describe("PipContainer", () => {
|
||||
),
|
||||
);
|
||||
|
||||
sdkContext = new TestSdkContext();
|
||||
sdkContext = new TestSDKContext();
|
||||
// @ts-ignore PipContainer uses SDKContext in the constructor
|
||||
SdkContextClass.instance = sdkContext;
|
||||
SDKContextClass.instance = sdkContext;
|
||||
sdkContext.client = client;
|
||||
});
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelS
|
||||
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
|
||||
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
||||
import { WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
||||
|
||||
const RightPanelBase = wrapInMatrixClientContext(_RightPanel);
|
||||
@@ -32,13 +32,13 @@ describe("RightPanel", () => {
|
||||
const resizeNotifier = new ResizeNotifier();
|
||||
|
||||
let cli: MockedObject<MatrixClient>;
|
||||
let context: SdkContextClass;
|
||||
let context: SDKContextClass;
|
||||
let RightPanel: React.ComponentType<React.ComponentProps<typeof RightPanelBase>>;
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
cli = mocked(MatrixClientPeg.safeGet());
|
||||
DMRoomMap.makeShared(cli);
|
||||
context = new SdkContextClass();
|
||||
context = new SDKContextClass();
|
||||
context.client = cli;
|
||||
RightPanel = wrapInSdkContext(RightPanelBase, context);
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ import { clientAndSDKContextRenderOptions, stubClient } from "../../../test-util
|
||||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { searchPagination, SearchScope } from "../../../../src/Searching";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore.ts";
|
||||
import { SettingLevel } from "../../../../src/settings/SettingLevel.ts";
|
||||
|
||||
@@ -36,13 +36,13 @@ jest.mock("../../../../src/Searching", () => ({
|
||||
describe("<RoomSearchView/>", () => {
|
||||
const eventMapper = (obj: Partial<IEvent>) => new MatrixEvent(obj);
|
||||
let client: MatrixClient;
|
||||
let sdkContext: SdkContextClass;
|
||||
let sdkContext: SDKContextClass;
|
||||
let room: Room;
|
||||
|
||||
beforeEach(async () => {
|
||||
stubClient();
|
||||
client = MatrixClientPeg.safeGet();
|
||||
sdkContext = new SdkContextClass();
|
||||
sdkContext = new SDKContextClass();
|
||||
client.supportsThreads = jest.fn().mockReturnValue(true);
|
||||
room = new Room("!room:server", client, client.getSafeUserId());
|
||||
mocked(client.getRoom).mockReturnValue(room);
|
||||
|
||||
@@ -55,7 +55,8 @@ import { type LocalRoom, LocalRoomState } from "../../../../src/models/LocalRoom
|
||||
import { DirectoryMember } from "../../../../src/utils/direct-messages";
|
||||
import { createDmLocalRoom } from "../../../../src/utils/dm/createDmLocalRoom";
|
||||
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
||||
import { SDKContext, SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContext } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import WidgetUtils from "../../../../src/utils/WidgetUtils";
|
||||
import { WidgetType } from "../../../../src/widgets/WidgetType";
|
||||
import WidgetStore from "../../../../src/stores/WidgetStore";
|
||||
@@ -85,7 +86,7 @@ describe("RoomView", () => {
|
||||
let cli: MockedObject<MatrixClient>;
|
||||
let room: Room;
|
||||
let rooms: Map<string, Room>;
|
||||
let stores: SdkContextClass;
|
||||
let stores: SDKContextClass;
|
||||
let crypto: CryptoApi;
|
||||
|
||||
// mute some noise
|
||||
@@ -110,7 +111,7 @@ describe("RoomView", () => {
|
||||
room.on(RoomEvent.TimelineReset, (...args) => cli.emit(RoomEvent.TimelineReset, ...args));
|
||||
|
||||
DMRoomMap.makeShared(cli);
|
||||
stores = new SdkContextClass();
|
||||
stores = new SDKContextClass();
|
||||
stores.client = cli;
|
||||
stores.rightPanelStore.useUnitTestClient(cli);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import React, { useState } from "react";
|
||||
|
||||
import ThreadView from "../../../../src/components/structures/ThreadView";
|
||||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
import dispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
@@ -190,18 +190,18 @@ describe("ThreadView", () => {
|
||||
});
|
||||
|
||||
it("sets the correct thread in the room view store", async () => {
|
||||
// expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBeNull();
|
||||
// expect(SDKContextClass.instance.roomViewStore.getThreadId()).toBeNull();
|
||||
const { unmount } = await getComponent();
|
||||
waitFor(() => {
|
||||
expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBe(rootEvent.getId());
|
||||
expect(SDKContextClass.instance.roomViewStore.getThreadId()).toBe(rootEvent.getId());
|
||||
});
|
||||
|
||||
unmount();
|
||||
await waitFor(() => expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBeNull());
|
||||
await waitFor(() => expect(SDKContextClass.instance.roomViewStore.getThreadId()).toBeNull());
|
||||
});
|
||||
|
||||
it("clears highlight message in the room view store", async () => {
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(room.roomId);
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(room.roomId);
|
||||
const mock = jest.spyOn(dispatcher, "dispatch");
|
||||
const { unmount } = await getComponent(rootEvent);
|
||||
mock.mockClear();
|
||||
|
||||
@@ -52,7 +52,7 @@ import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
import { SettingLevel } from "../../../../src/settings/SettingLevel";
|
||||
import MatrixClientBackedController from "../../../../src/settings/controllers/MatrixClientBackedController";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import type Timer from "../../../../src/utils/Timer";
|
||||
|
||||
// ScrollPanel calls this, but jsdom doesn't mock it for us
|
||||
@@ -162,7 +162,7 @@ const setupPagination = (
|
||||
|
||||
describe("TimelinePanel", () => {
|
||||
let client: Mocked<MatrixClient>;
|
||||
let sdkContext: SdkContextClass;
|
||||
let sdkContext: SDKContextClass;
|
||||
let userId: string;
|
||||
|
||||
filterConsole("checkForPreJoinUISI: showing all messages, skipping check");
|
||||
@@ -170,7 +170,7 @@ describe("TimelinePanel", () => {
|
||||
beforeEach(() => {
|
||||
client = mocked(stubClient());
|
||||
userId = client.getSafeUserId();
|
||||
sdkContext = new SdkContextClass();
|
||||
sdkContext = new SDKContextClass();
|
||||
});
|
||||
|
||||
describe("read receipts and markers", () => {
|
||||
|
||||
Reference in New Issue
Block a user