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:
@@ -34,7 +34,7 @@ import {
|
||||
WidgetLifecycle,
|
||||
} from "@matrix-org/react-sdk-module-api/lib/lifecycles/WidgetLifecycle";
|
||||
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { ElementWidgetDriver } from "../../../../src/stores/widgets/ElementWidgetDriver";
|
||||
import { mkEvent, stubClient } from "../../../test-utils";
|
||||
@@ -428,7 +428,7 @@ describe("ElementWidgetDriver", () => {
|
||||
});
|
||||
|
||||
it("reads related events from the current room", async () => {
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!this-room-id");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!this-room-id");
|
||||
|
||||
client.relations.mockResolvedValue({
|
||||
originalEvent: new MatrixEvent(),
|
||||
|
||||
@@ -38,7 +38,7 @@ import ActiveWidgetStore from "../../../../src/stores/ActiveWidgetStore";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
||||
import { type IApp } from "../../../../src/utils/WidgetUtils-types";
|
||||
import { ModalWidgetStore } from "../../../../src/stores/ModalWidgetStore";
|
||||
@@ -397,7 +397,7 @@ describe("WidgetMessaging as an account widget", () => {
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
// I give up, getting the return type of spyOn right is hopeless
|
||||
getRoomId = jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId") as unknown as MockedFunction<
|
||||
getRoomId = jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId") as unknown as MockedFunction<
|
||||
() => string | null
|
||||
>;
|
||||
getRoomId.mockReturnValue("!1:example.org");
|
||||
@@ -430,7 +430,7 @@ describe("WidgetMessaging as an account widget", () => {
|
||||
expect(messaging.setViewedRoomId).toHaveBeenCalledTimes(1);
|
||||
expect(messaging.setViewedRoomId).toHaveBeenLastCalledWith("!1:example.org");
|
||||
getRoomId.mockReturnValue("!2:example.org");
|
||||
SdkContextClass.instance.roomViewStore.emit(UPDATE_EVENT);
|
||||
SDKContextClass.instance.roomViewStore.emit(UPDATE_EVENT);
|
||||
expect(messaging.setViewedRoomId).toHaveBeenCalledTimes(2);
|
||||
expect(messaging.setViewedRoomId).toHaveBeenLastCalledWith("!2:example.org");
|
||||
});
|
||||
@@ -630,7 +630,7 @@ describe("WidgetMessaging action handling for stickerpicker", () => {
|
||||
const client = mocked(stubClient());
|
||||
room = mkRoom(client, "!1:example.org");
|
||||
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
|
||||
const getRoomId = jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId") as unknown as MockedFunction<
|
||||
const getRoomId = jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId") as unknown as MockedFunction<
|
||||
() => string | null
|
||||
>;
|
||||
getRoomId.mockReturnValue(room.roomId);
|
||||
|
||||
@@ -12,9 +12,9 @@ import { Widget, WidgetKind } from "matrix-widget-api";
|
||||
|
||||
import { OIDCState, WidgetPermissionStore } from "../../../../src/stores/widgets/WidgetPermissionStore";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
import { TestSdkContext } from "../../TestSdkContext";
|
||||
import { TestSDKContext } from "../../TestSDKContext";
|
||||
import { type SettingLevel } from "../../../../src/settings/SettingLevel";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||
import { stubClient } from "../../../test-utils";
|
||||
import { ElementWidgetDriver } from "../../../../src/stores/widgets/ElementWidgetDriver";
|
||||
import { WidgetType } from "../../../../src/widgets/WidgetType.ts";
|
||||
@@ -53,7 +53,7 @@ describe("WidgetPermissionStore", () => {
|
||||
},
|
||||
);
|
||||
mockClient = stubClient();
|
||||
const context = new TestSdkContext();
|
||||
const context = new TestSDKContext();
|
||||
context.client = mockClient;
|
||||
widgetPermissionStore = new WidgetPermissionStore(context);
|
||||
});
|
||||
@@ -85,8 +85,8 @@ describe("WidgetPermissionStore", () => {
|
||||
// check this is not the case for the entire account
|
||||
expect(widgetPermissionStore.getOIDCState(w, WidgetKind.Account, roomId)).toEqual(OIDCState.Unknown);
|
||||
});
|
||||
it("is created once in SdkContextClass", () => {
|
||||
const context = new SdkContextClass();
|
||||
it("is created once in SDKContextClass", () => {
|
||||
const context = new SDKContextClass();
|
||||
const store = context.widgetPermissionStore;
|
||||
expect(store).toBeDefined();
|
||||
const store2 = context.widgetPermissionStore;
|
||||
|
||||
Reference in New Issue
Block a user