1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-28 15:22:05 +03:00

Avoid using deprecated exports & methods from matrix-js-sdk (#12359)

This commit is contained in:
Michael Telatynski
2024-03-25 12:21:02 +00:00
committed by GitHub
parent 11912a0da0
commit 4941327c78
24 changed files with 73 additions and 80 deletions

View File

@ -15,7 +15,8 @@ limitations under the License.
*/
import { mocked } from "jest-mock";
import { IImageInfo, ISendEventResponse, MatrixClient, RelationType, UploadResponse } from "matrix-js-sdk/src/matrix";
import { ISendEventResponse, MatrixClient, RelationType, UploadResponse } from "matrix-js-sdk/src/matrix";
import { ImageInfo } from "matrix-js-sdk/src/types";
import { defer } from "matrix-js-sdk/src/utils";
import encrypt, { IEncryptedFile } from "matrix-encrypt-attachment";
@ -43,7 +44,7 @@ const createElement = document.createElement.bind(document);
describe("ContentMessages", () => {
const stickerUrl = "https://example.com/sticker";
const roomId = "!room:example.com";
const imageInfo = {} as unknown as IImageInfo;
const imageInfo = {} as unknown as ImageInfo;
const text = "test sticker";
let client: MatrixClient;
let contentMessages: ContentMessages;

View File

@ -22,6 +22,7 @@ import {
LocationAssetType,
M_ASSET,
M_POLL_END,
Room,
} from "matrix-js-sdk/src/matrix";
import {
@ -31,7 +32,7 @@ import {
stripHTMLReply,
stripPlainReply,
} from "../src/utils/Reply";
import { makePollStartEvent, mkEvent } from "./test-utils";
import { makePollStartEvent, mkEvent, stubClient } from "./test-utils";
import { RoomPermalinkCreator } from "../src/utils/permalinks/Permalinks";
function makeTestEvent(type: string, content: IContent): MatrixEvent {
@ -66,7 +67,7 @@ describe("Reply", () => {
room: "!room1:server",
content: {},
});
event.makeRedacted(event);
event.makeRedacted(event, new Room(event.getRoomId()!, stubClient(), event.getSender()!));
expect(getParentEventId(event)).toBeUndefined();
});
@ -182,7 +183,7 @@ But this is not
room: "!room1:server",
content: {},
});
event.makeRedacted(event);
event.makeRedacted(event, new Room(event.getRoomId()!, stubClient(), event.getSender()!));
expect(shouldDisplayReply(event)).toBe(false);
});

View File

@ -419,7 +419,7 @@ describe("TextForEvent", () => {
});
it("returns correct message for redacted poll start", () => {
pollEvent.makeRedacted(pollEvent);
pollEvent.makeRedacted(pollEvent, new Room(pollEvent.getRoomId()!, mockClient, mockClient.getSafeUserId()));
expect(textForEvent(pollEvent, mockClient)).toEqual("@a: Message deleted");
});
@ -445,7 +445,10 @@ describe("TextForEvent", () => {
});
it("returns correct message for redacted message", () => {
messageEvent.makeRedacted(messageEvent);
messageEvent.makeRedacted(
messageEvent,
new Room(messageEvent.getRoomId()!, mockClient, mockClient.getSafeUserId()),
);
expect(textForEvent(messageEvent, mockClient)).toEqual("@a: Message deleted");
});

View File

@ -63,7 +63,7 @@ describe("Unread", () => {
type: EventType.RoomMessage,
sender: aliceId,
});
redactedEvent.makeRedacted(redactedEvent);
redactedEvent.makeRedacted(redactedEvent, new Room(redactedEvent.getRoomId()!, client, aliceId));
beforeEach(() => {
jest.clearAllMocks();
@ -408,7 +408,7 @@ describe("Unread", () => {
content: {},
});
console.log("Event Id", redactedEvent.getId());
redactedEvent.makeRedacted(redactedEvent);
redactedEvent.makeRedacted(redactedEvent, room);
console.log("Event Id", redactedEvent.getId());
// Only for timeline events.
room.addLiveEvents([redactedEvent]);

View File

@ -15,7 +15,7 @@ limitations under the License.
*/
import { render } from "@testing-library/react";
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
import { EventType, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import React from "react";
import ViewSource from "../../../src/components/structures/ViewSource";
@ -43,7 +43,7 @@ describe("ViewSource", () => {
content: {},
state_key: undefined,
});
redactedMessageEvent.makeRedacted(redactionEvent);
redactedMessageEvent.makeRedacted(redactionEvent, new Room(ROOM_ID, stubClient(), SENDER));
});
beforeEach(stubClient);

View File

@ -25,6 +25,7 @@ import {
EventType,
Relations,
M_BEACON,
Room,
} from "matrix-js-sdk/src/matrix";
import MBeaconBody from "../../../../src/components/views/messages/MBeaconBody";
@ -304,10 +305,11 @@ describe("<MBeaconBody />", () => {
const redactionEvent = new MatrixEvent({ type: EventType.RoomRedaction, content: { reason: "test reason" } });
const setupRoomWithBeacon = (beaconInfoEvent: MatrixEvent, locationEvents: MatrixEvent[] = []) => {
const setupRoomWithBeacon = (beaconInfoEvent: MatrixEvent, locationEvents: MatrixEvent[] = []): Room => {
const room = makeRoomWithStateEvents([beaconInfoEvent], { roomId, mockClient });
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(beaconInfoEvent))!;
beaconInstance.addLocations(locationEvents);
return room;
};
const mockGetRelationsForEvent = (locationEvents: MatrixEvent[] = []) => {
const relations = new Relations(RelationType.Reference, M_BEACON.name, mockClient);
@ -320,12 +322,12 @@ describe("<MBeaconBody />", () => {
it("does nothing when getRelationsForEvent is falsy", () => {
const { beaconInfoEvent, location1, location2 } = makeEvents();
setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
const room = setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
getComponent({ mxEvent: beaconInfoEvent });
act(() => {
beaconInfoEvent.makeRedacted(redactionEvent);
beaconInfoEvent.makeRedacted(redactionEvent, room);
});
// no error, no redactions
@ -349,13 +351,13 @@ describe("<MBeaconBody />", () => {
it("does nothing when beacon has no related locations", async () => {
const { beaconInfoEvent } = makeEvents();
// no locations
setupRoomWithBeacon(beaconInfoEvent, []);
const room = setupRoomWithBeacon(beaconInfoEvent, []);
const getRelationsForEvent = await mockGetRelationsForEvent();
getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });
act(() => {
beaconInfoEvent.makeRedacted(redactionEvent);
beaconInfoEvent.makeRedacted(redactionEvent, room);
});
expect(getRelationsForEvent).toHaveBeenCalledWith(
@ -368,14 +370,14 @@ describe("<MBeaconBody />", () => {
it("redacts related locations on beacon redaction", async () => {
const { beaconInfoEvent, location1, location2 } = makeEvents();
setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
const room = setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
const getRelationsForEvent = await mockGetRelationsForEvent([location1, location2]);
getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });
act(() => {
beaconInfoEvent.makeRedacted(redactionEvent);
beaconInfoEvent.makeRedacted(redactionEvent, room);
});
expect(getRelationsForEvent).toHaveBeenCalledWith(

View File

@ -96,7 +96,7 @@ describe("<MPollEndBody />", () => {
mockClient.relations.mockResolvedValue({
events: [],
});
mockClient.fetchRoomEvent.mockResolvedValue(pollStartEvent.toJSON());
mockClient.fetchRoomEvent.mockResolvedValue(pollStartEvent.getEffectiveEvent());
});
afterEach(() => {

View File

@ -46,6 +46,14 @@ jest.mock("../../../../src/dispatcher/dispatcher");
describe("<MessageActionBar />", () => {
const userId = "@alice:server.org";
const roomId = "!room:server.org";
const client = getMockClientWithEventEmitter({
...mockClientMethodsUser(userId),
...mockClientMethodsEvents(),
getRoom: jest.fn(),
});
const room = new Room(roomId, client, userId);
const alicesMessageEvent = new MatrixEvent({
type: EventType.RoomMessage,
sender: userId,
@ -72,13 +80,7 @@ describe("<MessageActionBar />", () => {
type: EventType.RoomMessage,
sender: userId,
});
redactedEvent.makeRedacted(redactedEvent);
const client = getMockClientWithEventEmitter({
...mockClientMethodsUser(userId),
...mockClientMethodsEvents(),
getRoom: jest.fn(),
});
redactedEvent.makeRedacted(redactedEvent, room);
const localStorageMock = (() => {
let store: Record<string, any> = {};
@ -98,7 +100,6 @@ describe("<MessageActionBar />", () => {
writable: true,
});
const room = new Room(roomId, client, userId);
jest.spyOn(room, "getPendingEvents").mockReturnValue([]);
client.getRoom.mockReturnValue(room);

View File

@ -933,12 +933,7 @@ describe("<PowerLevelEditor />", () => {
// firing the event will raise a dialog warning about self demotion, wait for this to appear then click on it
await userEvent.click(await screen.findByText("Demote", { exact: true }));
expect(mockClient.setPowerLevel).toHaveBeenCalledTimes(1);
expect(mockClient.setPowerLevel).toHaveBeenCalledWith(
mockRoom.roomId,
defaultMember.userId,
changedPowerLevel,
powerLevelEvent,
);
expect(mockClient.setPowerLevel).toHaveBeenCalledWith(mockRoom.roomId, defaultMember.userId, changedPowerLevel);
});
});

View File

@ -70,7 +70,7 @@ describe("createRoom", () => {
// widget should be immutable for admins
expect(widgetPower).toBeGreaterThan(100);
// and we should have been reset back to admin
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, userId, 100, null);
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, userId, 100);
});
it("sets up Element video rooms correctly", async () => {
@ -99,7 +99,7 @@ describe("createRoom", () => {
// call should be immutable for admins
expect(callPower).toBeGreaterThan(100);
// and we should have been reset back to admin
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, userId, 100, null);
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, userId, 100);
});
it("doesn't create calls in non-video-rooms", async () => {

View File

@ -14,9 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { Room } from "matrix-js-sdk/src/matrix";
import { VoiceBroadcastPreview } from "../../../../src/stores/room-list/previews/VoiceBroadcastPreview";
import { VoiceBroadcastInfoState } from "../../../../src/voice-broadcast";
import { mkEvent } from "../../../test-utils";
import { mkEvent, stubClient } from "../../../test-utils";
import { mkVoiceBroadcastInfoStateEvent } from "../../../voice-broadcast/utils/test-utils";
describe("VoiceBroadcastPreview.getTextFor", () => {
@ -51,7 +53,10 @@ describe("VoiceBroadcastPreview.getTextFor", () => {
it("when passing a redacted broadcast stopped event, it should return null", () => {
const event = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Stopped, userId, deviceId);
event.makeRedacted(mkEvent({ event: true, content: {}, user: userId, type: "m.room.redaction" }));
event.makeRedacted(
mkEvent({ event: true, content: {}, user: userId, type: "m.room.redaction" }),
new Room(roomId, stubClient(), userId),
);
expect(preview.getTextFor(event)).toBeNull();
});
});

View File

@ -73,7 +73,10 @@ describe("EventUtils", () => {
type: EventType.RoomMessage,
sender: userId,
});
redactedEvent.makeRedacted(redactedEvent);
redactedEvent.makeRedacted(
redactedEvent,
new Room(redactedEvent.getRoomId()!, mockClient, mockClient.getUserId()!),
);
const stateEvent = new MatrixEvent({
type: EventType.RoomTopic,

View File

@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
import { EventType, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import { shouldDisplayAsBeaconTile } from "../../../src/utils/beacon/timeline";
import { makeBeaconInfoEvent } from "../../test-utils";
import { makeBeaconInfoEvent, stubClient } from "../../test-utils";
describe("shouldDisplayAsBeaconTile", () => {
const userId = "@user:server";
@ -26,7 +26,7 @@ describe("shouldDisplayAsBeaconTile", () => {
const notLiveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
const memberEvent = new MatrixEvent({ type: EventType.RoomMember });
const redactedBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
redactedBeacon.makeRedacted(redactedBeacon);
redactedBeacon.makeRedacted(redactedBeacon, new Room(roomId, stubClient(), userId));
it("returns true for a beacon with live property set to true", () => {
expect(shouldDisplayAsBeaconTile(liveBeacon)).toBe(true);

View File

@ -454,7 +454,7 @@ describe("VoiceBroadcastPlayback", () => {
describe("and the info event is deleted", () => {
beforeEach(() => {
infoEvent.makeRedacted(new MatrixEvent({}));
infoEvent.makeRedacted(new MatrixEvent({}), room);
});
it("should stop and destroy the playback", () => {