diff --git a/src/drawing/polygons/rectangle.test.ts b/src/drawing/polygons/rectangle.test.ts new file mode 100644 index 000000000..da4693b4d --- /dev/null +++ b/src/drawing/polygons/rectangle.test.ts @@ -0,0 +1,84 @@ +/** + * Copyright 2022 Google LLC. All Rights Reserved. + * + * 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 { initialize } from "../../index"; +import { Map_ } from "../../maps/maps/map"; + +beforeEach(() => { + initialize(); +}); + +test("Rectangle constructor is mocked", () => { + expect(new google.maps.Rectangle(null)).toBeTruthy(); +}); + +test("getBounds returns null", () => { + expect(new google.maps.Rectangle(null).getBounds()).toBeNull(); +}); + +test("getDraggable returns true", () => { + expect(new google.maps.Rectangle(null).getDraggable()).toBe(true); +}); + +test("getEditable returns true", () => { + expect(new google.maps.Rectangle(null).getEditable()).toBe(true); +}); + +test("getMap returns map", () => { + expect(new google.maps.Rectangle(null).getMap()).toBeInstanceOf(Map_); +}); + +test("getVisible returns true", () => { + expect(new google.maps.Rectangle(null).getVisible()).toBe(true); +}); + +test("setBounds is mocked", () => { + const rect = new google.maps.Rectangle(null); + const bounds = { north: 1, east: 2, west: 3, south: 4 }; + rect.setBounds(bounds); + expect(rect.setBounds).toHaveBeenCalledWith(bounds); +}); + +test("setDraggable is mocked", () => { + const rect = new google.maps.Rectangle(null); + rect.setDraggable(false); + expect(rect.setDraggable).toHaveBeenCalledWith(false); +}); + +test("setEditable is mocked", () => { + const rect = new google.maps.Rectangle(null); + rect.setEditable(false); + expect(rect.setEditable).toHaveBeenCalledWith(false); +}); + +test("setMap is mocked", () => { + const rect = new google.maps.Rectangle(null); + const myMap = {} as any; + rect.setMap(myMap); + expect(rect.setMap).toHaveBeenCalledWith({}); +}); + +test("setOptions is mocked", () => { + const rect = new google.maps.Rectangle(null); + rect.setOptions({ editable: true }); + expect(rect.setOptions).toHaveBeenCalledWith({ editable: true }); +}); + +test("setVisible is mocked", () => { + const rect = new google.maps.Rectangle(null); + rect.setVisible(false); + expect(rect.setVisible).toHaveBeenCalledWith(false); +}); diff --git a/src/drawing/polygons/rectangle.ts b/src/drawing/polygons/rectangle.ts new file mode 100644 index 000000000..bbc043fb2 --- /dev/null +++ b/src/drawing/polygons/rectangle.ts @@ -0,0 +1,39 @@ +/** + * Copyright 2022 Google LLC. All Rights Reserved. + * + * 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 { MVCObject } from "../../maps/event/mvcobject"; +import { Map_ } from "../../maps/maps/map"; + +export class Rectangle extends MVCObject implements google.maps.Rectangle { + constructor(opt?: google.maps.RectangleOptions) { + super(); + } + public getBounds = jest.fn(() => null); + public getDraggable = jest.fn(() => true); + public getEditable = jest.fn(() => true); + public getMap = jest.fn(() => new Map_(null)); + public getVisible = jest.fn(() => true); + public setBounds = jest.fn( + (bounds: google.maps.LatLngBounds | google.maps.LatLngBoundsLiteral) => {} + ); + public setDraggable = jest.fn((draggable: boolean) => {}); + public setEditable = jest.fn((editable: boolean) => {}); + public setMap = jest.fn((map: google.maps.Map | null) => {}); + public setOptions = jest.fn( + (options: google.maps.RectangleOptions | null) => {} + ); + public setVisible = jest.fn((visible: boolean) => {}); +} diff --git a/src/index.ts b/src/index.ts index 51ee5ff11..98d3b74d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,6 +33,7 @@ import { KmlLayer } from "./drawing/kml/kmllayer"; import { Point } from "./maps/coordinates/point"; import { Polygon } from "./drawing/polygons/polygon"; import { Polyline } from "./drawing/polygons/polyline"; +import { Rectangle } from "./drawing/polygons/rectangle"; import { SearchBox } from "./places/searchbox"; import { Size } from "./maps/coordinates/size"; import { VisibleRegion } from "./maps/maps/visibleregion"; @@ -80,6 +81,7 @@ const initialize = function (): void { Polygon: Polygon, Polyline: Polyline, Circle: Circle, + Rectangle: Rectangle, OverlayView: OverlayView, KmlLayer: KmlLayer, MapCanvasProjection: MapCanvasProjection, @@ -109,6 +111,7 @@ export { Point, Polygon, Polyline, + Rectangle, SearchBox, Size, StreetViewCoverageLayer,