Eliminate the use of MatrixClientPeg in utils (#10910)
This commit is contained in:
parent
a0c2676c38
commit
30429df948
108 changed files with 409 additions and 325 deletions
|
@ -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(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue