mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-03 06:55:44 +00:00
Absorb the matrix-react-sdk repository (#28192)
Co-authored-by: github-merge-queue <118344674+github-merge-queue@users.noreply.github.com> Co-authored-by: github-merge-queue <github-merge-queue@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Florian Duros <florian.duros@ormaz.fr> Co-authored-by: Kim Brose <kim.brose@nordeck.net> Co-authored-by: Florian Duros <florianduros@element.io> Co-authored-by: R Midhun Suresh <hi@midhun.dev> Co-authored-by: dbkr <986903+dbkr@users.noreply.github.com> Co-authored-by: ElementRobot <releases@riot.im> Co-authored-by: dbkr <dbkr@users.noreply.github.com> Co-authored-by: David Baker <dbkr@users.noreply.github.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Co-authored-by: David Langley <davidl@element.io> Co-authored-by: Michael Weimann <michaelw@matrix.org> Co-authored-by: Timshel <Timshel@users.noreply.github.com> Co-authored-by: Sahil Silare <32628578+sahil9001@users.noreply.github.com> Co-authored-by: Will Hunt <will@half-shot.uk> Co-authored-by: Hubert Chathi <hubert@uhoreg.ca> Co-authored-by: Andrew Ferrazzutti <andrewf@element.io> Co-authored-by: Robin <robin@robin.town> Co-authored-by: Tulir Asokan <tulir@maunium.net>
This commit is contained in:
committed by
GitHub
parent
2b99496025
commit
c05c429803
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import { EventType, MatrixClient, MatrixEvent, MatrixEventEvent, RelationType, Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { RelationsHelper, RelationsHelperEvent } from "../../../src/events/RelationsHelper";
|
||||
import { mkEvent, stubClient } from "../../test-utils";
|
||||
|
||||
describe("RelationsHelper", () => {
|
||||
const roomId = "!room:example.com";
|
||||
let event: MatrixEvent;
|
||||
let relatedEvent1: MatrixEvent;
|
||||
let relatedEvent2: MatrixEvent;
|
||||
let relatedEvent3: MatrixEvent;
|
||||
let room: Room;
|
||||
let client: MatrixClient;
|
||||
let relationsHelper: RelationsHelper;
|
||||
let onAdd: (event: MatrixEvent) => void;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
mocked(client.relations).mockClear();
|
||||
room = new Room(roomId, client, client.getSafeUserId());
|
||||
mocked(client.getRoom).mockImplementation((getRoomId?: string): Room | null => {
|
||||
if (getRoomId === roomId) return room;
|
||||
return null;
|
||||
});
|
||||
event = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
room: roomId,
|
||||
user: client.getSafeUserId(),
|
||||
content: {},
|
||||
});
|
||||
relatedEvent1 = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
room: roomId,
|
||||
user: client.getSafeUserId(),
|
||||
content: {
|
||||
["m.relates_to"]: {
|
||||
rel_type: RelationType.Reference,
|
||||
event_id: event.getId(),
|
||||
},
|
||||
},
|
||||
});
|
||||
relatedEvent2 = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
room: roomId,
|
||||
user: client.getSafeUserId(),
|
||||
content: {
|
||||
["m.relates_to"]: {
|
||||
rel_type: RelationType.Reference,
|
||||
event_id: event.getId(),
|
||||
},
|
||||
},
|
||||
});
|
||||
relatedEvent3 = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMessage,
|
||||
room: roomId,
|
||||
user: client.getSafeUserId(),
|
||||
content: {
|
||||
["m.relates_to"]: {
|
||||
rel_type: RelationType.Reference,
|
||||
event_id: event.getId(),
|
||||
},
|
||||
},
|
||||
});
|
||||
onAdd = jest.fn();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
relationsHelper?.destroy();
|
||||
});
|
||||
|
||||
describe("when there is an event without ID", () => {
|
||||
it("should raise an error", () => {
|
||||
jest.spyOn(event, "getId").mockReturnValue(undefined);
|
||||
|
||||
expect(() => {
|
||||
new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
}).toThrow("unable to create RelationsHelper: missing event ID");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is an event without room ID", () => {
|
||||
it("should raise an error", () => {
|
||||
jest.spyOn(event, "getRoomId").mockReturnValue(undefined);
|
||||
|
||||
expect(() => {
|
||||
new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
}).toThrow("unable to create RelationsHelper: missing room ID");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is an event without relations", () => {
|
||||
beforeEach(() => {
|
||||
relationsHelper = new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
relationsHelper.on(RelationsHelperEvent.Add, onAdd);
|
||||
});
|
||||
|
||||
describe("emitCurrent", () => {
|
||||
beforeEach(() => {
|
||||
relationsHelper.emitCurrent();
|
||||
});
|
||||
|
||||
it("should not emit any event", () => {
|
||||
expect(onAdd).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("and a new event appears", () => {
|
||||
beforeEach(() => {
|
||||
room.relations.aggregateChildEvent(relatedEvent2);
|
||||
event.emit(MatrixEventEvent.RelationsCreated, RelationType.Reference, EventType.RoomMessage);
|
||||
});
|
||||
|
||||
it("should emit the new event", () => {
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is an event with two pages server side relations", () => {
|
||||
beforeEach(() => {
|
||||
mocked(client.relations)
|
||||
.mockResolvedValueOnce({
|
||||
events: [relatedEvent1, relatedEvent2],
|
||||
nextBatch: "next",
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
events: [relatedEvent3],
|
||||
nextBatch: null,
|
||||
});
|
||||
relationsHelper = new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
relationsHelper.on(RelationsHelperEvent.Add, onAdd);
|
||||
});
|
||||
|
||||
describe("emitFetchCurrent", () => {
|
||||
beforeEach(async () => {
|
||||
await relationsHelper.emitFetchCurrent();
|
||||
});
|
||||
|
||||
it("should emit the server side events", () => {
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent1);
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent2);
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent3);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there is an event with relations", () => {
|
||||
beforeEach(() => {
|
||||
room.relations.aggregateChildEvent(relatedEvent1);
|
||||
relationsHelper = new RelationsHelper(event, RelationType.Reference, EventType.RoomMessage, client);
|
||||
relationsHelper.on(RelationsHelperEvent.Add, onAdd);
|
||||
});
|
||||
|
||||
describe("emitCurrent", () => {
|
||||
beforeEach(() => {
|
||||
relationsHelper.emitCurrent();
|
||||
});
|
||||
|
||||
it("should emit the related event", () => {
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("and a new event appears", () => {
|
||||
beforeEach(() => {
|
||||
room.relations.aggregateChildEvent(relatedEvent2);
|
||||
event.emit(MatrixEventEvent.RelationsCreated, RelationType.Reference, EventType.RoomMessage);
|
||||
});
|
||||
|
||||
it("should emit the new event", () => {
|
||||
expect(onAdd).toHaveBeenCalledWith(relatedEvent2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user