Merge branch 'develop' of https://github.com/vector-im/element-web into dbkr/stateafter
# Conflicts: # test/unit-tests/components/structures/RoomView-test.tsx # test/unit-tests/components/structures/TimelinePanel-test.tsx
This commit is contained in:
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { render, waitFor, screen } from "jest-matrix-react";
|
||||
import { render, waitFor, screen, act, cleanup } from "jest-matrix-react";
|
||||
import {
|
||||
ReceiptType,
|
||||
EventTimelineSet,
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
ThreadFilterType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import React, { createRef } from "react";
|
||||
import React from "react";
|
||||
import { Mocked, mocked } from "jest-mock";
|
||||
import { forEachRight } from "lodash";
|
||||
|
||||
@@ -180,7 +180,7 @@ describe("TimelinePanel", () => {
|
||||
const roomId = "#room:example.com";
|
||||
let room: Room;
|
||||
let timelineSet: EventTimelineSet;
|
||||
let timelinePanel: TimelinePanel;
|
||||
let timelinePanel: TimelinePanel | null = null;
|
||||
|
||||
const ev1 = new MatrixEvent({
|
||||
event_id: "ev1",
|
||||
@@ -199,17 +199,16 @@ describe("TimelinePanel", () => {
|
||||
});
|
||||
|
||||
const renderTimelinePanel = async (): Promise<void> => {
|
||||
const ref = createRef<TimelinePanel>();
|
||||
render(
|
||||
<TimelinePanel
|
||||
timelineSet={timelineSet}
|
||||
manageReadMarkers={true}
|
||||
manageReadReceipts={true}
|
||||
ref={ref}
|
||||
ref={(ref) => (timelinePanel = ref)}
|
||||
/>,
|
||||
);
|
||||
await flushPromises();
|
||||
timelinePanel = ref.current!;
|
||||
await waitFor(() => expect(timelinePanel).toBeTruthy());
|
||||
};
|
||||
|
||||
const setUpTimelineSet = (threadRoot?: MatrixEvent) => {
|
||||
@@ -234,8 +233,9 @@ describe("TimelinePanel", () => {
|
||||
room = new Room(roomId, client, userId, { pendingEventOrdering: PendingEventOrdering.Detached });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
afterEach(async () => {
|
||||
TimelinePanel.roomReadMarkerTsMap = {};
|
||||
cleanup();
|
||||
});
|
||||
|
||||
it("when there is no event, it should not send any receipt", async () => {
|
||||
@@ -260,7 +260,6 @@ describe("TimelinePanel", () => {
|
||||
await renderTimelinePanel();
|
||||
timelineSet.addLiveEvent(ev1, { addToState: true });
|
||||
await flushPromises();
|
||||
|
||||
// @ts-ignore
|
||||
await timelinePanel.sendReadReceipts();
|
||||
// @ts-ignore Simulate user activity by calling updateReadMarker on the TimelinePanel.
|
||||
@@ -278,7 +277,7 @@ describe("TimelinePanel", () => {
|
||||
client.setRoomReadMarkers.mockClear();
|
||||
|
||||
// @ts-ignore Simulate user activity by calling updateReadMarker on the TimelinePanel.
|
||||
await timelinePanel.updateReadMarker();
|
||||
await act(() => timelinePanel.updateReadMarker());
|
||||
});
|
||||
|
||||
it("should not send receipts again", () => {
|
||||
@@ -293,7 +292,7 @@ describe("TimelinePanel", () => {
|
||||
// setup, timelineSet is not actually the timelineSet of the room.
|
||||
await room.addLiveEvents([ev2], { addToState: true });
|
||||
room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]);
|
||||
await timelinePanel.forgetReadMarker();
|
||||
await timelinePanel!.forgetReadMarker();
|
||||
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev2.getId());
|
||||
});
|
||||
});
|
||||
@@ -317,7 +316,7 @@ describe("TimelinePanel", () => {
|
||||
|
||||
it("should send a fully read marker and a private receipt", async () => {
|
||||
await renderTimelinePanel();
|
||||
timelineSet.addLiveEvent(ev1, { addToState: true });
|
||||
act(() => timelineSet.addLiveEvent(ev1, { addToState: true }));
|
||||
await flushPromises();
|
||||
|
||||
// @ts-ignore
|
||||
@@ -328,6 +327,7 @@ describe("TimelinePanel", () => {
|
||||
// Expect the fully_read marker not to be send yet
|
||||
expect(client.setRoomReadMarkers).not.toHaveBeenCalled();
|
||||
|
||||
await flushPromises();
|
||||
client.sendReadReceipt.mockClear();
|
||||
|
||||
// @ts-ignore simulate user activity
|
||||
@@ -336,7 +336,7 @@ describe("TimelinePanel", () => {
|
||||
// It should not send the receipt again.
|
||||
expect(client.sendReadReceipt).not.toHaveBeenCalledWith(ev1, ReceiptType.ReadPrivate);
|
||||
// Expect the fully_read marker to be sent after user activity.
|
||||
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev1.getId());
|
||||
await waitFor(() => expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev1.getId()));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -363,11 +363,11 @@ describe("TimelinePanel", () => {
|
||||
|
||||
it("should send receipts but no fully_read when reading the thread timeline", async () => {
|
||||
await renderTimelinePanel();
|
||||
timelineSet.addLiveEvent(threadEv1, { addToState: true });
|
||||
act(() => timelineSet.addLiveEvent(threadEv1, { addToState: true }));
|
||||
await flushPromises();
|
||||
|
||||
// @ts-ignore
|
||||
await timelinePanel.sendReadReceipts();
|
||||
await act(() => timelinePanel.sendReadReceipts());
|
||||
|
||||
// fully_read is not supported for threads per spec
|
||||
expect(client.setRoomReadMarkers).not.toHaveBeenCalled();
|
||||
@@ -1032,7 +1032,7 @@ describe("TimelinePanel", () => {
|
||||
await waitFor(() => expectEvents(container, [events[1]]));
|
||||
});
|
||||
|
||||
defaultDispatcher.fire(Action.DumpDebugLogs);
|
||||
act(() => defaultDispatcher.fire(Action.DumpDebugLogs));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(spy).toHaveBeenCalledWith(expect.stringContaining("TimelinePanel(Room): Debugging info for roomId")),
|
||||
|
||||
Reference in New Issue
Block a user