Replace broadcast instance with SDKContext (#9824)
This commit is contained in:
@@ -18,18 +18,20 @@ import React from "react";
|
||||
import { act, render, RenderResult } from "@testing-library/react";
|
||||
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import UserMenu from "../../../src/components/structures/UserMenu";
|
||||
import { stubClient } from "../../test-utils";
|
||||
import UnwrappedUserMenu from "../../../src/components/structures/UserMenu";
|
||||
import { stubClient, wrapInSdkContext } from "../../test-utils";
|
||||
import {
|
||||
VoiceBroadcastInfoState,
|
||||
VoiceBroadcastRecording,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
} from "../../../src/voice-broadcast";
|
||||
import { mkVoiceBroadcastInfoStateEvent } from "../../voice-broadcast/utils/test-utils";
|
||||
import { TestSdkContext } from "../../TestSdkContext";
|
||||
|
||||
describe("<UserMenu>", () => {
|
||||
let client: MatrixClient;
|
||||
let renderResult: RenderResult;
|
||||
let sdkContext: TestSdkContext;
|
||||
let voiceBroadcastInfoEvent: MatrixEvent;
|
||||
let voiceBroadcastRecording: VoiceBroadcastRecording;
|
||||
let voiceBroadcastRecordingsStore: VoiceBroadcastRecordingsStore;
|
||||
@@ -42,15 +44,19 @@ describe("<UserMenu>", () => {
|
||||
client.getUserId() || "",
|
||||
client.getDeviceId() || "",
|
||||
);
|
||||
voiceBroadcastRecording = new VoiceBroadcastRecording(voiceBroadcastInfoEvent, client);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
voiceBroadcastRecordingsStore = VoiceBroadcastRecordingsStore.instance();
|
||||
sdkContext = new TestSdkContext();
|
||||
voiceBroadcastRecordingsStore = new VoiceBroadcastRecordingsStore();
|
||||
sdkContext._VoiceBroadcastRecordingsStore = voiceBroadcastRecordingsStore;
|
||||
|
||||
voiceBroadcastRecording = new VoiceBroadcastRecording(voiceBroadcastInfoEvent, client);
|
||||
});
|
||||
|
||||
describe("when rendered", () => {
|
||||
beforeEach(() => {
|
||||
const UserMenu = wrapInSdkContext(UnwrappedUserMenu, sdkContext);
|
||||
renderResult = render(<UserMenu isPanelCollapsed={true} />);
|
||||
});
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@ import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import SpacePanel from "../../../../src/components/views/spaces/SpacePanel";
|
||||
import UnwrappedSpacePanel from "../../../../src/components/views/spaces/SpacePanel";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { SpaceKey } from "../../../../src/stores/spaces";
|
||||
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
|
||||
import { UIComponent } from "../../../../src/settings/UIFeature";
|
||||
import { wrapInSdkContext } from "../../../test-utils";
|
||||
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
|
||||
|
||||
jest.mock("../../../../src/stores/spaces/SpaceStore", () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
@@ -49,6 +51,7 @@ describe("<SpacePanel />", () => {
|
||||
isGuest: jest.fn(),
|
||||
getAccountData: jest.fn(),
|
||||
} as unknown as MatrixClient;
|
||||
const SpacePanel = wrapInSdkContext(UnwrappedSpacePanel, SdkContextClass.instance);
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -23,11 +23,8 @@ import { stubClient, mkRoom, mkEvent } from "../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
import { StopGapWidget } from "../../../src/stores/widgets/StopGapWidget";
|
||||
import { ElementWidgetActions } from "../../../src/stores/widgets/ElementWidgetActions";
|
||||
import {
|
||||
VoiceBroadcastInfoEventType,
|
||||
VoiceBroadcastRecording,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
} from "../../../src/voice-broadcast";
|
||||
import { VoiceBroadcastInfoEventType, VoiceBroadcastRecording } from "../../../src/voice-broadcast";
|
||||
import { SdkContextClass } from "../../../src/contexts/SDKContext";
|
||||
|
||||
jest.mock("matrix-widget-api/lib/ClientWidgetApi");
|
||||
|
||||
@@ -90,7 +87,9 @@ describe("StopGapWidget", () => {
|
||||
});
|
||||
voiceBroadcastRecording = new VoiceBroadcastRecording(voiceBroadcastInfoEvent, client);
|
||||
jest.spyOn(voiceBroadcastRecording, "pause");
|
||||
jest.spyOn(VoiceBroadcastRecordingsStore.instance(), "getCurrent").mockReturnValue(voiceBroadcastRecording);
|
||||
jest.spyOn(SdkContextClass.instance.voiceBroadcastRecordingsStore, "getCurrent").mockReturnValue(
|
||||
voiceBroadcastRecording,
|
||||
);
|
||||
});
|
||||
|
||||
describe(`and receiving a action:${ElementWidgetActions.JoinCall} message`, () => {
|
||||
|
||||
@@ -20,19 +20,18 @@ import { mocked } from "jest-mock";
|
||||
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
VoiceBroadcastBody,
|
||||
VoiceBroadcastBody as UnwrappedVoiceBroadcastBody,
|
||||
VoiceBroadcastInfoState,
|
||||
VoiceBroadcastRecordingBody,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
VoiceBroadcastRecording,
|
||||
VoiceBroadcastPlaybackBody,
|
||||
VoiceBroadcastPlayback,
|
||||
VoiceBroadcastPlaybacksStore,
|
||||
} from "../../../src/voice-broadcast";
|
||||
import { stubClient } from "../../test-utils";
|
||||
import { stubClient, wrapInSdkContext } from "../../test-utils";
|
||||
import { mkVoiceBroadcastInfoStateEvent } from "../utils/test-utils";
|
||||
import { MediaEventHelper } from "../../../src/utils/MediaEventHelper";
|
||||
import { RoomPermalinkCreator } from "../../../src/utils/permalinks/Permalinks";
|
||||
import { SdkContextClass } from "../../../src/contexts/SDKContext";
|
||||
|
||||
jest.mock("../../../src/voice-broadcast/components/molecules/VoiceBroadcastRecordingBody", () => ({
|
||||
VoiceBroadcastRecordingBody: jest.fn(),
|
||||
@@ -57,6 +56,7 @@ describe("VoiceBroadcastBody", () => {
|
||||
let testPlayback: VoiceBroadcastPlayback;
|
||||
|
||||
const renderVoiceBroadcast = () => {
|
||||
const VoiceBroadcastBody = wrapInSdkContext(UnwrappedVoiceBroadcastBody, SdkContextClass.instance);
|
||||
render(
|
||||
<VoiceBroadcastBody
|
||||
mxEvent={infoEvent}
|
||||
@@ -66,7 +66,7 @@ describe("VoiceBroadcastBody", () => {
|
||||
permalinkCreator={new RoomPermalinkCreator(room)}
|
||||
/>,
|
||||
);
|
||||
testRecording = VoiceBroadcastRecordingsStore.instance().getByInfoEvent(infoEvent, client);
|
||||
testRecording = SdkContextClass.instance.voiceBroadcastRecordingsStore.getByInfoEvent(infoEvent, client);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -108,7 +108,7 @@ describe("VoiceBroadcastBody", () => {
|
||||
return null;
|
||||
});
|
||||
|
||||
jest.spyOn(VoiceBroadcastRecordingsStore.instance(), "getByInfoEvent").mockImplementation(
|
||||
jest.spyOn(SdkContextClass.instance.voiceBroadcastRecordingsStore, "getByInfoEvent").mockImplementation(
|
||||
(getEvent: MatrixEvent, getClient: MatrixClient): VoiceBroadcastRecording => {
|
||||
if (getEvent === infoEvent && getClient === client) {
|
||||
return testRecording;
|
||||
@@ -118,7 +118,7 @@ describe("VoiceBroadcastBody", () => {
|
||||
},
|
||||
);
|
||||
|
||||
jest.spyOn(VoiceBroadcastPlaybacksStore.instance(), "getByInfoEvent").mockImplementation(
|
||||
jest.spyOn(SdkContextClass.instance.voiceBroadcastPlaybacksStore, "getByInfoEvent").mockImplementation(
|
||||
(getEvent: MatrixEvent): VoiceBroadcastPlayback => {
|
||||
if (getEvent === infoEvent) {
|
||||
return testPlayback;
|
||||
|
||||
Reference in New Issue
Block a user