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:
@@ -11,7 +11,7 @@ import type { MockedObject } from "jest-mock-vitest-adapter";
|
||||
import { UserMenuViewModel } from "../../../src/viewmodels/menus/UserMenuViewModel";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsServer, mockClientMethodsUser } from "../../test-utils";
|
||||
import { MatrixDispatcher } from "../../../src/dispatcher/dispatcher";
|
||||
import { SdkContextClass } from "../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../src/contexts/SDKContextClass";
|
||||
import SdkConfig from "../../../src/SdkConfig";
|
||||
import { Action } from "../../../src/dispatcher/actions";
|
||||
import { UserTab } from "../../../src/components/views/dialogs/UserTab";
|
||||
@@ -29,13 +29,13 @@ describe("UserMenuViewModel", () => {
|
||||
getAuthMetadata: jest.fn().mockRejectedValue(new MatrixError({ errcode: "M_UNRECOGNIZED" }, 404)),
|
||||
setExtendedProfileProperty: jest.fn().mockResolvedValue(undefined),
|
||||
});
|
||||
SdkContextClass.instance.client = client;
|
||||
SDKContextClass.instance.client = client;
|
||||
});
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
SdkConfig.reset();
|
||||
SdkContextClass.instance.onLoggedOut();
|
||||
SdkContextClass.instance.client = undefined;
|
||||
SDKContextClass.instance.onLoggedOut();
|
||||
SDKContextClass.instance.client = undefined;
|
||||
});
|
||||
|
||||
it("should generate a menu options for a logged in client", () => {
|
||||
|
||||
@@ -15,7 +15,7 @@ import SpaceStore from "../../../src/stores/spaces/SpaceStore";
|
||||
import { FilterEnum } from "../../../src/stores/room-list-v3/skip-list/filters";
|
||||
import dispatcher from "../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../src/dispatcher/actions";
|
||||
import { SdkContextClass } from "../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../src/contexts/SDKContextClass";
|
||||
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
||||
import { RoomListViewModel } from "../../../src/viewmodels/room-list/RoomListViewModel";
|
||||
import { hasCreateRoomRights } from "../../../src/viewmodels/room-list/utils";
|
||||
@@ -68,7 +68,7 @@ describe("RoomListViewModel", () => {
|
||||
|
||||
jest.spyOn(RoomListStoreV3.instance, "isLoadingRooms", "get").mockReturnValue(false);
|
||||
jest.spyOn(SpaceStore.instance, "activeSpaceRoom", "get").mockReturnValue(null);
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(null);
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(null);
|
||||
|
||||
mocked(hasCreateRoomRights).mockReturnValue(false);
|
||||
});
|
||||
@@ -223,7 +223,7 @@ describe("RoomListViewModel", () => {
|
||||
it("should update active room index when room is selected", async () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room2:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room2:server");
|
||||
|
||||
dispatcher.dispatch({
|
||||
action: Action.ActiveRoomChanged,
|
||||
@@ -239,7 +239,7 @@ describe("RoomListViewModel", () => {
|
||||
it("should return undefined active room index when no room is selected", async () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(null);
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(null);
|
||||
|
||||
dispatcher.dispatch({
|
||||
action: Action.ActiveRoomChanged,
|
||||
@@ -258,7 +258,7 @@ describe("RoomListViewModel", () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
// Select room at index 1
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room2:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room2:server");
|
||||
dispatcher.dispatch({
|
||||
action: Action.ActiveRoomChanged,
|
||||
newRoomId: "!room2:server",
|
||||
@@ -284,7 +284,7 @@ describe("RoomListViewModel", () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
// Select room at index 1
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room2:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room2:server");
|
||||
dispatcher.dispatch({
|
||||
action: Action.ActiveRoomChanged,
|
||||
newRoomId: "!room2:server",
|
||||
@@ -293,7 +293,7 @@ describe("RoomListViewModel", () => {
|
||||
await flushPromises();
|
||||
|
||||
// User switches to room3
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room3:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room3:server");
|
||||
dispatcher.dispatch({
|
||||
action: Action.ActiveRoomChanged,
|
||||
oldRoomId: "!room2:server",
|
||||
@@ -489,7 +489,7 @@ describe("RoomListViewModel", () => {
|
||||
it("should navigate to next room when delta is 1", async () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room1:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room1:server");
|
||||
|
||||
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
|
||||
|
||||
@@ -512,7 +512,7 @@ describe("RoomListViewModel", () => {
|
||||
it("should navigate to previous room when delta is -1", async () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room2:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room2:server");
|
||||
|
||||
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
|
||||
|
||||
@@ -535,7 +535,7 @@ describe("RoomListViewModel", () => {
|
||||
it("should wrap around to last room when navigating backwards from first room", async () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room1:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!room1:server");
|
||||
|
||||
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
|
||||
|
||||
@@ -558,7 +558,7 @@ describe("RoomListViewModel", () => {
|
||||
it("should not navigate when current room is not found", async () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!unknown:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!unknown:server");
|
||||
|
||||
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
|
||||
dispatchSpy.mockClear();
|
||||
@@ -582,7 +582,7 @@ describe("RoomListViewModel", () => {
|
||||
it("should not navigate when no room is selected", async () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(null);
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(null);
|
||||
|
||||
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
|
||||
dispatchSpy.mockClear();
|
||||
@@ -859,7 +859,7 @@ describe("RoomListViewModel", () => {
|
||||
expect(favHeader.isExpanded).toBe(false);
|
||||
|
||||
// Select regularRoom1, which is the first room in the chats section
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!reg1:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!reg1:server");
|
||||
dispatcher.dispatch({
|
||||
action: Action.ActiveRoomChanged,
|
||||
newRoomId: "!reg1:server",
|
||||
@@ -1165,7 +1165,7 @@ describe("RoomListViewModel", () => {
|
||||
viewModel = new RoomListViewModel({ client: matrixClient });
|
||||
|
||||
// Select favRoom1 (index 0 globally, index 0 in favourites section)
|
||||
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!fav1:server");
|
||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "getRoomId").mockReturnValue("!fav1:server");
|
||||
dispatcher.dispatch({
|
||||
action: Action.ActiveRoomChanged,
|
||||
newRoomId: "!fav1:server",
|
||||
|
||||
@@ -16,13 +16,13 @@ import Modal from "../../../src/Modal";
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
import SettingsStore from "../../../src/settings/SettingsStore";
|
||||
import { UIFeature } from "../../../src/settings/UIFeature";
|
||||
import { SdkContextClass } from "../../../src/contexts/SDKContext";
|
||||
import { SDKContextClass } from "../../../src/contexts/SDKContextClass";
|
||||
import { DateSeparatorViewModel } from "../../../src/viewmodels/room/timeline/DateSeparatorViewModel";
|
||||
import { flushPromisesWithFakeTimers } from "../../test-utils";
|
||||
|
||||
jest.mock("../../../src/settings/SettingsStore");
|
||||
jest.mock("../../../src/contexts/SDKContext", () => ({
|
||||
SdkContextClass: {
|
||||
jest.mock("../../../src/contexts/SDKContextClass", () => ({
|
||||
SDKContextClass: {
|
||||
instance: {
|
||||
roomViewStore: {
|
||||
getRoomId: jest.fn(),
|
||||
@@ -97,7 +97,7 @@ describe("DateSeparatorViewModel", () => {
|
||||
jest.spyOn(dispatcher, "dispatch").mockImplementation(() => {});
|
||||
jest.spyOn(Modal, "createDialog").mockImplementation(() => ({ close: jest.fn() }) as any);
|
||||
|
||||
mocked(SdkContextClass.instance.roomViewStore.getRoomId).mockReturnValue(roomId);
|
||||
mocked(SDKContextClass.instance.roomViewStore.getRoomId).mockReturnValue(roomId);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -193,7 +193,7 @@ describe("DateSeparatorViewModel", () => {
|
||||
event_id: "$event",
|
||||
origin_server_ts: nowDate.getTime(),
|
||||
});
|
||||
mocked(SdkContextClass.instance.roomViewStore.getRoomId).mockReturnValue("!other:example.org");
|
||||
mocked(SDKContextClass.instance.roomViewStore.getRoomId).mockReturnValue("!other:example.org");
|
||||
const vm = createViewModel();
|
||||
|
||||
await vm.pickDate(nowDate.getTime() - HOUR_MS);
|
||||
@@ -299,7 +299,7 @@ describe("DateSeparatorViewModel", () => {
|
||||
});
|
||||
|
||||
it("does not jump when room changed before request resolves", async () => {
|
||||
mocked(SdkContextClass.instance.roomViewStore.getRoomId).mockReturnValue("!some-other-room");
|
||||
mocked(SDKContextClass.instance.roomViewStore.getRoomId).mockReturnValue("!some-other-room");
|
||||
mockTimestampToEvent.mockResolvedValue({
|
||||
event_id: "$abc",
|
||||
origin_server_ts: 0,
|
||||
@@ -313,7 +313,7 @@ describe("DateSeparatorViewModel", () => {
|
||||
});
|
||||
|
||||
it("does not show jump to date error if user switched room", async () => {
|
||||
mocked(SdkContextClass.instance.roomViewStore.getRoomId).mockReturnValue("!some-other-room");
|
||||
mocked(SDKContextClass.instance.roomViewStore.getRoomId).mockReturnValue("!some-other-room");
|
||||
mockTimestampToEvent.mockRejectedValue(new Error("Fake error in test"));
|
||||
const vm = createViewModel();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user