You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-09 08:42:50 +03:00
Eliminate the use of MatrixClientPeg in utils (#10910)
This commit is contained in:
committed by
GitHub
parent
a0c2676c38
commit
30429df948
@@ -112,7 +112,7 @@ describe("MessagePanel", function () {
|
||||
return arg === "showDisplaynameChanges";
|
||||
});
|
||||
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
@@ -91,7 +91,7 @@ describe("PipContainer", () => {
|
||||
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.get());
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
|
||||
room = new Room("!1:example.org", client, "@alice:example.org", {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
|
@@ -48,7 +48,7 @@ describe("RightPanel", () => {
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
cli = mocked(MatrixClientPeg.get());
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(cli);
|
||||
context = new SdkContextClass();
|
||||
context.client = cli;
|
||||
RightPanel = wrapInSdkContext(RightPanelBase, context);
|
||||
|
@@ -83,7 +83,7 @@ describe("RoomView", () => {
|
||||
room.on(RoomEvent.Timeline, (...args) => cli.emit(RoomEvent.Timeline, ...args));
|
||||
room.on(RoomEvent.TimelineReset, (...args) => cli.emit(RoomEvent.TimelineReset, ...args));
|
||||
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(cli);
|
||||
stores = new SdkContextClass();
|
||||
stores.client = cli;
|
||||
stores.rightPanelStore.useUnitTestClient(cli);
|
||||
@@ -457,7 +457,7 @@ describe("RoomView", () => {
|
||||
});
|
||||
|
||||
it("the last Jitsi widget should be removed", () => {
|
||||
expect(WidgetUtils.setRoomWidget).toHaveBeenCalledWith(room.roomId, widget2Id);
|
||||
expect(WidgetUtils.setRoomWidget).toHaveBeenCalledWith(cli, room.roomId, widget2Id);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -131,7 +131,7 @@ describe("ThreadView", () => {
|
||||
|
||||
rootEvent = res.rootEvent;
|
||||
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(mockClient);
|
||||
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(SENDER);
|
||||
});
|
||||
|
||||
|
@@ -90,7 +90,7 @@ describe("ForwardDialog", () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(mockClient);
|
||||
jest.clearAllMocks();
|
||||
mockClient.getUserId.mockReturnValue("@bob:example.org");
|
||||
mockClient.getSafeUserId.mockReturnValue("@bob:example.org");
|
||||
|
@@ -143,7 +143,7 @@ describe("InviteDialog", () => {
|
||||
getClientWellKnown: jest.fn().mockResolvedValue({}),
|
||||
});
|
||||
SdkConfig.put({ validated_server_config: {} as ValidatedServerConfig } as IConfigOptions);
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(mockClient);
|
||||
jest.clearAllMocks();
|
||||
|
||||
room = new Room(roomId, mockClient, mockClient.getSafeUserId());
|
||||
|
@@ -86,7 +86,7 @@ describe("AppTile", () => {
|
||||
cli.hasLazyLoadMembersEnabled = () => false;
|
||||
|
||||
// Init misc. startup deps
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(cli);
|
||||
|
||||
r1 = new Room("r1", cli, "@name:example.com");
|
||||
r2 = new Room("r2", cli, "@name:example.com");
|
||||
|
@@ -75,7 +75,7 @@ describe("<Pill>", () => {
|
||||
beforeEach(() => {
|
||||
client = mocked(stubClient());
|
||||
SdkContextClass.instance.client = client;
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
room1 = new Room(room1Id, client, user1Id);
|
||||
room1.name = "Room 1";
|
||||
const user1JoinRoom1Event = mkRoomMemberJoinEvent(user1Id, room1Id, {
|
||||
|
@@ -120,7 +120,7 @@ describe("<TextualBody />", () => {
|
||||
);
|
||||
|
||||
it("renders m.emote correctly", () => {
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(defaultMatrixClient);
|
||||
|
||||
const ev = mkEvent({
|
||||
type: "m.room.message",
|
||||
@@ -140,7 +140,7 @@ describe("<TextualBody />", () => {
|
||||
});
|
||||
|
||||
it("renders m.notice correctly", () => {
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(defaultMatrixClient);
|
||||
|
||||
const ev = mkEvent({
|
||||
type: "m.room.message",
|
||||
@@ -161,7 +161,7 @@ describe("<TextualBody />", () => {
|
||||
|
||||
describe("renders plain-text m.text correctly", () => {
|
||||
beforeEach(() => {
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(defaultMatrixClient);
|
||||
});
|
||||
|
||||
it("simple message renders as expected", () => {
|
||||
@@ -264,7 +264,7 @@ describe("<TextualBody />", () => {
|
||||
isGuest: () => false,
|
||||
mxcUrlToHttp: (s: string) => s,
|
||||
});
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(defaultMatrixClient);
|
||||
});
|
||||
|
||||
it("italics, bold, underline and strikethrough render as expected", () => {
|
||||
@@ -408,7 +408,7 @@ describe("<TextualBody />", () => {
|
||||
isGuest: () => false,
|
||||
mxcUrlToHttp: (s: string) => s,
|
||||
});
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(defaultMatrixClient);
|
||||
|
||||
const ev = mkRoomTextMessage("Visit https://matrix.org/");
|
||||
const { container, rerender } = getComponent(
|
||||
|
@@ -71,7 +71,7 @@ describe("<RoomSummaryCard />", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(mockClient);
|
||||
|
||||
mockClient.getRoom.mockReturnValue(room);
|
||||
jest.spyOn(room, "isElementVideoRoom").mockRestore();
|
||||
|
@@ -97,7 +97,7 @@ describe("<EditMessageComposer/>", () => {
|
||||
|
||||
userEvent.setup();
|
||||
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(mockClient);
|
||||
|
||||
jest.spyOn(Autocompleter.prototype, "getCompletions").mockResolvedValue([
|
||||
{
|
||||
|
@@ -47,7 +47,7 @@ describe("NewRoomIntro", () => {
|
||||
|
||||
beforeAll(() => {
|
||||
client = stubClient();
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
});
|
||||
|
||||
describe("for a DM Room", () => {
|
||||
|
@@ -112,7 +112,7 @@ describe("RoomHeader", () => {
|
||||
[MediaDeviceKindEnum.AudioOutput]: [],
|
||||
});
|
||||
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(carol.userId);
|
||||
});
|
||||
|
||||
@@ -761,7 +761,7 @@ function createRoom(info: IRoomCreationInfo) {
|
||||
};
|
||||
}
|
||||
|
||||
DMRoomMap.makeShared().start();
|
||||
DMRoomMap.makeShared(client).start();
|
||||
|
||||
const room = new Room(roomId, client, userId, {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
|
@@ -33,8 +33,9 @@ jest.mock("../../../../src/IdentityAuthClient", () => {
|
||||
jest.useRealTimers();
|
||||
|
||||
const createRoom = (roomId: string, userId: string): Room => {
|
||||
const newRoom = new Room(roomId, MatrixClientPeg.get(), userId, {});
|
||||
DMRoomMap.makeShared().start();
|
||||
const cli = MatrixClientPeg.get();
|
||||
const newRoom = new Room(roomId, cli, userId, {});
|
||||
DMRoomMap.makeShared(cli).start();
|
||||
return newRoom;
|
||||
};
|
||||
|
||||
|
@@ -42,7 +42,7 @@ describe("RoomPreviewCard", () => {
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.get());
|
||||
client.getUserId.mockReturnValue("@alice:example.org");
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
|
||||
room = new Room("!1:example.org", client, "@alice:example.org", {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
|
@@ -90,7 +90,7 @@ describe("RoomTile", () => {
|
||||
|
||||
client = mocked(stubClient());
|
||||
sdkContext.client = client;
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
|
||||
room = new Room("!1:example.org", client, "@alice:example.org", {
|
||||
pendingEventOrdering: PendingEventOrdering.Detached,
|
||||
|
@@ -159,7 +159,7 @@ describe("<SpacePanel />", () => {
|
||||
mkStubRoom("!room2:server", "Room 2", mockClient),
|
||||
mkStubRoom("!room3:server", "Room 3", mockClient),
|
||||
];
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(mockClient);
|
||||
jest.useFakeTimers();
|
||||
|
||||
const { getByLabelText } = render(<SpacePanel />);
|
||||
|
@@ -40,7 +40,7 @@ jest.mock("../../../../src/stores/spaces/SpaceStore", () => {
|
||||
describe("SpaceButton", () => {
|
||||
stubClient();
|
||||
const space = mkRoom(MatrixClientPeg.get(), "!1:example.org");
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(MatrixClientPeg.get());
|
||||
|
||||
const dispatchSpy = jest.spyOn(defaultDispatcher, "dispatch");
|
||||
|
||||
|
@@ -37,7 +37,7 @@ describe("RightPanelStore", () => {
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
cli = mocked(MatrixClientPeg.get());
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(cli);
|
||||
|
||||
// Make sure we start with a clean store
|
||||
store.reset();
|
||||
|
@@ -162,7 +162,7 @@ describe("RoomListStore", () => {
|
||||
room1.updateMyMembership("join");
|
||||
room2.updateMyMembership("join");
|
||||
room3.updateMyMembership("join");
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
const { store } = createStore();
|
||||
client.getVisibleRooms = jest.fn().mockReturnValue([room1, room2, room3]);
|
||||
|
||||
@@ -274,7 +274,7 @@ describe("RoomListStore", () => {
|
||||
|
||||
it("Passes the feature flag on to the client when asking for visible rooms", () => {
|
||||
// Given a store that we can ask for a room list
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
const { store } = createStore();
|
||||
client.getVisibleRooms = jest.fn().mockReturnValue([]);
|
||||
|
||||
|
@@ -41,7 +41,7 @@ describe("Algorithm", () => {
|
||||
beforeEach(() => {
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.get());
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
|
||||
algorithm = new Algorithm();
|
||||
algorithm.start();
|
||||
|
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
import { getEventDisplayInfo } from "../../src/utils/EventRenderingUtils";
|
||||
import { VoiceBroadcastInfoState } from "../../src/voice-broadcast";
|
||||
import { mkVoiceBroadcastInfoStateEvent } from "../voice-broadcast/utils/test-utils";
|
||||
import { createTestClient } from "../test-utils";
|
||||
|
||||
describe("getEventDisplayInfo", () => {
|
||||
const mkBroadcastInfoEvent = (state: VoiceBroadcastInfoState) => {
|
||||
@@ -24,7 +25,7 @@ describe("getEventDisplayInfo", () => {
|
||||
};
|
||||
|
||||
it("should return the expected value for a broadcast started event", () => {
|
||||
expect(getEventDisplayInfo(mkBroadcastInfoEvent(VoiceBroadcastInfoState.Started), false))
|
||||
expect(getEventDisplayInfo(createTestClient(), mkBroadcastInfoEvent(VoiceBroadcastInfoState.Started), false))
|
||||
.toMatchInlineSnapshot(`
|
||||
{
|
||||
"hasRenderer": true,
|
||||
@@ -38,7 +39,7 @@ describe("getEventDisplayInfo", () => {
|
||||
});
|
||||
|
||||
it("should return the expected value for a broadcast stopped event", () => {
|
||||
expect(getEventDisplayInfo(mkBroadcastInfoEvent(VoiceBroadcastInfoState.Stopped), false))
|
||||
expect(getEventDisplayInfo(createTestClient(), mkBroadcastInfoEvent(VoiceBroadcastInfoState.Stopped), false))
|
||||
.toMatchInlineSnapshot(`
|
||||
{
|
||||
"hasRenderer": true,
|
||||
|
@@ -253,20 +253,20 @@ describe("EventUtils", () => {
|
||||
|
||||
describe("canEditContent()", () => {
|
||||
it.each<TestCase>(uneditableCases)("returns false for %s", (_description, event) => {
|
||||
expect(canEditContent(event)).toBe(false);
|
||||
expect(canEditContent(mockClient, event)).toBe(false);
|
||||
});
|
||||
|
||||
it.each<TestCase>(editableCases)("returns true for %s", (_description, event) => {
|
||||
expect(canEditContent(event)).toBe(true);
|
||||
expect(canEditContent(mockClient, event)).toBe(true);
|
||||
});
|
||||
});
|
||||
describe("canEditOwnContent()", () => {
|
||||
it.each<TestCase>(uneditableCases)("returns false for %s", (_description, event) => {
|
||||
expect(canEditOwnEvent(event)).toBe(false);
|
||||
expect(canEditOwnEvent(mockClient, event)).toBe(false);
|
||||
});
|
||||
|
||||
it.each<TestCase>(editableCases)("returns true for %s", (_description, event) => {
|
||||
expect(canEditOwnEvent(event)).toBe(true);
|
||||
expect(canEditOwnEvent(mockClient, event)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -460,6 +460,7 @@ describe("EventUtils", () => {
|
||||
findEditableEvent({
|
||||
events: [],
|
||||
isForward: true,
|
||||
matrixClient: mockClient,
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
@@ -90,7 +90,7 @@ describe("MultiInviter", () => {
|
||||
return MXID_PROFILE_STATES[userId] || Promise.reject();
|
||||
});
|
||||
|
||||
inviter = new MultiInviter(ROOMID);
|
||||
inviter = new MultiInviter(client, ROOMID);
|
||||
});
|
||||
|
||||
describe("invite", () => {
|
||||
|
@@ -94,7 +94,7 @@ describe("HTMLExport", () => {
|
||||
jest.setSystemTime(REPEATABLE_DATE);
|
||||
|
||||
client = stubClient() as jest.Mocked<MatrixClient>;
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
|
||||
room = new Room("!myroom:example.org", client, "@me:example.org");
|
||||
client.getRoom.mockReturnValue(room);
|
||||
|
@@ -41,7 +41,7 @@ describe("leaveRoomBehaviour", () => {
|
||||
beforeEach(async () => {
|
||||
stubClient();
|
||||
client = mocked(MatrixClientPeg.get());
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
|
||||
room = mkRoom(client, "!1:example.org");
|
||||
space = mkRoom(client, "!2:example.org");
|
||||
@@ -87,7 +87,7 @@ describe("leaveRoomBehaviour", () => {
|
||||
it("returns to the home page after leaving a room outside of a space that was being viewed", async () => {
|
||||
viewRoom(room);
|
||||
|
||||
await leaveRoomBehaviour(room.roomId);
|
||||
await leaveRoomBehaviour(client, room.roomId);
|
||||
await expectDispatch({ action: Action.ViewHomePage });
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ describe("leaveRoomBehaviour", () => {
|
||||
viewRoom(room);
|
||||
SpaceStore.instance.setActiveSpace(space.roomId, false);
|
||||
|
||||
await leaveRoomBehaviour(room.roomId);
|
||||
await leaveRoomBehaviour(client, room.roomId);
|
||||
await expectDispatch({
|
||||
action: Action.ViewRoom,
|
||||
room_id: space.roomId,
|
||||
@@ -110,7 +110,7 @@ describe("leaveRoomBehaviour", () => {
|
||||
viewRoom(space);
|
||||
SpaceStore.instance.setActiveSpace(space.roomId, false);
|
||||
|
||||
await leaveRoomBehaviour(space.roomId);
|
||||
await leaveRoomBehaviour(client, space.roomId);
|
||||
await expectDispatch({ action: Action.ViewHomePage });
|
||||
});
|
||||
|
||||
@@ -122,7 +122,7 @@ describe("leaveRoomBehaviour", () => {
|
||||
viewRoom(room);
|
||||
SpaceStore.instance.setActiveSpace(room.roomId, false);
|
||||
|
||||
await leaveRoomBehaviour(room.roomId);
|
||||
await leaveRoomBehaviour(client, room.roomId);
|
||||
await expectDispatch({
|
||||
action: Action.ViewRoom,
|
||||
room_id: space.roomId,
|
||||
@@ -136,7 +136,7 @@ describe("leaveRoomBehaviour", () => {
|
||||
});
|
||||
|
||||
it("Passes through the dynamic predecessor setting", async () => {
|
||||
await leaveRoomBehaviour(room.roomId);
|
||||
await leaveRoomBehaviour(client, room.roomId);
|
||||
expect(client.getRoomUpgradeHistory).toHaveBeenCalledWith(room.roomId, false, false);
|
||||
});
|
||||
});
|
||||
@@ -150,7 +150,7 @@ describe("leaveRoomBehaviour", () => {
|
||||
});
|
||||
|
||||
it("Passes through the dynamic predecessor setting", async () => {
|
||||
await leaveRoomBehaviour(room.roomId);
|
||||
await leaveRoomBehaviour(client, room.roomId);
|
||||
expect(client.getRoomUpgradeHistory).toHaveBeenCalledWith(room.roomId, false, true);
|
||||
});
|
||||
});
|
||||
|
@@ -342,13 +342,13 @@ describe("Permalinks", function () {
|
||||
makeMemberWithPL(roomId, "@bob:second", 0),
|
||||
]);
|
||||
});
|
||||
const result = makeRoomPermalink("!somewhere:example.org");
|
||||
const result = makeRoomPermalink(mockClient, "!somewhere:example.org");
|
||||
expect(result).toBe("https://matrix.to/#/!somewhere:example.org?via=first&via=second");
|
||||
});
|
||||
|
||||
it("should generate a room permalink for room aliases with no candidate servers", function () {
|
||||
mockClient.getRoom.mockReturnValue(null);
|
||||
const result = makeRoomPermalink("#somewhere:example.org");
|
||||
const result = makeRoomPermalink(mockClient, "#somewhere:example.org");
|
||||
expect(result).toBe("https://matrix.to/#/#somewhere:example.org");
|
||||
});
|
||||
|
||||
@@ -359,7 +359,7 @@ describe("Permalinks", function () {
|
||||
makeMemberWithPL(roomId, "@bob:second", 0),
|
||||
]);
|
||||
});
|
||||
const result = makeRoomPermalink("#somewhere:example.org");
|
||||
const result = makeRoomPermalink(mockClient, "#somewhere:example.org");
|
||||
expect(result).toBe("https://matrix.to/#/#somewhere:example.org");
|
||||
});
|
||||
|
||||
|
@@ -62,14 +62,14 @@ describe("pillify", () => {
|
||||
],
|
||||
};
|
||||
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(cli);
|
||||
});
|
||||
|
||||
it("should do nothing for empty element", () => {
|
||||
const { container } = render(<div />);
|
||||
const originalHtml = container.outerHTML;
|
||||
const containers: Element[] = [];
|
||||
pillifyLinks([container], event, containers);
|
||||
pillifyLinks(MatrixClientPeg.get(), [container], event, containers);
|
||||
expect(containers).toHaveLength(0);
|
||||
expect(container.outerHTML).toEqual(originalHtml);
|
||||
});
|
||||
@@ -77,7 +77,7 @@ describe("pillify", () => {
|
||||
it("should pillify @room", () => {
|
||||
const { container } = render(<div>@room</div>);
|
||||
const containers: Element[] = [];
|
||||
pillifyLinks([container], event, containers);
|
||||
pillifyLinks(MatrixClientPeg.get(), [container], event, containers);
|
||||
expect(containers).toHaveLength(1);
|
||||
expect(container.querySelector(".mx_Pill.mx_AtRoomPill")?.textContent).toBe("!@room");
|
||||
});
|
||||
@@ -85,10 +85,10 @@ describe("pillify", () => {
|
||||
it("should not double up pillification on repeated calls", () => {
|
||||
const { container } = render(<div>@room</div>);
|
||||
const containers: Element[] = [];
|
||||
pillifyLinks([container], event, containers);
|
||||
pillifyLinks([container], event, containers);
|
||||
pillifyLinks([container], event, containers);
|
||||
pillifyLinks([container], event, containers);
|
||||
pillifyLinks(MatrixClientPeg.get(), [container], event, containers);
|
||||
pillifyLinks(MatrixClientPeg.get(), [container], event, containers);
|
||||
pillifyLinks(MatrixClientPeg.get(), [container], event, containers);
|
||||
pillifyLinks(MatrixClientPeg.get(), [container], event, containers);
|
||||
expect(containers).toHaveLength(1);
|
||||
expect(container.querySelector(".mx_Pill.mx_AtRoomPill")?.textContent).toBe("!@room");
|
||||
});
|
||||
|
@@ -33,7 +33,7 @@ describe("shouldEncryptRoomWithSingle3rdPartyInvite", () => {
|
||||
|
||||
beforeAll(() => {
|
||||
client = stubClient();
|
||||
DMRoomMap.makeShared();
|
||||
DMRoomMap.makeShared(client);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
Reference in New Issue
Block a user