From 2c30e6d909b499ff10df7a147cda2d76ffbf0449 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Wed, 8 Feb 2023 09:31:24 +0100 Subject: [PATCH] Migrate `ZoomButtons-test` to react-testing-library (#10104) --- src/components/views/location/ZoomButtons.tsx | 4 +- .../views/location/ZoomButtons-test.tsx | 21 ++--- .../LocationViewDialog-test.tsx.snap | 8 +- .../__snapshots__/ZoomButtons-test.tsx.snap | 76 +++++-------------- 4 files changed, 29 insertions(+), 80 deletions(-) diff --git a/src/components/views/location/ZoomButtons.tsx b/src/components/views/location/ZoomButtons.tsx index 4c707979bc..461cdad3cd 100644 --- a/src/components/views/location/ZoomButtons.tsx +++ b/src/components/views/location/ZoomButtons.tsx @@ -39,7 +39,7 @@ const ZoomButtons: React.FC = ({ map }) => {
@@ -47,7 +47,7 @@ const ZoomButtons: React.FC = ({ map }) => { diff --git a/test/components/views/location/ZoomButtons-test.tsx b/test/components/views/location/ZoomButtons-test.tsx index 831860bcd5..8fbe6710eb 100644 --- a/test/components/views/location/ZoomButtons-test.tsx +++ b/test/components/views/location/ZoomButtons-test.tsx @@ -1,5 +1,5 @@ /* -Copyright 2022 The Matrix.org Foundation C.I.C. +Copyright 2022, 2023 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,13 +15,10 @@ limitations under the License. */ import React from "react"; -// eslint-disable-next-line deprecate/import -import { mount } from "enzyme"; import * as maplibregl from "maplibre-gl"; -import { act } from "react-dom/test-utils"; +import { render, screen } from "@testing-library/react"; import ZoomButtons from "../../../../src/components/views/location/ZoomButtons"; -import { findByTestId } from "../../../test-utils"; describe("", () => { const mapOptions = { container: {} as unknown as HTMLElement, style: "" }; @@ -29,7 +26,7 @@ describe("", () => { const defaultProps = { map: mockMap, }; - const getComponent = (props = {}) => mount(); + const getComponent = (props = {}) => render(); beforeEach(() => { jest.clearAllMocks(); @@ -37,15 +34,12 @@ describe("", () => { it("renders buttons", () => { const component = getComponent(); - expect(component).toMatchSnapshot(); + expect(component.asFragment()).toMatchSnapshot(); }); it("calls map zoom in on zoom in click", () => { const component = getComponent(); - - act(() => { - findByTestId(component, "map-zoom-in-button").at(0).simulate("click"); - }); + screen.getByTestId("map-zoom-in-button").click(); expect(mockMap.zoomIn).toHaveBeenCalled(); expect(component).toBeTruthy(); @@ -53,10 +47,7 @@ describe("", () => { it("calls map zoom out on zoom out click", () => { const component = getComponent(); - - act(() => { - findByTestId(component, "map-zoom-out-button").at(0).simulate("click"); - }); + screen.getByTestId("map-zoom-out-button").click(); expect(mockMap.zoomOut).toHaveBeenCalled(); expect(component).toBeTruthy(); diff --git a/test/components/views/location/__snapshots__/LocationViewDialog-test.tsx.snap b/test/components/views/location/__snapshots__/LocationViewDialog-test.tsx.snap index a2284ceee8..32670dadac 100644 --- a/test/components/views/location/__snapshots__/LocationViewDialog-test.tsx.snap +++ b/test/components/views/location/__snapshots__/LocationViewDialog-test.tsx.snap @@ -135,7 +135,7 @@ exports[` renders map correctly 1`] = ` > renders map correctly 1`] = ` >
renders map correctly 1`] = ` renders map correctly 1`] = ` >
renders buttons 1`] = ` - +
-
-
-
- - +
+
-
-
- + class="mx_ZoomButtons_icon" + /> +
- + `;