1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-07-31 13:44:28 +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

@ -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);