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:
@@ -14,7 +14,7 @@ import SdkConfig from "../../../src/SdkConfig";
|
||||
import SettingsStore from "../../../src/settings/SettingsStore";
|
||||
import { MemberListStore } from "../../../src/stores/MemberListStore";
|
||||
import { stubClient } from "../../test-utils";
|
||||
import { TestSdkContext } from "../TestSdkContext";
|
||||
import { TestSDKContext } from "../TestSDKContext";
|
||||
|
||||
describe("MemberListStore", () => {
|
||||
const alice = "@alice:bar";
|
||||
@@ -26,7 +26,7 @@ describe("MemberListStore", () => {
|
||||
let room: Room;
|
||||
|
||||
beforeEach(() => {
|
||||
const context = new TestSdkContext();
|
||||
const context = new TestSDKContext();
|
||||
client = stubClient();
|
||||
client.baseUrl = "https://invalid.base.url.here";
|
||||
context.client = client;
|
||||
|
||||
@@ -9,14 +9,14 @@ import { MultiRoomViewStore } from "../../../src/stores/MultiRoomViewStore";
|
||||
import { RoomViewStore } from "../../../src/stores/RoomViewStore";
|
||||
import { Action } from "../../../src/dispatcher/actions";
|
||||
import type { MatrixDispatcher } from "../../../src/dispatcher/dispatcher";
|
||||
import { TestSdkContext } from "../TestSdkContext";
|
||||
import { TestSDKContext } from "../TestSDKContext";
|
||||
|
||||
jest.mock("../../../src/stores/RoomViewStore");
|
||||
|
||||
describe("MultiRoomViewStore", () => {
|
||||
let multiRoomViewStore: MultiRoomViewStore;
|
||||
let mockDispatcher: MatrixDispatcher;
|
||||
let mockSdkContext: TestSdkContext;
|
||||
let mockSdkContext: TestSDKContext;
|
||||
let mockRoomViewStore: jest.Mocked<RoomViewStore>;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -30,7 +30,7 @@ describe("MultiRoomViewStore", () => {
|
||||
} as unknown as MatrixDispatcher;
|
||||
|
||||
// Create mock SDK context
|
||||
mockSdkContext = new TestSdkContext();
|
||||
mockSdkContext = new TestSDKContext();
|
||||
|
||||
// Create mock RoomViewStore instance
|
||||
mockRoomViewStore = {
|
||||
|
||||
@@ -35,7 +35,7 @@ import { MatrixDispatcher } from "../../../src/dispatcher/dispatcher";
|
||||
import { UPDATE_EVENT } from "../../../src/stores/AsyncStore";
|
||||
import { type ActiveRoomChangedPayload } from "../../../src/dispatcher/payloads/ActiveRoomChangedPayload";
|
||||
import { SpaceStoreClass } from "../../../src/stores/spaces/SpaceStore";
|
||||
import { TestSdkContext } from "../TestSdkContext";
|
||||
import { TestSDKContext } from "../TestSDKContext";
|
||||
import { type ViewRoomPayload } from "../../../src/dispatcher/payloads/ViewRoomPayload";
|
||||
import Modal from "../../../src/Modal";
|
||||
import ErrorDialog from "../../../src/components/views/dialogs/ErrorDialog";
|
||||
@@ -175,7 +175,7 @@ describe("RoomViewStore", function () {
|
||||
let roomViewStore: RoomViewStore;
|
||||
let slidingSyncManager: SlidingSyncManager;
|
||||
let dis: MatrixDispatcher;
|
||||
let stores: TestSdkContext;
|
||||
let stores: TestSDKContext;
|
||||
|
||||
beforeEach(function () {
|
||||
jest.clearAllMocks();
|
||||
@@ -192,7 +192,7 @@ describe("RoomViewStore", function () {
|
||||
// Make the RVS to test
|
||||
dis = new MatrixDispatcher();
|
||||
slidingSyncManager = new MockSlidingSyncManager();
|
||||
stores = new TestSdkContext();
|
||||
stores = new TestSDKContext();
|
||||
stores.client = mockClient;
|
||||
stores._SlidingSyncManager = slidingSyncManager;
|
||||
stores._PosthogAnalytics = new MockPosthogAnalytics();
|
||||
|
||||
@@ -11,7 +11,7 @@ import { type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import TypingStore from "../../../src/stores/TypingStore";
|
||||
import { LOCAL_ROOM_ID_PREFIX } from "../../../src/models/LocalRoom";
|
||||
import SettingsStore from "../../../src/settings/SettingsStore";
|
||||
import { TestSdkContext } from "../TestSdkContext";
|
||||
import { TestSDKContext } from "../TestSDKContext";
|
||||
|
||||
jest.mock("../../../src/settings/SettingsStore", () => ({
|
||||
getValue: jest.fn(),
|
||||
@@ -29,7 +29,7 @@ describe("TypingStore", () => {
|
||||
mockClient = {
|
||||
sendTyping: jest.fn(),
|
||||
} as unknown as MatrixClient;
|
||||
const context = new TestSdkContext();
|
||||
const context = new TestSDKContext();
|
||||
context.client = mockClient;
|
||||
typingStore = new TypingStore(context);
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
|
||||
|
||||
@@ -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