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:
parent
d5c111f656
commit
95630f525f
9 changed files with 40 additions and 38 deletions
|
@ -113,16 +113,16 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
||||||
this.unmounted = true;
|
this.unmounted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async checkServerLiveliness(serverConfig: ValidatedServerConfig): Promise<void> {
|
private async checkServerLiveliness(serverConfig: ValidatedServerConfig): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(serverConfig.hsUrl, serverConfig.isUrl);
|
await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(serverConfig.hsUrl, serverConfig.isUrl);
|
||||||
if (this.unmounted) return;
|
if (this.unmounted) return false;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
serverIsAlive: true,
|
serverIsAlive: true,
|
||||||
});
|
});
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (this.unmounted) return;
|
if (this.unmounted) return false;
|
||||||
const { serverIsAlive, serverDeadError } = AutoDiscoveryUtils.authComponentStateForError(
|
const { serverIsAlive, serverDeadError } = AutoDiscoveryUtils.authComponentStateForError(
|
||||||
e,
|
e,
|
||||||
"forgot_password",
|
"forgot_password",
|
||||||
|
@ -131,7 +131,9 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
||||||
serverIsAlive,
|
serverIsAlive,
|
||||||
errorText: serverDeadError,
|
errorText: serverDeadError,
|
||||||
});
|
});
|
||||||
|
return serverIsAlive;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onPhaseEmailInputSubmit(): Promise<void> {
|
private async onPhaseEmailInputSubmit(): Promise<void> {
|
||||||
|
@ -299,10 +301,10 @@ export default class ForgotPassword extends React.Component<Props, State> {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Refresh the server errors. Just in case the server came back online of went offline.
|
// Refresh the server errors. Just in case the server came back online of went offline.
|
||||||
await this.checkServerLiveliness(this.props.serverConfig);
|
const serverIsAlive = await this.checkServerLiveliness(this.props.serverConfig);
|
||||||
|
|
||||||
// Server error
|
// Server error
|
||||||
if (!this.state.serverIsAlive) return;
|
if (!serverIsAlive) return;
|
||||||
|
|
||||||
switch (this.state.phase) {
|
switch (this.state.phase) {
|
||||||
case Phase.EnterEmail:
|
case Phase.EnterEmail:
|
||||||
|
|
|
@ -162,8 +162,11 @@ describe("<MatrixChat />", () => {
|
||||||
};
|
};
|
||||||
let initPromise: Promise<void> | undefined;
|
let initPromise: Promise<void> | undefined;
|
||||||
let defaultProps: ComponentProps<typeof MatrixChat>;
|
let defaultProps: ComponentProps<typeof MatrixChat>;
|
||||||
const getComponent = (props: Partial<ComponentProps<typeof MatrixChat>> = {}) =>
|
const getComponent = (props: Partial<ComponentProps<typeof MatrixChat>> = {}) => {
|
||||||
render(<MatrixChat {...defaultProps} {...props} />, { legacyRoot: true });
|
// 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
|
// make test results readable
|
||||||
filterConsole(
|
filterConsole(
|
||||||
|
@ -1128,7 +1131,7 @@ describe("<MatrixChat />", () => {
|
||||||
|
|
||||||
await getComponentAndLogin();
|
await getComponentAndLogin();
|
||||||
|
|
||||||
act(() => bootstrapDeferred.resolve());
|
bootstrapDeferred.resolve();
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
screen.findByRole("heading", { name: "You're in", level: 1 }),
|
screen.findByRole("heading", { name: "You're in", level: 1 }),
|
||||||
|
|
|
@ -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.
|
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 {
|
import {
|
||||||
ReceiptType,
|
ReceiptType,
|
||||||
EventTimelineSet,
|
EventTimelineSet,
|
||||||
|
@ -28,7 +28,7 @@ import {
|
||||||
ThreadFilterType,
|
ThreadFilterType,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||||
import React, { createRef } from "react";
|
import React from "react";
|
||||||
import { Mocked, mocked } from "jest-mock";
|
import { Mocked, mocked } from "jest-mock";
|
||||||
import { forEachRight } from "lodash";
|
import { forEachRight } from "lodash";
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ describe("TimelinePanel", () => {
|
||||||
const roomId = "#room:example.com";
|
const roomId = "#room:example.com";
|
||||||
let room: Room;
|
let room: Room;
|
||||||
let timelineSet: EventTimelineSet;
|
let timelineSet: EventTimelineSet;
|
||||||
let timelinePanel: TimelinePanel;
|
let timelinePanel: TimelinePanel | null = null;
|
||||||
|
|
||||||
const ev1 = new MatrixEvent({
|
const ev1 = new MatrixEvent({
|
||||||
event_id: "ev1",
|
event_id: "ev1",
|
||||||
|
@ -197,19 +197,16 @@ describe("TimelinePanel", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderTimelinePanel = async (): Promise<void> => {
|
const renderTimelinePanel = async (): Promise<void> => {
|
||||||
const ref = createRef<TimelinePanel>();
|
|
||||||
render(
|
render(
|
||||||
<TimelinePanel
|
<TimelinePanel
|
||||||
timelineSet={timelineSet}
|
timelineSet={timelineSet}
|
||||||
manageReadMarkers={true}
|
manageReadMarkers={true}
|
||||||
manageReadReceipts={true}
|
manageReadReceipts={true}
|
||||||
ref={ref}
|
ref={(ref) => (timelinePanel = ref)}
|
||||||
/>,
|
/>,
|
||||||
{ legacyRoot: true },
|
|
||||||
);
|
);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
await waitFor(() => expect(ref.current).toBeTruthy());
|
await waitFor(() => expect(timelinePanel).toBeTruthy());
|
||||||
timelinePanel = ref.current!;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const setUpTimelineSet = (threadRoot?: MatrixEvent) => {
|
const setUpTimelineSet = (threadRoot?: MatrixEvent) => {
|
||||||
|
@ -234,8 +231,9 @@ describe("TimelinePanel", () => {
|
||||||
room = new Room(roomId, client, userId, { pendingEventOrdering: PendingEventOrdering.Detached });
|
room = new Room(roomId, client, userId, { pendingEventOrdering: PendingEventOrdering.Detached });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(async () => {
|
||||||
TimelinePanel.roomReadMarkerTsMap = {};
|
TimelinePanel.roomReadMarkerTsMap = {};
|
||||||
|
cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when there is no event, it should not send any receipt", async () => {
|
it("when there is no event, it should not send any receipt", async () => {
|
||||||
|
@ -257,17 +255,14 @@ describe("TimelinePanel", () => {
|
||||||
|
|
||||||
describe("and reading the timeline", () => {
|
describe("and reading the timeline", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await act(async () => {
|
|
||||||
await renderTimelinePanel();
|
await renderTimelinePanel();
|
||||||
timelineSet.addLiveEvent(ev1, {});
|
timelineSet.addLiveEvent(ev1, {});
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
await timelinePanel.sendReadReceipts();
|
await timelinePanel.sendReadReceipts();
|
||||||
// @ts-ignore Simulate user activity by calling updateReadMarker on the TimelinePanel.
|
// @ts-ignore Simulate user activity by calling updateReadMarker on the TimelinePanel.
|
||||||
await timelinePanel.updateReadMarker();
|
await timelinePanel.updateReadMarker();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it("should send a fully read marker and a public receipt", async () => {
|
it("should send a fully read marker and a public receipt", async () => {
|
||||||
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev1.getId());
|
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev1.getId());
|
||||||
|
@ -295,7 +290,7 @@ describe("TimelinePanel", () => {
|
||||||
// setup, timelineSet is not actually the timelineSet of the room.
|
// setup, timelineSet is not actually the timelineSet of the room.
|
||||||
await room.addLiveEvents([ev2], {});
|
await room.addLiveEvents([ev2], {});
|
||||||
room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]);
|
room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]);
|
||||||
await timelinePanel.forgetReadMarker();
|
await timelinePanel!.forgetReadMarker();
|
||||||
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev2.getId());
|
expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev2.getId());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,7 @@ Please see LICENSE files in the repository root for full details.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { mocked } from "jest-mock";
|
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 userEvent from "@testing-library/user-event";
|
||||||
import { MatrixClient, createClient } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient, createClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
|
@ -68,13 +68,13 @@ describe("<ForgotPassword>", () => {
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
// clean up modals
|
// clean up modals
|
||||||
await clearAllModals();
|
await clearAllModals();
|
||||||
|
cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when starting a password reset flow", () => {
|
describe("when starting a password reset flow", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
renderResult = render(
|
renderResult = render(
|
||||||
<ForgotPassword serverConfig={serverConfig} onComplete={onComplete} onLoginClick={onLoginClick} />,
|
<ForgotPassword serverConfig={serverConfig} onComplete={onComplete} onLoginClick={onLoginClick} />,
|
||||||
{ legacyRoot: true },
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -120,6 +120,7 @@ describe("<ForgotPassword>", () => {
|
||||||
|
|
||||||
describe("and submitting an unknown email", () => {
|
describe("and submitting an unknown email", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
mocked(AutoDiscoveryUtils.validateServerConfigWithStaticUrls).mockResolvedValue(serverConfig);
|
||||||
await typeIntoField("Email address", testEmail);
|
await typeIntoField("Email address", testEmail);
|
||||||
mocked(client).requestPasswordEmailToken.mockRejectedValue({
|
mocked(client).requestPasswordEmailToken.mockRejectedValue({
|
||||||
errcode: "M_THREEPID_NOT_FOUND",
|
errcode: "M_THREEPID_NOT_FOUND",
|
||||||
|
|
|
@ -48,7 +48,6 @@ describe("DateSeparator", () => {
|
||||||
<MatrixClientContext.Provider value={mockClient}>
|
<MatrixClientContext.Provider value={mockClient}>
|
||||||
<DateSeparator {...defaultProps} {...props} />
|
<DateSeparator {...defaultProps} {...props} />
|
||||||
</MatrixClientContext.Provider>,
|
</MatrixClientContext.Provider>,
|
||||||
{ legacyRoot: true },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
type TestCase = [string, number, string];
|
type TestCase = [string, number, string];
|
||||||
|
|
|
@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { render, waitFor, waitForElementToBeRemoved } from "jest-matrix-react";
|
import { render, waitFor } from "jest-matrix-react";
|
||||||
import { EventTimeline, MatrixEvent, Room, M_TEXT } from "matrix-js-sdk/src/matrix";
|
import { EventTimeline, MatrixEvent, Room, M_TEXT } from "matrix-js-sdk/src/matrix";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
|
||||||
|
@ -121,13 +121,13 @@ describe("<MPollEndBody />", () => {
|
||||||
describe("when poll start event does not exist in current timeline", () => {
|
describe("when poll start event does not exist in current timeline", () => {
|
||||||
it("fetches the related poll start event and displays a poll tile", async () => {
|
it("fetches the related poll start event and displays a poll tile", async () => {
|
||||||
await setupRoomWithEventsTimeline(pollEndEvent);
|
await setupRoomWithEventsTimeline(pollEndEvent);
|
||||||
const { container, getByTestId, getByRole } = getComponent();
|
const { container, getByTestId, getByRole, queryByRole } = getComponent();
|
||||||
|
|
||||||
// while fetching event, only icon is shown
|
// while fetching event, only icon is shown
|
||||||
expect(container).toMatchSnapshot();
|
expect(container).toMatchSnapshot();
|
||||||
|
|
||||||
await waitFor(() => expect(getByRole("progressbar")).toBeInTheDocument());
|
await waitFor(() => expect(getByRole("progressbar")).toBeInTheDocument());
|
||||||
await waitForElementToBeRemoved(() => getByRole("progressbar"));
|
await waitFor(() => expect(queryByRole("progressbar")).not.toBeInTheDocument());
|
||||||
|
|
||||||
expect(mockClient.fetchRoomEvent).toHaveBeenCalledWith(roomId, pollStartEvent.getId());
|
expect(mockClient.fetchRoomEvent).toHaveBeenCalledWith(roomId, pollStartEvent.getId());
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { fireEvent, render, screen, cleanup, act, within } from "jest-matrix-react";
|
import { fireEvent, render, screen, cleanup, act, within, waitForElementToBeRemoved } from "jest-matrix-react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { Mocked, mocked } from "jest-mock";
|
import { Mocked, mocked } from "jest-mock";
|
||||||
import { Room, User, MatrixClient, RoomMember, MatrixEvent, EventType, Device } from "matrix-js-sdk/src/matrix";
|
import { Room, User, MatrixClient, RoomMember, MatrixEvent, EventType, Device } from "matrix-js-sdk/src/matrix";
|
||||||
|
@ -199,7 +199,6 @@ describe("<UserInfo />", () => {
|
||||||
|
|
||||||
return render(<UserInfo {...defaultProps} {...props} />, {
|
return render(<UserInfo {...defaultProps} {...props} />, {
|
||||||
wrapper: Wrapper,
|
wrapper: Wrapper,
|
||||||
legacyRoot: true,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -655,6 +654,9 @@ describe("<UserInfo />", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(screen.findByRole("button", { name: "Deactivate user" })).resolves.toBeInTheDocument();
|
await expect(screen.findByRole("button", { name: "Deactivate user" })).resolves.toBeInTheDocument();
|
||||||
|
if (screen.queryAllByRole("progressbar").length) {
|
||||||
|
await waitForElementToBeRemoved(() => screen.queryAllByRole("progressbar"));
|
||||||
|
}
|
||||||
expect(container).toMatchSnapshot();
|
expect(container).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -519,7 +519,7 @@ function wrapAndRender(
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
rawComponent: getRawComponent(props, roomContext, mockClient),
|
rawComponent: getRawComponent(props, roomContext, mockClient),
|
||||||
renderResult: render(getRawComponent(props, roomContext, mockClient), { legacyRoot: true }),
|
renderResult: render(getRawComponent(props, roomContext, mockClient)),
|
||||||
roomContext,
|
roomContext,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe("<JoinRuleSettings />", () => {
|
||||||
onError: jest.fn(),
|
onError: jest.fn(),
|
||||||
};
|
};
|
||||||
const getComponent = (props: Partial<JoinRuleSettingsProps> = {}) =>
|
const getComponent = (props: Partial<JoinRuleSettingsProps> = {}) =>
|
||||||
render(<JoinRuleSettings {...defaultProps} {...props} />, { legacyRoot: false });
|
render(<JoinRuleSettings {...defaultProps} {...props} />);
|
||||||
|
|
||||||
const setRoomStateEvents = (
|
const setRoomStateEvents = (
|
||||||
room: Room,
|
room: Room,
|
||||||
|
|
Loading…
Reference in a new issue