Gitter sunsetting: Use findPredecessor in EventTileFactory (#10075)
This commit is contained in:
parent
9743852380
commit
f1a08cd572
4 changed files with 153 additions and 9 deletions
|
@ -37,6 +37,7 @@ import {
|
|||
} from "../../test-utils";
|
||||
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
|
||||
import { IRoomState } from "../../../src/components/structures/RoomView";
|
||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||
|
||||
jest.mock("../../../src/utils/beacon", () => ({
|
||||
useBeacon: jest.fn(),
|
||||
|
@ -58,6 +59,7 @@ describe("MessagePanel", function () {
|
|||
getRoom: jest.fn(),
|
||||
getClientWellKnown: jest.fn().mockReturnValue({}),
|
||||
});
|
||||
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(client);
|
||||
|
||||
const room = new Room(roomId, client, userId);
|
||||
|
||||
|
@ -464,11 +466,12 @@ describe("MessagePanel", function () {
|
|||
|
||||
it("should collapse creation events", function () {
|
||||
const events = mkCreationEvents();
|
||||
TestUtilsMatrix.upsertRoomStateEvents(room, events);
|
||||
const { container } = render(getComponent({ events }));
|
||||
|
||||
const createEvent = events.find((event) => event.getType() === "m.room.create");
|
||||
const encryptionEvent = events.find((event) => event.getType() === "m.room.encryption");
|
||||
client.getRoom.mockImplementation((id) => (id === createEvent!.getRoomId() ? room : null));
|
||||
TestUtilsMatrix.upsertRoomStateEvents(room, events);
|
||||
|
||||
const { container } = render(getComponent({ events }));
|
||||
|
||||
// we expect that
|
||||
// - the room creation event, the room encryption event, and Alice inviting Bob,
|
||||
|
@ -508,6 +511,8 @@ describe("MessagePanel", function () {
|
|||
|
||||
it("should hide read-marker at the end of creation event summary", function () {
|
||||
const events = mkCreationEvents();
|
||||
const createEvent = events.find((event) => event.getType() === "m.room.create");
|
||||
client.getRoom.mockImplementation((id) => (id === createEvent!.getRoomId() ? room : null));
|
||||
TestUtilsMatrix.upsertRoomStateEvents(room, events);
|
||||
|
||||
const { container } = render(
|
||||
|
|
|
@ -18,8 +18,10 @@ import {
|
|||
JSONEventFactory,
|
||||
MessageEventFactory,
|
||||
pickFactory,
|
||||
RoomCreateEventFactory,
|
||||
TextualEventFactory,
|
||||
} from "../../src/events/EventTileFactory";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
import { VoiceBroadcastChunkEventType, VoiceBroadcastInfoState } from "../../src/voice-broadcast";
|
||||
import { createTestClient, mkEvent } from "../test-utils";
|
||||
import { mkVoiceBroadcastInfoStateEvent } from "../voice-broadcast/utils/test-utils";
|
||||
|
@ -27,23 +29,64 @@ import { mkVoiceBroadcastInfoStateEvent } from "../voice-broadcast/utils/test-ut
|
|||
const roomId = "!room:example.com";
|
||||
|
||||
describe("pickFactory", () => {
|
||||
let client: MatrixClient;
|
||||
let room: Room;
|
||||
|
||||
let createEventWithPredecessor: MatrixEvent;
|
||||
let createEventWithoutPredecessor: MatrixEvent;
|
||||
let dynamicPredecessorEvent: MatrixEvent;
|
||||
|
||||
let voiceBroadcastStartedEvent: MatrixEvent;
|
||||
let voiceBroadcastStoppedEvent: MatrixEvent;
|
||||
let voiceBroadcastChunkEvent: MatrixEvent;
|
||||
let utdEvent: MatrixEvent;
|
||||
let utdBroadcastChunkEvent: MatrixEvent;
|
||||
let audioMessageEvent: MatrixEvent;
|
||||
let client: MatrixClient;
|
||||
|
||||
beforeAll(() => {
|
||||
client = createTestClient();
|
||||
|
||||
const room = new Room(roomId, client, client.getSafeUserId());
|
||||
room = new Room(roomId, client, client.getSafeUserId());
|
||||
mocked(client.getRoom).mockImplementation((getRoomId: string): Room | null => {
|
||||
if (getRoomId === room.roomId) return room;
|
||||
return null;
|
||||
});
|
||||
|
||||
createEventWithoutPredecessor = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomCreate,
|
||||
user: client.getUserId()!,
|
||||
room: roomId,
|
||||
content: {
|
||||
creator: client.getUserId()!,
|
||||
room_version: "9",
|
||||
},
|
||||
});
|
||||
createEventWithPredecessor = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomCreate,
|
||||
user: client.getUserId()!,
|
||||
room: roomId,
|
||||
content: {
|
||||
creator: client.getUserId()!,
|
||||
room_version: "9",
|
||||
predecessor: {
|
||||
room_id: "roomid1",
|
||||
event_id: null,
|
||||
},
|
||||
},
|
||||
});
|
||||
dynamicPredecessorEvent = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomPredecessor,
|
||||
user: client.getUserId()!,
|
||||
room: roomId,
|
||||
skey: "",
|
||||
content: {
|
||||
predecessor_room_id: "roomid2",
|
||||
last_known_event_id: null,
|
||||
},
|
||||
});
|
||||
voiceBroadcastStartedEvent = mkVoiceBroadcastInfoStateEvent(
|
||||
roomId,
|
||||
VoiceBroadcastInfoState.Started,
|
||||
|
@ -117,6 +160,15 @@ describe("pickFactory", () => {
|
|||
expect(pickFactory(voiceBroadcastChunkEvent, client, true)).toBe(JSONEventFactory);
|
||||
});
|
||||
|
||||
it("should return a JSONEventFactory for a room create event without predecessor", () => {
|
||||
room.currentState.events.set(
|
||||
EventType.RoomCreate,
|
||||
new Map([[createEventWithoutPredecessor.getStateKey()!, createEventWithoutPredecessor]]),
|
||||
);
|
||||
room.currentState.events.set(EventType.RoomPredecessor, new Map());
|
||||
expect(pickFactory(createEventWithoutPredecessor, client, true)).toBe(JSONEventFactory);
|
||||
});
|
||||
|
||||
it("should return a TextualEventFactory for a voice broadcast stopped event", () => {
|
||||
expect(pickFactory(voiceBroadcastStoppedEvent, client, true)).toBe(TextualEventFactory);
|
||||
});
|
||||
|
@ -131,6 +183,80 @@ describe("pickFactory", () => {
|
|||
});
|
||||
|
||||
describe("when not showing hidden events", () => {
|
||||
describe("without dynamic predecessor support", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockReset();
|
||||
});
|
||||
|
||||
it("should return undefined for a room without predecessor", () => {
|
||||
room.currentState.events.set(
|
||||
EventType.RoomCreate,
|
||||
new Map([[createEventWithoutPredecessor.getStateKey()!, createEventWithoutPredecessor]]),
|
||||
);
|
||||
room.currentState.events.set(EventType.RoomPredecessor, new Map());
|
||||
expect(pickFactory(createEventWithoutPredecessor, client, false)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return a RoomCreateFactory for a room with fixed predecessor", () => {
|
||||
room.currentState.events.set(
|
||||
EventType.RoomCreate,
|
||||
new Map([[createEventWithPredecessor.getStateKey()!, createEventWithPredecessor]]),
|
||||
);
|
||||
room.currentState.events.set(EventType.RoomPredecessor, new Map());
|
||||
expect(pickFactory(createEventWithPredecessor, client, false)).toBe(RoomCreateEventFactory);
|
||||
});
|
||||
|
||||
it("should return undefined for a room with dynamic predecessor", () => {
|
||||
room.currentState.events.set(
|
||||
EventType.RoomCreate,
|
||||
new Map([[createEventWithoutPredecessor.getStateKey()!, createEventWithoutPredecessor]]),
|
||||
);
|
||||
room.currentState.events.set(
|
||||
EventType.RoomPredecessor,
|
||||
new Map([[dynamicPredecessorEvent.getStateKey()!, dynamicPredecessorEvent]]),
|
||||
);
|
||||
expect(pickFactory(createEventWithoutPredecessor, client, false)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("with dynamic predecessor support", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(SettingsStore, "getValue")
|
||||
.mockReset()
|
||||
.mockImplementation((settingName) => settingName === "feature_dynamic_room_predecessors");
|
||||
});
|
||||
|
||||
it("should return undefined for a room without predecessor", () => {
|
||||
room.currentState.events.set(
|
||||
EventType.RoomCreate,
|
||||
new Map([[createEventWithoutPredecessor.getStateKey()!, createEventWithoutPredecessor]]),
|
||||
);
|
||||
room.currentState.events.set(EventType.RoomPredecessor, new Map());
|
||||
expect(pickFactory(createEventWithoutPredecessor, client, false)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should return a RoomCreateFactory for a room with fixed predecessor", () => {
|
||||
room.currentState.events.set(
|
||||
EventType.RoomCreate,
|
||||
new Map([[createEventWithPredecessor.getStateKey()!, createEventWithPredecessor]]),
|
||||
);
|
||||
room.currentState.events.set(EventType.RoomPredecessor, new Map());
|
||||
expect(pickFactory(createEventWithPredecessor, client, false)).toBe(RoomCreateEventFactory);
|
||||
});
|
||||
|
||||
it("should return a RoomCreateFactory for a room with dynamic predecessor", () => {
|
||||
room.currentState.events.set(
|
||||
EventType.RoomCreate,
|
||||
new Map([[createEventWithoutPredecessor.getStateKey()!, createEventWithoutPredecessor]]),
|
||||
);
|
||||
room.currentState.events.set(
|
||||
EventType.RoomPredecessor,
|
||||
new Map([[dynamicPredecessorEvent.getStateKey()!, dynamicPredecessorEvent]]),
|
||||
);
|
||||
expect(pickFactory(createEventWithoutPredecessor, client, false)).toBe(RoomCreateEventFactory);
|
||||
});
|
||||
});
|
||||
|
||||
it("should return undefined for a voice broadcast event", () => {
|
||||
expect(pickFactory(voiceBroadcastChunkEvent, client, false)).toBeUndefined();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue