Remove usage of legacyRoot in RTL tests (#28485)

* Remove usage of legacyRoot in RTL tests

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2024-11-20 18:09:51 +00:00
committed by GitHub
parent d5c111f656
commit 95630f525f
9 changed files with 40 additions and 38 deletions

View File

@@ -162,8 +162,11 @@ describe("<MatrixChat />", () => {
};
let initPromise: Promise<void> | undefined;
let defaultProps: ComponentProps<typeof MatrixChat>;
const getComponent = (props: Partial<ComponentProps<typeof MatrixChat>> = {}) =>
render(<MatrixChat {...defaultProps} {...props} />, { legacyRoot: true });
const getComponent = (props: Partial<ComponentProps<typeof MatrixChat>> = {}) => {
// MatrixChat does many questionable things which bomb tests in modern React mode,
// we'll want to refactor and break up MatrixChat before turning off legacyRoot mode
return render(<MatrixChat {...defaultProps} {...props} />, { legacyRoot: true });
};
// make test results readable
filterConsole(
@@ -1128,7 +1131,7 @@ describe("<MatrixChat />", () => {
await getComponentAndLogin();
act(() => bootstrapDeferred.resolve());
bootstrapDeferred.resolve();
await expect(
screen.findByRole("heading", { name: "You're in", level: 1 }),

View File

@@ -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, act } 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";
@@ -178,7 +178,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",
@@ -197,19 +197,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)}
/>,
{ legacyRoot: true },
);
await flushPromises();
await waitFor(() => expect(ref.current).toBeTruthy());
timelinePanel = ref.current!;
await waitFor(() => expect(timelinePanel).toBeTruthy());
};
const setUpTimelineSet = (threadRoot?: MatrixEvent) => {
@@ -234,8 +231,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 () => {
@@ -257,16 +255,13 @@ describe("TimelinePanel", () => {
describe("and reading the timeline", () => {
beforeEach(async () => {
await act(async () => {
await renderTimelinePanel();
timelineSet.addLiveEvent(ev1, {});
await flushPromises();
// @ts-ignore
await timelinePanel.sendReadReceipts();
// @ts-ignore Simulate user activity by calling updateReadMarker on the TimelinePanel.
await timelinePanel.updateReadMarker();
});
await renderTimelinePanel();
timelineSet.addLiveEvent(ev1, {});
await flushPromises();
// @ts-ignore
await timelinePanel.sendReadReceipts();
// @ts-ignore Simulate user activity by calling updateReadMarker on the TimelinePanel.
await timelinePanel.updateReadMarker();
});
it("should send a fully read marker and a public receipt", async () => {
@@ -295,7 +290,7 @@ describe("TimelinePanel", () => {
// setup, timelineSet is not actually the timelineSet of the room.
await room.addLiveEvents([ev2], {});
room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]);
await timelinePanel.forgetReadMarker();
await timelinePanel!.forgetReadMarker();
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev2.getId());
});
});

View File

@@ -8,7 +8,7 @@ Please see LICENSE files in the repository root for full details.
import React from "react";
import { mocked } from "jest-mock";
import { render, RenderResult, screen, waitFor } from "jest-matrix-react";
import { render, RenderResult, screen, waitFor, cleanup } from "jest-matrix-react";
import userEvent from "@testing-library/user-event";
import { MatrixClient, createClient } from "matrix-js-sdk/src/matrix";
@@ -68,13 +68,13 @@ describe("<ForgotPassword>", () => {
afterEach(async () => {
// clean up modals
await clearAllModals();
cleanup();
});
describe("when starting a password reset flow", () => {
beforeEach(() => {
renderResult = render(
<ForgotPassword serverConfig={serverConfig} onComplete={onComplete} onLoginClick={onLoginClick} />,
{ legacyRoot: true },
);
});
@@ -120,6 +120,7 @@ describe("<ForgotPassword>", () => {
describe("and submitting an unknown email", () => {
beforeEach(async () => {
mocked(AutoDiscoveryUtils.validateServerConfigWithStaticUrls).mockResolvedValue(serverConfig);
await typeIntoField("Email address", testEmail);
mocked(client).requestPasswordEmailToken.mockRejectedValue({
errcode: "M_THREEPID_NOT_FOUND",