You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Revert "Revert "Move redaction event tests into their own describe block""
This reverts commit 2e24481df3
.
This commit is contained in:
@ -70,112 +70,114 @@ describe("MatrixEvent", () => {
|
|||||||
expect(a.toSnapshot().isEquivalentTo(b)).toBe(false);
|
expect(a.toSnapshot().isEquivalentTo(b)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should prune clearEvent when being redacted", () => {
|
describe("redaction", () => {
|
||||||
const ev = new MatrixEvent({
|
it("should prune clearEvent when being redacted", () => {
|
||||||
type: "m.room.message",
|
const ev = new MatrixEvent({
|
||||||
content: {
|
type: "m.room.message",
|
||||||
body: "Test",
|
content: {
|
||||||
},
|
body: "Test",
|
||||||
event_id: "$event1:server",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(ev.getContent().body).toBe("Test");
|
|
||||||
expect(ev.getWireContent().body).toBe("Test");
|
|
||||||
ev.makeEncrypted("m.room.encrypted", { ciphertext: "xyz" }, "", "");
|
|
||||||
expect(ev.getContent().body).toBe("Test");
|
|
||||||
expect(ev.getWireContent().body).toBeUndefined();
|
|
||||||
expect(ev.getWireContent().ciphertext).toBe("xyz");
|
|
||||||
|
|
||||||
const mockClient = {} as unknown as MockedObject<MatrixClient>;
|
|
||||||
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
|
||||||
const redaction = new MatrixEvent({
|
|
||||||
type: "m.room.redaction",
|
|
||||||
redacts: ev.getId(),
|
|
||||||
});
|
|
||||||
|
|
||||||
ev.makeRedacted(redaction, room);
|
|
||||||
expect(ev.getContent().body).toBeUndefined();
|
|
||||||
expect(ev.getWireContent().body).toBeUndefined();
|
|
||||||
expect(ev.getWireContent().ciphertext).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should remain in the main timeline when redacted", async () => {
|
|
||||||
// Given an event in the main timeline
|
|
||||||
const mockClient = {
|
|
||||||
supportsThreads: jest.fn().mockReturnValue(true),
|
|
||||||
decryptEventIfNeeded: jest.fn().mockReturnThis(),
|
|
||||||
getUserId: jest.fn().mockReturnValue("@user:server"),
|
|
||||||
} as unknown as MockedObject<MatrixClient>;
|
|
||||||
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
|
||||||
const ev = new MatrixEvent({
|
|
||||||
type: "m.room.message",
|
|
||||||
content: {
|
|
||||||
body: "Test",
|
|
||||||
},
|
|
||||||
event_id: "$event1:server",
|
|
||||||
});
|
|
||||||
|
|
||||||
await room.addLiveEvents([ev]);
|
|
||||||
await room.createThreadsTimelineSets();
|
|
||||||
expect(ev.threadRootId).toBeUndefined();
|
|
||||||
expect(mainTimelineLiveEventIds(room)).toEqual(["$event1:server"]);
|
|
||||||
|
|
||||||
// When I redact it
|
|
||||||
const redaction = new MatrixEvent({
|
|
||||||
type: "m.room.redaction",
|
|
||||||
redacts: ev.getId(),
|
|
||||||
});
|
|
||||||
ev.makeRedacted(redaction, room);
|
|
||||||
|
|
||||||
// Then it remains in the main timeline
|
|
||||||
expect(ev.threadRootId).toBeUndefined();
|
|
||||||
expect(mainTimelineLiveEventIds(room)).toEqual(["$event1:server"]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should move into the main timeline when redacted", async () => {
|
|
||||||
// Given an event in a thread
|
|
||||||
const mockClient = {
|
|
||||||
supportsThreads: jest.fn().mockReturnValue(true),
|
|
||||||
decryptEventIfNeeded: jest.fn().mockReturnThis(),
|
|
||||||
getUserId: jest.fn().mockReturnValue("@user:server"),
|
|
||||||
} as unknown as MockedObject<MatrixClient>;
|
|
||||||
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
|
||||||
const threadRoot = new MatrixEvent({
|
|
||||||
type: "m.room.message",
|
|
||||||
content: {
|
|
||||||
body: "threadRoot",
|
|
||||||
},
|
|
||||||
event_id: "$threadroot:server",
|
|
||||||
});
|
|
||||||
const ev = new MatrixEvent({
|
|
||||||
type: "m.room.message",
|
|
||||||
content: {
|
|
||||||
"body": "Test",
|
|
||||||
"m.relates_to": {
|
|
||||||
rel_type: THREAD_RELATION_TYPE.name,
|
|
||||||
event_id: "$threadroot:server",
|
|
||||||
},
|
},
|
||||||
},
|
event_id: "$event1:server",
|
||||||
event_id: "$event1:server",
|
});
|
||||||
|
|
||||||
|
expect(ev.getContent().body).toBe("Test");
|
||||||
|
expect(ev.getWireContent().body).toBe("Test");
|
||||||
|
ev.makeEncrypted("m.room.encrypted", { ciphertext: "xyz" }, "", "");
|
||||||
|
expect(ev.getContent().body).toBe("Test");
|
||||||
|
expect(ev.getWireContent().body).toBeUndefined();
|
||||||
|
expect(ev.getWireContent().ciphertext).toBe("xyz");
|
||||||
|
|
||||||
|
const mockClient = {} as unknown as MockedObject<MatrixClient>;
|
||||||
|
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
||||||
|
const redaction = new MatrixEvent({
|
||||||
|
type: "m.room.redaction",
|
||||||
|
redacts: ev.getId(),
|
||||||
|
});
|
||||||
|
|
||||||
|
ev.makeRedacted(redaction, room);
|
||||||
|
expect(ev.getContent().body).toBeUndefined();
|
||||||
|
expect(ev.getWireContent().body).toBeUndefined();
|
||||||
|
expect(ev.getWireContent().ciphertext).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
await room.addLiveEvents([threadRoot, ev]);
|
it("should remain in the main timeline when redacted", async () => {
|
||||||
await room.createThreadsTimelineSets();
|
// Given an event in the main timeline
|
||||||
expect(ev.threadRootId).toEqual("$threadroot:server");
|
const mockClient = {
|
||||||
expect(mainTimelineLiveEventIds(room)).toEqual(["$threadroot:server"]);
|
supportsThreads: jest.fn().mockReturnValue(true),
|
||||||
expect(threadLiveEventIds(room, 0)).toEqual(["$threadroot:server", "$event1:server"]);
|
decryptEventIfNeeded: jest.fn().mockReturnThis(),
|
||||||
|
getUserId: jest.fn().mockReturnValue("@user:server"),
|
||||||
|
} as unknown as MockedObject<MatrixClient>;
|
||||||
|
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
||||||
|
const ev = new MatrixEvent({
|
||||||
|
type: "m.room.message",
|
||||||
|
content: {
|
||||||
|
body: "Test",
|
||||||
|
},
|
||||||
|
event_id: "$event1:server",
|
||||||
|
});
|
||||||
|
|
||||||
// When I redact it
|
await room.addLiveEvents([ev]);
|
||||||
const redaction = new MatrixEvent({
|
await room.createThreadsTimelineSets();
|
||||||
type: "m.room.redaction",
|
expect(ev.threadRootId).toBeUndefined();
|
||||||
redacts: ev.getId(),
|
expect(mainTimelineLiveEventIds(room)).toEqual(["$event1:server"]);
|
||||||
|
|
||||||
|
// When I redact it
|
||||||
|
const redaction = new MatrixEvent({
|
||||||
|
type: "m.room.redaction",
|
||||||
|
redacts: ev.getId(),
|
||||||
|
});
|
||||||
|
ev.makeRedacted(redaction, room);
|
||||||
|
|
||||||
|
// Then it remains in the main timeline
|
||||||
|
expect(ev.threadRootId).toBeUndefined();
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual(["$event1:server"]);
|
||||||
});
|
});
|
||||||
ev.makeRedacted(redaction, room);
|
|
||||||
|
|
||||||
// Then it disappears from the thread and appears in the main timeline
|
it("should move into the main timeline when redacted", async () => {
|
||||||
expect(ev.threadRootId).toBeUndefined();
|
// Given an event in a thread
|
||||||
expect(mainTimelineLiveEventIds(room)).toEqual(["$threadroot:server", "$event1:server"]);
|
const mockClient = {
|
||||||
expect(threadLiveEventIds(room, 0)).not.toContain("$event1:server");
|
supportsThreads: jest.fn().mockReturnValue(true),
|
||||||
|
decryptEventIfNeeded: jest.fn().mockReturnThis(),
|
||||||
|
getUserId: jest.fn().mockReturnValue("@user:server"),
|
||||||
|
} as unknown as MockedObject<MatrixClient>;
|
||||||
|
const room = new Room("!roomid:e.xyz", mockClient, "myname");
|
||||||
|
const threadRoot = new MatrixEvent({
|
||||||
|
type: "m.room.message",
|
||||||
|
content: {
|
||||||
|
body: "threadRoot",
|
||||||
|
},
|
||||||
|
event_id: "$threadroot:server",
|
||||||
|
});
|
||||||
|
const ev = new MatrixEvent({
|
||||||
|
type: "m.room.message",
|
||||||
|
content: {
|
||||||
|
"body": "Test",
|
||||||
|
"m.relates_to": {
|
||||||
|
rel_type: THREAD_RELATION_TYPE.name,
|
||||||
|
event_id: "$threadroot:server",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
event_id: "$event1:server",
|
||||||
|
});
|
||||||
|
|
||||||
|
await room.addLiveEvents([threadRoot, ev]);
|
||||||
|
await room.createThreadsTimelineSets();
|
||||||
|
expect(ev.threadRootId).toEqual("$threadroot:server");
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual(["$threadroot:server"]);
|
||||||
|
expect(threadLiveEventIds(room, 0)).toEqual(["$threadroot:server", "$event1:server"]);
|
||||||
|
|
||||||
|
// When I redact it
|
||||||
|
const redaction = new MatrixEvent({
|
||||||
|
type: "m.room.redaction",
|
||||||
|
redacts: ev.getId(),
|
||||||
|
});
|
||||||
|
ev.makeRedacted(redaction, room);
|
||||||
|
|
||||||
|
// Then it disappears from the thread and appears in the main timeline
|
||||||
|
expect(ev.threadRootId).toBeUndefined();
|
||||||
|
expect(mainTimelineLiveEventIds(room)).toEqual(["$threadroot:server", "$event1:server"]);
|
||||||
|
expect(threadLiveEventIds(room, 0)).not.toContain("$event1:server");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("applyVisibilityEvent", () => {
|
describe("applyVisibilityEvent", () => {
|
||||||
|
Reference in New Issue
Block a user