2022-04-11 16:29:07 +08:00
|
|
|
/*
|
2024-09-09 21:57:16 +08:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-02-08 16:31:24 +08:00
|
|
|
Copyright 2022, 2023 The Matrix.org Foundation C.I.C.
|
2022-04-11 16:29:07 +08:00
|
|
|
|
2024-09-09 21:57:16 +08:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-04-11 16:29:07 +08:00
|
|
|
*/
|
|
|
|
|
2022-12-12 19:24:14 +08:00
|
|
|
import React from "react";
|
2022-12-19 07:17:15 +08:00
|
|
|
import * as maplibregl from "maplibre-gl";
|
2023-02-08 16:31:24 +08:00
|
|
|
import { render, screen } from "@testing-library/react";
|
2022-04-11 16:29:07 +08:00
|
|
|
|
2022-12-12 19:24:14 +08:00
|
|
|
import ZoomButtons from "../../../../src/components/views/location/ZoomButtons";
|
2022-04-11 16:29:07 +08:00
|
|
|
|
2022-12-12 19:24:14 +08:00
|
|
|
describe("<ZoomButtons />", () => {
|
2022-12-19 07:17:15 +08:00
|
|
|
const mapOptions = { container: {} as unknown as HTMLElement, style: "" };
|
|
|
|
const mockMap = new maplibregl.Map(mapOptions);
|
2022-04-11 16:29:07 +08:00
|
|
|
const defaultProps = {
|
|
|
|
map: mockMap,
|
|
|
|
};
|
2023-02-08 16:31:24 +08:00
|
|
|
const getComponent = (props = {}) => render(<ZoomButtons {...defaultProps} {...props} />);
|
2022-04-11 16:29:07 +08:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2022-12-12 19:24:14 +08:00
|
|
|
it("renders buttons", () => {
|
2022-04-11 16:29:07 +08:00
|
|
|
const component = getComponent();
|
2023-02-08 16:31:24 +08:00
|
|
|
expect(component.asFragment()).toMatchSnapshot();
|
2022-04-11 16:29:07 +08:00
|
|
|
});
|
|
|
|
|
2022-12-12 19:24:14 +08:00
|
|
|
it("calls map zoom in on zoom in click", () => {
|
2022-04-11 16:29:07 +08:00
|
|
|
const component = getComponent();
|
2023-02-08 16:31:24 +08:00
|
|
|
screen.getByTestId("map-zoom-in-button").click();
|
2022-04-11 16:29:07 +08:00
|
|
|
|
|
|
|
expect(mockMap.zoomIn).toHaveBeenCalled();
|
|
|
|
expect(component).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2022-12-12 19:24:14 +08:00
|
|
|
it("calls map zoom out on zoom out click", () => {
|
2022-04-11 16:29:07 +08:00
|
|
|
const component = getComponent();
|
2023-02-08 16:31:24 +08:00
|
|
|
screen.getByTestId("map-zoom-out-button").click();
|
2022-04-11 16:29:07 +08:00
|
|
|
|
|
|
|
expect(mockMap.zoomOut).toHaveBeenCalled();
|
|
|
|
expect(component).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|