Remove Enzyme tests in favour of React testing-library (#10289)

This commit is contained in:
Michael Telatynski
2023-03-06 12:13:17 +00:00
committed by GitHub
parent 303b878b17
commit 667ec166d7
10 changed files with 432 additions and 3163 deletions

View File

@@ -14,16 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React from "react";
// eslint-disable-next-line deprecate/import
import { mount, ReactWrapper } from "enzyme";
import React, { createRef, RefObject } from "react";
import { mocked, MockedObject } from "jest-mock";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib";
import { fireEvent, render, screen } from "@testing-library/react";
import { fireEvent, render, screen, RenderResult } from "@testing-library/react";
import {
stubClient,
@@ -98,7 +96,7 @@ describe("RoomView", () => {
jest.restoreAllMocks();
});
const mountRoomView = async (): Promise<ReactWrapper> => {
const mountRoomView = async (ref?: RefObject<_RoomView>): Promise<RenderResult> => {
if (stores.roomViewStore.getRoomId() !== room.roomId) {
const switchedRoom = new Promise<void>((resolve) => {
const subFn = () => {
@@ -119,7 +117,7 @@ describe("RoomView", () => {
await switchedRoom;
}
const roomView = mount(
const roomView = render(
<SDKContext.Provider value={stores}>
<RoomView
// threepidInvite should be optional on RoomView props
@@ -127,6 +125,7 @@ describe("RoomView", () => {
threepidInvite={undefined as any}
resizeNotifier={new ResizeNotifier()}
forceTimeline={false}
wrappedRef={ref as any}
/>
</SDKContext.Provider>,
);
@@ -170,8 +169,11 @@ describe("RoomView", () => {
await flushPromises();
return roomView;
};
const getRoomViewInstance = async (): Promise<_RoomView> =>
(await mountRoomView()).find(_RoomView).instance() as _RoomView;
const getRoomViewInstance = async (): Promise<_RoomView> => {
const ref = createRef<_RoomView>();
await mountRoomView(ref);
return ref.current!;
};
it("when there is no room predecessor, getHiddenHighlightCount should return 0", async () => {
const instance = await getRoomViewInstance();

View File

@@ -15,8 +15,6 @@ limitations under the License.
*/
import { render, waitFor, screen } from "@testing-library/react";
// eslint-disable-next-line deprecate/import
import { mount, ReactWrapper } from "enzyme";
import { ReceiptType } from "matrix-js-sdk/src/@types/read_receipts";
import {
EventTimelineSet,
@@ -38,7 +36,7 @@ import {
ThreadEvent,
ThreadFilterType,
} from "matrix-js-sdk/src/models/thread";
import React from "react";
import React, { createRef } from "react";
import TimelinePanel from "../../../src/components/structures/TimelinePanel";
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
@@ -137,15 +135,17 @@ describe("TimelinePanel", () => {
// Create a TimelinePanel with ev0 already present
const timelineSet = new EventTimelineSet(room, {});
timelineSet.addLiveEvent(ev0);
const component: ReactWrapper<TimelinePanel> = mount(
const ref = createRef<TimelinePanel>();
render(
<TimelinePanel
timelineSet={timelineSet}
manageReadMarkers={true}
manageReadReceipts={true}
eventId={ev0.getId()}
ref={ref}
/>,
);
const timelinePanel = component.instance() as TimelinePanel;
const timelinePanel = ref.current!;
// An event arrived, and we read it
timelineSet.addLiveEvent(ev1);