Skip to content

Commit bd1afb4

Browse files
committed
test skipping insertion
1 parent 3bb9291 commit bd1afb4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

spec/unit/room-state.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,4 +1122,55 @@ describe("RoomState", function () {
11221122
).toBeFalsy();
11231123
});
11241124
});
1125+
describe("skipWrongOrderRoomStateInserts", () => {
1126+
const idNow = "now";
1127+
const idBefore = "before";
1128+
let onRoomStateEvent: (event: MatrixEvent, state: RoomState, lastStateEvent: MatrixEvent | null) => void;
1129+
const evNow = new MatrixEvent({
1130+
type: "m.call.member",
1131+
room_id: roomId,
1132+
state_key: "@user:example.org",
1133+
content: {},
1134+
});
1135+
evNow.event.unsigned = { replaces_state: idBefore };
1136+
evNow.event.event_id = idNow;
1137+
1138+
const evBefore = new MatrixEvent({
1139+
type: "m.call.member",
1140+
room_id: roomId,
1141+
state_key: "@user:example.org",
1142+
content: {},
1143+
});
1144+
1145+
const updatedStateWithBefore = jest.fn();
1146+
const updatedStateWithNow = jest.fn();
1147+
1148+
beforeEach(() => {
1149+
evBefore.event.event_id = idBefore;
1150+
onRoomStateEvent = (event, _state, _lastState) => {
1151+
if (event.event.event_id === idNow) {
1152+
updatedStateWithNow();
1153+
} else if (event.event.event_id === idBefore) {
1154+
updatedStateWithBefore();
1155+
}
1156+
};
1157+
state.on(RoomStateEvent.Events, onRoomStateEvent);
1158+
});
1159+
afterEach(() => {
1160+
state.off(RoomStateEvent.Events, onRoomStateEvent);
1161+
updatedStateWithNow.mockReset();
1162+
updatedStateWithBefore.mockReset();
1163+
});
1164+
it("should skip inserting state to the end of the timeline if the current endState events replaces_state id is the same as the inserted events id", () => {
1165+
//
1166+
state.setStateEvents([evNow, evBefore], { toStartOfTimeline: false });
1167+
expect(updatedStateWithBefore).not.toHaveBeenCalled();
1168+
expect(updatedStateWithNow).toHaveBeenCalled();
1169+
});
1170+
it("should skip inserting state at the beginning of the timeline if the inserted events replaces_state is the event id of the current startState", () => {
1171+
state.setStateEvents([evBefore, evNow], { toStartOfTimeline: true });
1172+
expect(updatedStateWithBefore).toHaveBeenCalled();
1173+
expect(updatedStateWithNow).not.toHaveBeenCalled();
1174+
});
1175+
});
11251176
});

0 commit comments

Comments
 (0)