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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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);

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