2022-04-11 16:29:07 +08:00
|
|
|
/*
|
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
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
import ZoomButtons from "../../../../src/components/views/location/ZoomButtons";
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("renders buttons", () => {
|
|
|
|
const component = getComponent();
|
2023-02-08 16:31:24 +08:00
|
|
|
expect(component.asFragment()).toMatchSnapshot();
|
2022-04-11 16:29:07 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("calls map zoom in on zoom in click", () => {
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("calls map zoom out on zoom out click", () => {
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|