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:
@@ -81,6 +81,7 @@ import {
|
|||||||
import { TokenRefresher } from "./utils/oidc/TokenRefresher";
|
import { TokenRefresher } from "./utils/oidc/TokenRefresher";
|
||||||
import { checkBrowserSupport } from "./SupportedBrowser";
|
import { checkBrowserSupport } from "./SupportedBrowser";
|
||||||
import { type URLParams } from "./vector/url_utils.ts";
|
import { type URLParams } from "./vector/url_utils.ts";
|
||||||
|
import { type OnLoggedInPayload } from "./dispatcher/payloads/OnLoggedInPayload.ts";
|
||||||
|
|
||||||
const HOMESERVER_URL_KEY = "mx_hs_url";
|
const HOMESERVER_URL_KEY = "mx_hs_url";
|
||||||
const ID_SERVER_URL_KEY = "mx_is_url";
|
const ID_SERVER_URL_KEY = "mx_is_url";
|
||||||
@@ -906,9 +907,9 @@ async function doSetLoggedIn(
|
|||||||
}
|
}
|
||||||
checkSessionLock();
|
checkSessionLock();
|
||||||
|
|
||||||
// We are now logged in, so fire this. We have yet to start the client but the
|
// We are now logged in, so fire this. We have yet to start the client but the client_started dispatch is for that.
|
||||||
// client_started dispatch is for that.
|
// Dispatch this synchronously so SDKContextClass can set the client for other modules to consume.
|
||||||
dis.fire(Action.OnLoggedIn);
|
dis.dispatch<OnLoggedInPayload>({ action: Action.OnLoggedIn, client }, true);
|
||||||
|
|
||||||
const clientPegOpts: MatrixClientPegAssignOpts = {};
|
const clientPegOpts: MatrixClientPegAssignOpts = {};
|
||||||
if (credentials.pickleKey) {
|
if (credentials.pickleKey) {
|
||||||
|
|||||||
@@ -1521,7 +1521,6 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||||||
* Handle an {@link Action.OnLoggedIn} action (i.e, we now have a client with working credentials).
|
* Handle an {@link Action.OnLoggedIn} action (i.e, we now have a client with working credentials).
|
||||||
*/
|
*/
|
||||||
private onLoggedIn(): void {
|
private onLoggedIn(): void {
|
||||||
this.stores.client = MatrixClientPeg.safeGet();
|
|
||||||
StorageManager.tryPersistStorage();
|
StorageManager.tryPersistStorage();
|
||||||
|
|
||||||
// If we're loading the app for the first time, we can now transition to a splash screen while we wait for the
|
// If we're loading the app for the first time, we can now transition to a splash screen while we wait for the
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ import { OidcClientStore } from "../stores/oidc/OidcClientStore";
|
|||||||
import WidgetStore from "../stores/WidgetStore";
|
import WidgetStore from "../stores/WidgetStore";
|
||||||
import ResizeNotifier from "../utils/ResizeNotifier";
|
import ResizeNotifier from "../utils/ResizeNotifier";
|
||||||
import { MultiRoomViewStore } from "../stores/MultiRoomViewStore";
|
import { MultiRoomViewStore } from "../stores/MultiRoomViewStore";
|
||||||
|
import { type ActionPayload, isAction } from "../dispatcher/payloads.ts";
|
||||||
|
import { Action } from "../dispatcher/actions.ts";
|
||||||
|
import { type OnLoggedInPayload } from "../dispatcher/payloads/OnLoggedInPayload.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which (mostly) lazily initialises stores as and when they are requested, ensuring they remain
|
* A class which (mostly) lazily initialises stores as and when they are requested, ensuring they remain
|
||||||
@@ -43,11 +46,13 @@ export class SDKContextClass {
|
|||||||
*/
|
*/
|
||||||
public static readonly instance = new SDKContextClass();
|
public static readonly instance = new SDKContextClass();
|
||||||
|
|
||||||
// Optional as we don't have a client on initial load if unregistered. This should be set
|
// Optional as we don't have a client on initial load if unregistered.
|
||||||
// when the MatrixClient is first acquired in the dispatcher event Action.OnLoggedIn.
|
|
||||||
// It is only safe to set this once, as updating this value will NOT notify components using
|
// It is only safe to set this once, as updating this value will NOT notify components using
|
||||||
// this Context.
|
// this Context.
|
||||||
public client?: MatrixClient;
|
protected _client?: MatrixClient;
|
||||||
|
public get client(): MatrixClient | undefined {
|
||||||
|
return this._client;
|
||||||
|
}
|
||||||
|
|
||||||
// All protected fields to make it easier to derive test stores
|
// All protected fields to make it easier to derive test stores
|
||||||
protected _WidgetPermissionStore?: WidgetPermissionStore;
|
protected _WidgetPermissionStore?: WidgetPermissionStore;
|
||||||
@@ -67,6 +72,16 @@ export class SDKContextClass {
|
|||||||
protected _ResizeNotifier?: ResizeNotifier;
|
protected _ResizeNotifier?: ResizeNotifier;
|
||||||
protected _MultiRoomViewStore?: MultiRoomViewStore;
|
protected _MultiRoomViewStore?: MultiRoomViewStore;
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
defaultDispatcher.register(this.onDispatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onDispatch = (payload: ActionPayload): void => {
|
||||||
|
if (isAction<OnLoggedInPayload>(payload, Action.OnLoggedIn)) {
|
||||||
|
this._client = payload.client;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Automatically construct stores which need to be created eagerly so they can register with
|
* Automatically construct stores which need to be created eagerly so they can register with
|
||||||
* the dispatcher.
|
* the dispatcher.
|
||||||
@@ -193,5 +208,6 @@ export class SDKContextClass {
|
|||||||
public onLoggedOut(): void {
|
public onLoggedOut(): void {
|
||||||
this._UserProfilesStore = undefined;
|
this._UserProfilesStore = undefined;
|
||||||
this._OidcClientStore = undefined;
|
this._OidcClientStore = undefined;
|
||||||
|
this._client = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ export enum Action {
|
|||||||
* access token from local storage). Note that this does not necessarily mean that a login action has happened,
|
* access token from local storage). Note that this does not necessarily mean that a login action has happened,
|
||||||
* just that authentication creds have been set up.
|
* just that authentication creds have been set up.
|
||||||
*
|
*
|
||||||
* No additional payload information required.
|
* Use with a OnLoggedInPayload.
|
||||||
*/
|
*/
|
||||||
OnLoggedIn = "on_logged_in",
|
OnLoggedIn = "on_logged_in",
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ export interface ActionPayload {
|
|||||||
action: DispatcherAction;
|
action: DispatcherAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type guard to check if a payload is of a specific action type.
|
||||||
|
* @param payload - the incoming payload to check
|
||||||
|
* @param action - the action to return true for
|
||||||
|
*/
|
||||||
|
export function isAction<P extends ActionPayload>(payload: ActionPayload, action: P["action"]): payload is P {
|
||||||
|
return payload.action === action;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The function the dispatcher calls when ready for an AsyncActionPayload. The
|
* The function the dispatcher calls when ready for an AsyncActionPayload. The
|
||||||
* single argument is used to start a dispatch. First the dispatcher calls the
|
* single argument is used to start a dispatch. First the dispatcher calls the
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Element Creations Ltd.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||||
|
Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
|
import { type ActionPayload } from "../payloads";
|
||||||
|
import { type Action } from "../actions";
|
||||||
|
|
||||||
|
export interface OnLoggedInPayload extends ActionPayload {
|
||||||
|
action: Action.OnLoggedIn;
|
||||||
|
|
||||||
|
client: MatrixClient;
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { SDKContextClass } from "../../src/contexts/SDKContextClass";
|
import { SDKContextClass } from "../../src/contexts/SDKContextClass";
|
||||||
import { type PosthogAnalytics } from "../../src/PosthogAnalytics";
|
import { type PosthogAnalytics } from "../../src/PosthogAnalytics";
|
||||||
import { type SlidingSyncManager } from "../../src/SlidingSyncManager";
|
import { type SlidingSyncManager } from "../../src/SlidingSyncManager";
|
||||||
@@ -22,6 +24,7 @@ import type WidgetStore from "../../src/stores/WidgetStore";
|
|||||||
* replace individual stores. This is useful for tests which need to mock out stores.
|
* replace individual stores. This is useful for tests which need to mock out stores.
|
||||||
*/
|
*/
|
||||||
export class TestSDKContext extends SDKContextClass {
|
export class TestSDKContext extends SDKContextClass {
|
||||||
|
declare public _client?: MatrixClient;
|
||||||
declare public _RightPanelStore?: RightPanelStore;
|
declare public _RightPanelStore?: RightPanelStore;
|
||||||
declare public _RoomNotificationStateStore?: RoomNotificationStateStore;
|
declare public _RoomNotificationStateStore?: RoomNotificationStateStore;
|
||||||
declare public _RoomViewStore?: RoomViewStore;
|
declare public _RoomViewStore?: RoomViewStore;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ describe("<LoggedInView />", () => {
|
|||||||
mockClient.setPushRuleActions.mockReset().mockResolvedValue({});
|
mockClient.setPushRuleActions.mockReset().mockResolvedValue({});
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
mockClient.pushProcessor = new PushProcessor(mockClient);
|
mockClient.pushProcessor = new PushProcessor(mockClient);
|
||||||
mockSdkContext.client = mockClient;
|
mockSdkContext._client = mockClient;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("synced push rules", () => {
|
describe("synced push rules", () => {
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ describe("PipContainer", () => {
|
|||||||
sdkContext = new TestSDKContext();
|
sdkContext = new TestSDKContext();
|
||||||
// @ts-ignore PipContainer uses SDKContext in the constructor
|
// @ts-ignore PipContainer uses SDKContext in the constructor
|
||||||
SDKContextClass.instance = sdkContext;
|
SDKContextClass.instance = sdkContext;
|
||||||
sdkContext.client = client;
|
sdkContext._client = client;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelS
|
|||||||
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
|
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
|
||||||
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
||||||
import { WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
|
import { WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
|
||||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
|
||||||
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
||||||
|
import { TestSDKContext } from "../../TestSDKContext.ts";
|
||||||
|
|
||||||
const RightPanelBase = wrapInMatrixClientContext(_RightPanel);
|
const RightPanelBase = wrapInMatrixClientContext(_RightPanel);
|
||||||
|
|
||||||
@@ -32,14 +32,14 @@ describe("RightPanel", () => {
|
|||||||
const resizeNotifier = new ResizeNotifier();
|
const resizeNotifier = new ResizeNotifier();
|
||||||
|
|
||||||
let cli: MockedObject<MatrixClient>;
|
let cli: MockedObject<MatrixClient>;
|
||||||
let context: SDKContextClass;
|
let context: TestSDKContext;
|
||||||
let RightPanel: React.ComponentType<React.ComponentProps<typeof RightPanelBase>>;
|
let RightPanel: React.ComponentType<React.ComponentProps<typeof RightPanelBase>>;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stubClient();
|
stubClient();
|
||||||
cli = mocked(MatrixClientPeg.safeGet());
|
cli = mocked(MatrixClientPeg.safeGet());
|
||||||
DMRoomMap.makeShared(cli);
|
DMRoomMap.makeShared(cli);
|
||||||
context = new SDKContextClass();
|
context = new TestSDKContext();
|
||||||
context.client = cli;
|
context._client = cli;
|
||||||
RightPanel = wrapInSdkContext(RightPanelBase, context);
|
RightPanel = wrapInSdkContext(RightPanelBase, context);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ import { DirectoryMember } from "../../../../src/utils/direct-messages";
|
|||||||
import { createDmLocalRoom } from "../../../../src/utils/dm/createDmLocalRoom";
|
import { createDmLocalRoom } from "../../../../src/utils/dm/createDmLocalRoom";
|
||||||
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
||||||
import { SDKContext } from "../../../../src/contexts/SDKContext";
|
import { SDKContext } from "../../../../src/contexts/SDKContext";
|
||||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../../TestSDKContext.ts";
|
||||||
import WidgetUtils from "../../../../src/utils/WidgetUtils";
|
import WidgetUtils from "../../../../src/utils/WidgetUtils";
|
||||||
import { WidgetType } from "../../../../src/widgets/WidgetType";
|
import { WidgetType } from "../../../../src/widgets/WidgetType";
|
||||||
import WidgetStore from "../../../../src/stores/WidgetStore";
|
import WidgetStore from "../../../../src/stores/WidgetStore";
|
||||||
@@ -86,7 +86,7 @@ describe("RoomView", () => {
|
|||||||
let cli: MockedObject<MatrixClient>;
|
let cli: MockedObject<MatrixClient>;
|
||||||
let room: Room;
|
let room: Room;
|
||||||
let rooms: Map<string, Room>;
|
let rooms: Map<string, Room>;
|
||||||
let stores: SDKContextClass;
|
let stores: TestSDKContext;
|
||||||
let crypto: CryptoApi;
|
let crypto: CryptoApi;
|
||||||
|
|
||||||
// mute some noise
|
// mute some noise
|
||||||
@@ -111,8 +111,8 @@ describe("RoomView", () => {
|
|||||||
room.on(RoomEvent.TimelineReset, (...args) => cli.emit(RoomEvent.TimelineReset, ...args));
|
room.on(RoomEvent.TimelineReset, (...args) => cli.emit(RoomEvent.TimelineReset, ...args));
|
||||||
|
|
||||||
DMRoomMap.makeShared(cli);
|
DMRoomMap.makeShared(cli);
|
||||||
stores = new SDKContextClass();
|
stores = new TestSDKContext();
|
||||||
stores.client = cli;
|
stores._client = cli;
|
||||||
stores.rightPanelStore.useUnitTestClient(cli);
|
stores.rightPanelStore.useUnitTestClient(cli);
|
||||||
|
|
||||||
crypto = cli.getCrypto()!;
|
crypto = cli.getCrypto()!;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { type IConfigOptions } from "../../../../../src/IConfigOptions";
|
|||||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
||||||
import { type IProfileInfo } from "../../../../../src/hooks/useProfileInfo";
|
import { type IProfileInfo } from "../../../../../src/hooks/useProfileInfo";
|
||||||
import { DirectoryMember, startDmOnFirstMessage } from "../../../../../src/utils/direct-messages";
|
import { DirectoryMember, startDmOnFirstMessage } from "../../../../../src/utils/direct-messages";
|
||||||
|
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||||
|
|
||||||
const mockGetAccessToken = jest.fn().mockResolvedValue("getAccessToken");
|
const mockGetAccessToken = jest.fn().mockResolvedValue("getAccessToken");
|
||||||
jest.mock("../../../../../src/IdentityAuthClient", () =>
|
jest.mock("../../../../../src/IdentityAuthClient", () =>
|
||||||
@@ -94,6 +95,7 @@ const bobProfileInfo: IProfileInfo = {
|
|||||||
describe("InviteDialog", () => {
|
describe("InviteDialog", () => {
|
||||||
let mockClient: Mocked<MatrixClient>;
|
let mockClient: Mocked<MatrixClient>;
|
||||||
let room: Room;
|
let room: Room;
|
||||||
|
let sdkContext: TestSDKContext;
|
||||||
|
|
||||||
filterConsole(
|
filterConsole(
|
||||||
"Error retrieving profile for userId @carol:example.com",
|
"Error retrieving profile for userId @carol:example.com",
|
||||||
@@ -178,13 +180,15 @@ describe("InviteDialog", () => {
|
|||||||
mockClient.getRooms.mockReturnValue([room]);
|
mockClient.getRooms.mockReturnValue([room]);
|
||||||
mockClient.getRoom.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 () => {
|
afterEach(async () => {
|
||||||
await clearAllModals();
|
await clearAllModals();
|
||||||
SDKContextClass.instance.onLoggedOut();
|
SDKContextClass.instance.onLoggedOut();
|
||||||
SDKContextClass.instance.client = undefined;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext
|
|||||||
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||||
import { UIFeature } from "../../../../../src/settings/UIFeature";
|
import { UIFeature } from "../../../../../src/settings/UIFeature";
|
||||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||||
|
|
||||||
describe("<RoomSettingsDialog />", () => {
|
describe("<RoomSettingsDialog />", () => {
|
||||||
const userId = "@alice:server.org";
|
const userId = "@alice:server.org";
|
||||||
@@ -44,7 +44,7 @@ describe("<RoomSettingsDialog />", () => {
|
|||||||
const room2 = new Room("!room2:server.org", mockClient, userId);
|
const room2 = new Room("!room2:server.org", mockClient, userId);
|
||||||
room2.name = "Another Room";
|
room2.name = "Another Room";
|
||||||
|
|
||||||
let sdkContext: SDKContextClass;
|
let sdkContext: TestSDKContext;
|
||||||
|
|
||||||
jest.spyOn(SettingsStore, "getValue");
|
jest.spyOn(SettingsStore, "getValue");
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ describe("<RoomSettingsDialog />", () => {
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
sdkContext = new SDKContextClass();
|
sdkContext = new TestSDKContext();
|
||||||
sdkContext.client = mockClient;
|
sdkContext._client = mockClient;
|
||||||
|
|
||||||
jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false);
|
jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false);
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
} from "../../../../test-utils";
|
} from "../../../../test-utils";
|
||||||
import { UIFeature } from "../../../../../src/settings/UIFeature";
|
import { UIFeature } from "../../../../../src/settings/UIFeature";
|
||||||
import { SettingLevel } from "../../../../../src/settings/SettingLevel";
|
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 { type FeatureSettingKey } from "../../../../../src/settings/Settings.tsx";
|
||||||
import { mockOpenIdConfiguration } from "../../../../test-utils/oidc.ts";
|
import { mockOpenIdConfiguration } from "../../../../test-utils/oidc.ts";
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ describe("<UserSettingsDialog />", () => {
|
|||||||
const mockSettingsStore = mocked(SettingsStore);
|
const mockSettingsStore = mocked(SettingsStore);
|
||||||
let mockClient!: MockedObject<MatrixClient>;
|
let mockClient!: MockedObject<MatrixClient>;
|
||||||
|
|
||||||
let sdkContext: SDKContextClass;
|
let sdkContext: TestSDKContext;
|
||||||
const defaultProps = { onFinished: jest.fn() };
|
const defaultProps = { onFinished: jest.fn() };
|
||||||
const getComponent = (
|
const getComponent = (
|
||||||
props: Partial<typeof defaultProps & { initialTabId?: UserTab; props: Record<string, any> }> = {},
|
props: Partial<typeof defaultProps & { initialTabId?: UserTab; props: Record<string, any> }> = {},
|
||||||
@@ -76,8 +76,8 @@ describe("<UserSettingsDialog />", () => {
|
|||||||
getMediaConfig: jest.fn(),
|
getMediaConfig: jest.fn(),
|
||||||
getAuthMetadata: jest.fn().mockResolvedValue(mockOpenIdConfiguration()),
|
getAuthMetadata: jest.fn().mockResolvedValue(mockOpenIdConfiguration()),
|
||||||
});
|
});
|
||||||
sdkContext = new SDKContextClass();
|
sdkContext = new TestSDKContext();
|
||||||
sdkContext.client = mockClient;
|
sdkContext._client = mockClient;
|
||||||
mockSettingsStore.getValue.mockReturnValue(false);
|
mockSettingsStore.getValue.mockReturnValue(false);
|
||||||
mockSettingsStore.getValueAt.mockReturnValue(false);
|
mockSettingsStore.getValueAt.mockReturnValue(false);
|
||||||
mockSettingsStore.getFeatureSettingNames.mockReturnValue([]);
|
mockSettingsStore.getFeatureSettingNames.mockReturnValue([]);
|
||||||
|
|||||||
@@ -48,11 +48,12 @@ describe("<Pill>", () => {
|
|||||||
const user3Id = "@user3:example.com";
|
const user3Id = "@user3:example.com";
|
||||||
let renderResult: RenderResult;
|
let renderResult: RenderResult;
|
||||||
let pillParentClickHandler: (e: ButtonEvent) => void;
|
let pillParentClickHandler: (e: ButtonEvent) => void;
|
||||||
|
let sdkContext: TestSDKContext;
|
||||||
|
|
||||||
const renderPill = (props: PillProps): void => {
|
const renderPill = (props: PillProps): void => {
|
||||||
const cli = MatrixClientPeg.safeGet();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const mockSdkContext = new TestSDKContext();
|
const mockSdkContext = new TestSDKContext();
|
||||||
mockSdkContext.client = cli;
|
mockSdkContext._client = cli;
|
||||||
|
|
||||||
const withDefault = {
|
const withDefault = {
|
||||||
inMessage: true,
|
inMessage: true,
|
||||||
@@ -79,7 +80,10 @@ describe("<Pill>", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
client = mocked(stubClient());
|
client = mocked(stubClient());
|
||||||
SDKContextClass.instance.client = client;
|
sdkContext = new TestSDKContext();
|
||||||
|
// @ts-ignore Pill uses the SDKContext global
|
||||||
|
SDKContextClass.instance = sdkContext;
|
||||||
|
sdkContext._client = client;
|
||||||
DMRoomMap.makeShared(client);
|
DMRoomMap.makeShared(client);
|
||||||
room1 = new Room(room1Id, client, user1Id);
|
room1 = new Room(room1Id, client, user1Id);
|
||||||
room1.name = "Room 1";
|
room1.name = "Room 1";
|
||||||
|
|||||||
+8
-8
@@ -12,7 +12,7 @@ import { type EventTimeline, JoinRule, Room } from "matrix-js-sdk/src/matrix";
|
|||||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||||
|
|
||||||
import { SDKContext } from "../../../../../../src/contexts/SDKContext";
|
import { SDKContext } from "../../../../../../src/contexts/SDKContext";
|
||||||
import { SDKContextClass } from "../../../../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../../../../TestSDKContext.ts";
|
||||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../../test-utils";
|
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../../test-utils";
|
||||||
import {
|
import {
|
||||||
CallGuestLinkButton,
|
CallGuestLinkButton,
|
||||||
@@ -26,7 +26,7 @@ import SettingsStore from "../../../../../../src/settings/SettingsStore";
|
|||||||
|
|
||||||
describe("<CallGuestLinkButton />", () => {
|
describe("<CallGuestLinkButton />", () => {
|
||||||
const roomId = "!room:server.org";
|
const roomId = "!room:server.org";
|
||||||
let sdkContext!: SDKContextClass;
|
let sdkContext!: TestSDKContext;
|
||||||
let modalSpy: jest.SpyInstance;
|
let modalSpy: jest.SpyInstance;
|
||||||
let modalResolve: (value: unknown[] | PromiseLike<unknown[]>) => void;
|
let modalResolve: (value: unknown[] | PromiseLike<unknown[]>) => void;
|
||||||
let room: Room;
|
let room: Room;
|
||||||
@@ -78,8 +78,8 @@ describe("<CallGuestLinkButton />", () => {
|
|||||||
...mockClientMethodsUser(),
|
...mockClientMethodsUser(),
|
||||||
sendStateEvent: jest.fn(),
|
sendStateEvent: jest.fn(),
|
||||||
});
|
});
|
||||||
sdkContext = new SDKContextClass();
|
sdkContext = new TestSDKContext();
|
||||||
sdkContext.client = client;
|
sdkContext._client = client;
|
||||||
const modalPromise = new Promise<unknown[]>((resolve) => {
|
const modalPromise = new Promise<unknown[]>((resolve) => {
|
||||||
modalResolve = resolve;
|
modalResolve = resolve;
|
||||||
});
|
});
|
||||||
@@ -94,7 +94,7 @@ describe("<CallGuestLinkButton />", () => {
|
|||||||
return oldGet(key);
|
return oldGet(key);
|
||||||
});
|
});
|
||||||
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(true);
|
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(true);
|
||||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
jest.spyOn(sdkContext.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
@@ -152,7 +152,7 @@ describe("<CallGuestLinkButton />", () => {
|
|||||||
|
|
||||||
it("don't show external conference button if now guest spa link is configured", () => {
|
it("don't show external conference button if now guest spa link is configured", () => {
|
||||||
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
||||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
jest.spyOn(sdkContext.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||||
|
|
||||||
jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
|
jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
|
||||||
if (key === "element_call") {
|
if (key === "element_call") {
|
||||||
@@ -179,7 +179,7 @@ describe("<CallGuestLinkButton />", () => {
|
|||||||
|
|
||||||
it("opens the share dialog with the correct share link in an encrypted room", () => {
|
it("opens the share dialog with the correct share link in an encrypted room", () => {
|
||||||
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
||||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
jest.spyOn(sdkContext.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||||
|
|
||||||
getComponent(room);
|
getComponent(room);
|
||||||
const modalSpy = jest.spyOn(Modal, "createDialog");
|
const modalSpy = jest.spyOn(Modal, "createDialog");
|
||||||
@@ -201,7 +201,7 @@ describe("<CallGuestLinkButton />", () => {
|
|||||||
it("share dialog has correct link in an unencrypted room", () => {
|
it("share dialog has correct link in an unencrypted room", () => {
|
||||||
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
|
||||||
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(false);
|
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(false);
|
||||||
jest.spyOn(SDKContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
|
jest.spyOn(sdkContext.roomViewStore, "isViewingCall").mockReturnValue(true);
|
||||||
|
|
||||||
getComponent(room);
|
getComponent(room);
|
||||||
const modalSpy = jest.spyOn(Modal, "createDialog");
|
const modalSpy = jest.spyOn(Modal, "createDialog");
|
||||||
|
|||||||
+4
-4
@@ -13,7 +13,7 @@ import { fireEvent, render, screen, waitFor } from "jest-matrix-react";
|
|||||||
|
|
||||||
import { VideoRoomChatButton } from "../../../../../../src/components/views/rooms/RoomHeader/VideoRoomChatButton";
|
import { VideoRoomChatButton } from "../../../../../../src/components/views/rooms/RoomHeader/VideoRoomChatButton";
|
||||||
import { SDKContext } from "../../../../../../src/contexts/SDKContext";
|
import { SDKContext } from "../../../../../../src/contexts/SDKContext";
|
||||||
import { SDKContextClass } from "../../../../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../../../../TestSDKContext.ts";
|
||||||
import type RightPanelStore from "../../../../../../src/stores/right-panel/RightPanelStore";
|
import type RightPanelStore from "../../../../../../src/stores/right-panel/RightPanelStore";
|
||||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../../test-utils";
|
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../../test-utils";
|
||||||
import { RoomNotificationState } from "../../../../../../src/stores/notifications/RoomNotificationState";
|
import { RoomNotificationState } from "../../../../../../src/stores/notifications/RoomNotificationState";
|
||||||
@@ -23,7 +23,7 @@ import { RightPanelPhases } from "../../../../../../src/stores/right-panel/Right
|
|||||||
|
|
||||||
describe("<VideoRoomChatButton />", () => {
|
describe("<VideoRoomChatButton />", () => {
|
||||||
const roomId = "!room:server.org";
|
const roomId = "!room:server.org";
|
||||||
let sdkContext!: SDKContextClass;
|
let sdkContext!: TestSDKContext;
|
||||||
let rightPanelStore!: MockedObject<RightPanelStore>;
|
let rightPanelStore!: MockedObject<RightPanelStore>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -59,8 +59,8 @@ describe("<VideoRoomChatButton />", () => {
|
|||||||
rightPanelStore = {
|
rightPanelStore = {
|
||||||
showOrHidePhase: jest.fn(),
|
showOrHidePhase: jest.fn(),
|
||||||
} as unknown as MockedObject<RightPanelStore>;
|
} as unknown as MockedObject<RightPanelStore>;
|
||||||
sdkContext = new SDKContextClass();
|
sdkContext = new TestSDKContext();
|
||||||
sdkContext.client = client;
|
sdkContext._client = client;
|
||||||
jest.spyOn(sdkContext, "rightPanelStore", "get").mockReturnValue(rightPanelStore);
|
jest.spyOn(sdkContext, "rightPanelStore", "get").mockReturnValue(rightPanelStore);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ export async function renderMemberList(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const context = new TestSDKContext();
|
const context = new TestSDKContext();
|
||||||
context.client = client;
|
context._client = client;
|
||||||
context.memberListStore.isPresenceEnabled = jest.fn().mockReturnValue(enablePresence);
|
context.memberListStore.isPresenceEnabled = jest.fn().mockReturnValue(enablePresence);
|
||||||
const root = render(
|
const root = render(
|
||||||
<MatrixClientContext.Provider value={client}>
|
<MatrixClientContext.Provider value={client}>
|
||||||
|
|||||||
+4
-4
@@ -16,7 +16,7 @@ import { ToastContext, ToastRack } from "@element-hq/web-shared-components";
|
|||||||
|
|
||||||
import AccountUserSettingsTab from "../../../../../../../src/components/views/settings/tabs/user/AccountUserSettingsTab";
|
import AccountUserSettingsTab from "../../../../../../../src/components/views/settings/tabs/user/AccountUserSettingsTab";
|
||||||
import { SDKContext } from "../../../../../../../src/contexts/SDKContext";
|
import { SDKContext } from "../../../../../../../src/contexts/SDKContext";
|
||||||
import { SDKContextClass } from "../../../../../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../../../../../TestSDKContext.ts";
|
||||||
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
|
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
|
||||||
import {
|
import {
|
||||||
getMockClientWithEventEmitter,
|
getMockClientWithEventEmitter,
|
||||||
@@ -51,7 +51,7 @@ describe("<AccountUserSettingsTab />", () => {
|
|||||||
const userId = "@alice:server.org";
|
const userId = "@alice:server.org";
|
||||||
let mockClient: MockedObject<MatrixClient>;
|
let mockClient: MockedObject<MatrixClient>;
|
||||||
|
|
||||||
let stores: SDKContextClass;
|
let stores: TestSDKContext;
|
||||||
|
|
||||||
const getComponent = () => (
|
const getComponent = () => (
|
||||||
<MatrixClientContext.Provider value={mockClient}>
|
<MatrixClientContext.Provider value={mockClient}>
|
||||||
@@ -87,8 +87,8 @@ describe("<AccountUserSettingsTab />", () => {
|
|||||||
id_server_unbind_result: "success",
|
id_server_unbind_result: "success",
|
||||||
});
|
});
|
||||||
|
|
||||||
stores = new SDKContextClass();
|
stores = new TestSDKContext();
|
||||||
stores.client = mockClient;
|
stores._client = mockClient;
|
||||||
// stub out this store completely to avoid mocking initialisation
|
// stub out this store completely to avoid mocking initialisation
|
||||||
const mockOidcClientStore = {} as unknown as OidcClientStore;
|
const mockOidcClientStore = {} as unknown as OidcClientStore;
|
||||||
jest.spyOn(stores, "oidcClientStore", "get").mockReturnValue(mockOidcClientStore);
|
jest.spyOn(stores, "oidcClientStore", "get").mockReturnValue(mockOidcClientStore);
|
||||||
|
|||||||
+3
-3
@@ -20,7 +20,7 @@ import {
|
|||||||
mockPlatformPeg,
|
mockPlatformPeg,
|
||||||
} from "../../../../../../test-utils";
|
} from "../../../../../../test-utils";
|
||||||
import { SDKContext } from "../../../../../../../src/contexts/SDKContext";
|
import { SDKContext } from "../../../../../../../src/contexts/SDKContext";
|
||||||
import { SDKContextClass } from "../../../../../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../../../../../TestSDKContext.ts";
|
||||||
import defaultDispatcher from "../../../../../../../src/dispatcher/dispatcher";
|
import defaultDispatcher from "../../../../../../../src/dispatcher/dispatcher";
|
||||||
import { UIFeature } from "../../../../../../../src/settings/UIFeature";
|
import { UIFeature } from "../../../../../../../src/settings/UIFeature";
|
||||||
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
|
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
|
||||||
@@ -42,8 +42,8 @@ describe("<SecurityUserSettingsTab />", () => {
|
|||||||
setIgnoredUsers,
|
setIgnoredUsers,
|
||||||
});
|
});
|
||||||
|
|
||||||
const sdkContext = new SDKContextClass();
|
const sdkContext = new TestSDKContext();
|
||||||
sdkContext.client = mockClient;
|
sdkContext._client = mockClient;
|
||||||
|
|
||||||
const getComponent = () => (
|
const getComponent = () => (
|
||||||
<MatrixClientContext.Provider value={mockClient}>
|
<MatrixClientContext.Provider value={mockClient}>
|
||||||
|
|||||||
+4
-4
@@ -57,7 +57,7 @@ import { INACTIVE_DEVICE_AGE_MS } from "../../../../../../../src/components/view
|
|||||||
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
|
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
|
||||||
import { getClientInformationEventType } from "../../../../../../../src/utils/device/clientInformation";
|
import { getClientInformationEventType } from "../../../../../../../src/utils/device/clientInformation";
|
||||||
import { SDKContext } from "../../../../../../../src/contexts/SDKContext";
|
import { SDKContext } from "../../../../../../../src/contexts/SDKContext";
|
||||||
import { SDKContextClass } from "../../../../../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../../../../../TestSDKContext.ts";
|
||||||
import { type OidcClientStore } from "../../../../../../../src/stores/oidc/OidcClientStore";
|
import { type OidcClientStore } from "../../../../../../../src/stores/oidc/OidcClientStore";
|
||||||
import { makeDelegatedAuthConfig } from "../../../../../../test-utils/oidc";
|
import { makeDelegatedAuthConfig } from "../../../../../../test-utils/oidc";
|
||||||
import MatrixClientContext from "../../../../../../../src/contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../../../../../src/contexts/MatrixClientContext";
|
||||||
@@ -134,7 +134,7 @@ describe("<SessionManagerTab />", () => {
|
|||||||
} as unknown as CryptoApi);
|
} as unknown as CryptoApi);
|
||||||
|
|
||||||
let mockClient!: MockedObject<MatrixClient>;
|
let mockClient!: MockedObject<MatrixClient>;
|
||||||
let sdkContext: SDKContextClass;
|
let sdkContext: TestSDKContext;
|
||||||
|
|
||||||
const defaultProps = {};
|
const defaultProps = {};
|
||||||
const getComponent = (props = {}): React.ReactElement => (
|
const getComponent = (props = {}): React.ReactElement => (
|
||||||
@@ -250,8 +250,8 @@ describe("<SessionManagerTab />", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sdkContext = new SDKContextClass();
|
sdkContext = new TestSDKContext();
|
||||||
sdkContext.client = mockClient;
|
sdkContext._client = mockClient;
|
||||||
|
|
||||||
// @ts-ignore allow delete of non-optional prop
|
// @ts-ignore allow delete of non-optional prop
|
||||||
delete window.location;
|
delete window.location;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { MetaSpace, type SpaceKey } from "../../../../../src/stores/spaces";
|
|||||||
import { shouldShowComponent } from "../../../../../src/customisations/helpers/UIComponents";
|
import { shouldShowComponent } from "../../../../../src/customisations/helpers/UIComponents";
|
||||||
import { UIComponent } from "../../../../../src/settings/UIFeature";
|
import { UIComponent } from "../../../../../src/settings/UIFeature";
|
||||||
import { mkStubRoom, wrapInMatrixClientContext, wrapInSdkContext } from "../../../../test-utils";
|
import { mkStubRoom, wrapInMatrixClientContext, wrapInSdkContext } from "../../../../test-utils";
|
||||||
import { SDKContextClass } from "../../../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../../../TestSDKContext.ts";
|
||||||
import SpaceStore from "../../../../../src/stores/spaces/SpaceStore";
|
import SpaceStore from "../../../../../src/stores/spaces/SpaceStore";
|
||||||
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||||
import { type SpaceNotificationState } from "../../../../../src/stores/notifications/SpaceNotificationState";
|
import { type SpaceNotificationState } from "../../../../../src/stores/notifications/SpaceNotificationState";
|
||||||
@@ -124,12 +124,13 @@ describe("<SpacePanel />", () => {
|
|||||||
isVersionSupported: jest.fn().mockResolvedValue(true),
|
isVersionSupported: jest.fn().mockResolvedValue(true),
|
||||||
doesServerSupportUnstableFeature: jest.fn().mockResolvedValue(false),
|
doesServerSupportUnstableFeature: jest.fn().mockResolvedValue(false),
|
||||||
} as unknown as MatrixClient;
|
} as unknown as MatrixClient;
|
||||||
const SpacePanel = wrapInSdkContext(wrapInMatrixClientContext(UnwrappedSpacePanel), SDKContextClass.instance);
|
const sdkContext = new TestSDKContext();
|
||||||
|
const SpacePanel = wrapInSdkContext(wrapInMatrixClientContext(UnwrappedSpacePanel), sdkContext);
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
|
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
|
||||||
jest.spyOn(MatrixClientPeg, "safeGet").mockReturnValue(mockClient);
|
jest.spyOn(MatrixClientPeg, "safeGet").mockReturnValue(mockClient);
|
||||||
SDKContextClass.instance.client = mockClient;
|
sdkContext._client = mockClient;
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ import { SDKContextClass } from "../../../src/contexts/SDKContextClass";
|
|||||||
import { OidcClientStore } from "../../../src/stores/oidc/OidcClientStore";
|
import { OidcClientStore } from "../../../src/stores/oidc/OidcClientStore";
|
||||||
import { UserProfilesStore } from "../../../src/stores/UserProfilesStore";
|
import { UserProfilesStore } from "../../../src/stores/UserProfilesStore";
|
||||||
import { createTestClient } from "../../test-utils";
|
import { createTestClient } from "../../test-utils";
|
||||||
|
import { TestSDKContext } from "../TestSDKContext.ts";
|
||||||
|
|
||||||
describe("SDKContextClass", () => {
|
describe("SDKContextClass", () => {
|
||||||
let sdkContext = SDKContextClass.instance;
|
let sdkContext: TestSDKContext;
|
||||||
let client: MatrixClient;
|
let client: MatrixClient;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
@@ -22,7 +23,7 @@ describe("SDKContextClass", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
sdkContext = new SDKContextClass();
|
sdkContext = new TestSDKContext();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("instance should always return the same instance", () => {
|
it("instance should always return the same instance", () => {
|
||||||
@@ -40,7 +41,7 @@ describe("SDKContextClass", () => {
|
|||||||
|
|
||||||
describe("when SDKContext has a client", () => {
|
describe("when SDKContext has a client", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
sdkContext.client = client;
|
sdkContext._client = client;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("userProfilesStore should return a UserProfilesStore", () => {
|
it("userProfilesStore should return a UserProfilesStore", () => {
|
||||||
@@ -53,6 +54,7 @@ describe("SDKContextClass", () => {
|
|||||||
it("onLoggedOut should clear the UserProfilesStore", () => {
|
it("onLoggedOut should clear the UserProfilesStore", () => {
|
||||||
const store = sdkContext.userProfilesStore;
|
const store = sdkContext.userProfilesStore;
|
||||||
sdkContext.onLoggedOut();
|
sdkContext.onLoggedOut();
|
||||||
|
sdkContext._client = client;
|
||||||
expect(sdkContext.userProfilesStore).not.toBe(store);
|
expect(sdkContext.userProfilesStore).not.toBe(store);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { EventEmitter } from "events";
|
|||||||
import { stubClient } from "../../test-utils";
|
import { stubClient } from "../../test-utils";
|
||||||
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
||||||
import { SDKContext } from "../../../src/contexts/SDKContext";
|
import { SDKContext } from "../../../src/contexts/SDKContext";
|
||||||
import { SDKContextClass } from "../../../src/contexts/SDKContextClass";
|
import { TestSDKContext } from "../TestSDKContext.ts";
|
||||||
import { ScopedRoomContextProvider } from "../../../src/contexts/ScopedRoomContext";
|
import { ScopedRoomContextProvider } from "../../../src/contexts/ScopedRoomContext";
|
||||||
import RoomContext, { type RoomContextType } from "../../../src/contexts/RoomContext";
|
import RoomContext, { type RoomContextType } from "../../../src/contexts/RoomContext";
|
||||||
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
||||||
@@ -22,7 +22,7 @@ import { ModuleApi } from "../../../src/modules/Api";
|
|||||||
|
|
||||||
describe("ExtrasApi", () => {
|
describe("ExtrasApi", () => {
|
||||||
let client: MatrixClient;
|
let client: MatrixClient;
|
||||||
let sdkContext: SDKContextClass;
|
let sdkContext: TestSDKContext;
|
||||||
let room: Room;
|
let room: Room;
|
||||||
let roomContext: RoomContextType;
|
let roomContext: RoomContextType;
|
||||||
|
|
||||||
@@ -31,8 +31,8 @@ describe("ExtrasApi", () => {
|
|||||||
room = new Room("!test:room", client, "@alice:example.org", {
|
room = new Room("!test:room", client, "@alice:example.org", {
|
||||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||||
});
|
});
|
||||||
sdkContext = new SDKContextClass();
|
sdkContext = new TestSDKContext();
|
||||||
sdkContext.client = client;
|
sdkContext._client = client;
|
||||||
jest.spyOn(sdkContext.roomViewStore, "getRoomId").mockReturnValue(room.roomId);
|
jest.spyOn(sdkContext.roomViewStore, "getRoomId").mockReturnValue(room.roomId);
|
||||||
|
|
||||||
const mockRoomViewStore = new (class extends EventEmitter {
|
const mockRoomViewStore = new (class extends EventEmitter {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ describe("MemberListStore", () => {
|
|||||||
const context = new TestSDKContext();
|
const context = new TestSDKContext();
|
||||||
client = stubClient();
|
client = stubClient();
|
||||||
client.baseUrl = "https://invalid.base.url.here";
|
client.baseUrl = "https://invalid.base.url.here";
|
||||||
context.client = client;
|
context._client = client;
|
||||||
store = new MemberListStore(context);
|
store = new MemberListStore(context);
|
||||||
// alice is joined to the room.
|
// alice is joined to the room.
|
||||||
room = new Room(roomId, client, client.getUserId()!);
|
room = new Room(roomId, client, client.getUserId()!);
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ describe("RoomViewStore", function () {
|
|||||||
dis = new MatrixDispatcher();
|
dis = new MatrixDispatcher();
|
||||||
slidingSyncManager = new MockSlidingSyncManager();
|
slidingSyncManager = new MockSlidingSyncManager();
|
||||||
stores = new TestSDKContext();
|
stores = new TestSDKContext();
|
||||||
stores.client = mockClient;
|
stores._client = mockClient;
|
||||||
stores._SlidingSyncManager = slidingSyncManager;
|
stores._SlidingSyncManager = slidingSyncManager;
|
||||||
stores._PosthogAnalytics = new MockPosthogAnalytics();
|
stores._PosthogAnalytics = new MockPosthogAnalytics();
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ describe("TypingStore", () => {
|
|||||||
sendTyping: jest.fn(),
|
sendTyping: jest.fn(),
|
||||||
} as unknown as MatrixClient;
|
} as unknown as MatrixClient;
|
||||||
const context = new TestSDKContext();
|
const context = new TestSDKContext();
|
||||||
context.client = mockClient;
|
context._client = mockClient;
|
||||||
typingStore = new TypingStore(context);
|
typingStore = new TypingStore(context);
|
||||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
|
||||||
return name === "sendTypingNotifications";
|
return name === "sendTypingNotifications";
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ describe("WidgetPermissionStore", () => {
|
|||||||
);
|
);
|
||||||
mockClient = stubClient();
|
mockClient = stubClient();
|
||||||
const context = new TestSDKContext();
|
const context = new TestSDKContext();
|
||||||
context.client = mockClient;
|
context._client = mockClient;
|
||||||
widgetPermissionStore = new WidgetPermissionStore(context);
|
widgetPermissionStore = new WidgetPermissionStore(context);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import DMRoomMap from "../../../../src/utils/DMRoomMap";
|
|||||||
import { mediaFromMxc } from "../../../../src/customisations/Media";
|
import { mediaFromMxc } from "../../../../src/customisations/Media";
|
||||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||||
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
import { SDKContextClass } from "../../../../src/contexts/SDKContextClass";
|
||||||
|
import { TestSDKContext } from "../../TestSDKContext.ts";
|
||||||
|
|
||||||
jest.mock("jszip");
|
jest.mock("jszip");
|
||||||
jest.mock("../../../../src/settings/SettingsStore");
|
jest.mock("../../../../src/settings/SettingsStore");
|
||||||
@@ -93,6 +94,7 @@ const EVENT_MENTION: IRoomEvent = {
|
|||||||
describe("HTMLExport", () => {
|
describe("HTMLExport", () => {
|
||||||
let client: jest.Mocked<MatrixClient>;
|
let client: jest.Mocked<MatrixClient>;
|
||||||
let room: Room;
|
let room: Room;
|
||||||
|
let sdkContext: TestSDKContext;
|
||||||
|
|
||||||
filterConsole(
|
filterConsole(
|
||||||
"Starting export",
|
"Starting export",
|
||||||
@@ -111,7 +113,10 @@ describe("HTMLExport", () => {
|
|||||||
jest.setSystemTime(REPEATABLE_DATE);
|
jest.setSystemTime(REPEATABLE_DATE);
|
||||||
|
|
||||||
client = stubClient() as jest.Mocked<MatrixClient>;
|
client = stubClient() as jest.Mocked<MatrixClient>;
|
||||||
SDKContextClass.instance.client = client;
|
sdkContext = new TestSDKContext();
|
||||||
|
// @ts-ignore HTMLExport uses SDKContext in the constructor
|
||||||
|
SDKContextClass.instance = sdkContext;
|
||||||
|
sdkContext._client = client;
|
||||||
DMRoomMap.makeShared(client);
|
DMRoomMap.makeShared(client);
|
||||||
|
|
||||||
room = new Room("!myroom:example.org", client, "@me:example.org");
|
room = new Room("!myroom:example.org", client, "@me:example.org");
|
||||||
|
|||||||
@@ -17,10 +17,13 @@ import { Action } from "../../../src/dispatcher/actions";
|
|||||||
import { UserTab } from "../../../src/components/views/dialogs/UserTab";
|
import { UserTab } from "../../../src/components/views/dialogs/UserTab";
|
||||||
import Modal from "../../../src/Modal";
|
import Modal from "../../../src/Modal";
|
||||||
import FeedbackDialog from "../../../src/components/views/dialogs/FeedbackDialog";
|
import FeedbackDialog from "../../../src/components/views/dialogs/FeedbackDialog";
|
||||||
|
import { TestSDKContext } from "../../unit-tests/TestSDKContext.ts";
|
||||||
|
|
||||||
describe("UserMenuViewModel", () => {
|
describe("UserMenuViewModel", () => {
|
||||||
let dispatcher: MatrixDispatcher;
|
let dispatcher: MatrixDispatcher;
|
||||||
let client: MockedObject<MatrixClient>;
|
let client: MockedObject<MatrixClient>;
|
||||||
|
let sdkContext: TestSDKContext;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
dispatcher = new MatrixDispatcher();
|
dispatcher = new MatrixDispatcher();
|
||||||
client = getMockClientWithEventEmitter({
|
client = getMockClientWithEventEmitter({
|
||||||
@@ -29,13 +32,15 @@ describe("UserMenuViewModel", () => {
|
|||||||
getAuthMetadata: jest.fn().mockRejectedValue(new MatrixError({ errcode: "M_UNRECOGNIZED" }, 404)),
|
getAuthMetadata: jest.fn().mockRejectedValue(new MatrixError({ errcode: "M_UNRECOGNIZED" }, 404)),
|
||||||
setExtendedProfileProperty: jest.fn().mockResolvedValue(undefined),
|
setExtendedProfileProperty: jest.fn().mockResolvedValue(undefined),
|
||||||
});
|
});
|
||||||
SDKContextClass.instance.client = client;
|
sdkContext = new TestSDKContext();
|
||||||
|
// @ts-ignore UserMenuViewModel uses SDKContext in the constructor
|
||||||
|
SDKContextClass.instance = sdkContext;
|
||||||
|
sdkContext._client = client;
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
SdkConfig.reset();
|
SdkConfig.reset();
|
||||||
SDKContextClass.instance.onLoggedOut();
|
SDKContextClass.instance.onLoggedOut();
|
||||||
SDKContextClass.instance.client = undefined;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should generate a menu options for a logged in client", () => {
|
it("should generate a menu options for a logged in client", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user