Skip to content

Commit 00eb424

Browse files
authored
feat: Added mocks for Rectangle (#326)
* feat: Added mocks for Rectangle * test: Improved test suite for rectangle
1 parent b8a2c51 commit 00eb424

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright 2022 Google LLC. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { initialize } from "../../index";
18+
import { Map_ } from "../../maps/maps/map";
19+
20+
beforeEach(() => {
21+
initialize();
22+
});
23+
24+
test("Rectangle constructor is mocked", () => {
25+
expect(new google.maps.Rectangle(null)).toBeTruthy();
26+
});
27+
28+
test("getBounds returns null", () => {
29+
expect(new google.maps.Rectangle(null).getBounds()).toBeNull();
30+
});
31+
32+
test("getDraggable returns true", () => {
33+
expect(new google.maps.Rectangle(null).getDraggable()).toBe(true);
34+
});
35+
36+
test("getEditable returns true", () => {
37+
expect(new google.maps.Rectangle(null).getEditable()).toBe(true);
38+
});
39+
40+
test("getMap returns map", () => {
41+
expect(new google.maps.Rectangle(null).getMap()).toBeInstanceOf(Map_);
42+
});
43+
44+
test("getVisible returns true", () => {
45+
expect(new google.maps.Rectangle(null).getVisible()).toBe(true);
46+
});
47+
48+
test("setBounds is mocked", () => {
49+
const rect = new google.maps.Rectangle(null);
50+
const bounds = { north: 1, east: 2, west: 3, south: 4 };
51+
rect.setBounds(bounds);
52+
expect(rect.setBounds).toHaveBeenCalledWith(bounds);
53+
});
54+
55+
test("setDraggable is mocked", () => {
56+
const rect = new google.maps.Rectangle(null);
57+
rect.setDraggable(false);
58+
expect(rect.setDraggable).toHaveBeenCalledWith(false);
59+
});
60+
61+
test("setEditable is mocked", () => {
62+
const rect = new google.maps.Rectangle(null);
63+
rect.setEditable(false);
64+
expect(rect.setEditable).toHaveBeenCalledWith(false);
65+
});
66+
67+
test("setMap is mocked", () => {
68+
const rect = new google.maps.Rectangle(null);
69+
const myMap = {} as any;
70+
rect.setMap(myMap);
71+
expect(rect.setMap).toHaveBeenCalledWith({});
72+
});
73+
74+
test("setOptions is mocked", () => {
75+
const rect = new google.maps.Rectangle(null);
76+
rect.setOptions({ editable: true });
77+
expect(rect.setOptions).toHaveBeenCalledWith({ editable: true });
78+
});
79+
80+
test("setVisible is mocked", () => {
81+
const rect = new google.maps.Rectangle(null);
82+
rect.setVisible(false);
83+
expect(rect.setVisible).toHaveBeenCalledWith(false);
84+
});

src/drawing/polygons/rectangle.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2022 Google LLC. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { MVCObject } from "../../maps/event/mvcobject";
18+
import { Map_ } from "../../maps/maps/map";
19+
20+
export class Rectangle extends MVCObject implements google.maps.Rectangle {
21+
constructor(opt?: google.maps.RectangleOptions) {
22+
super();
23+
}
24+
public getBounds = jest.fn(() => null);
25+
public getDraggable = jest.fn(() => true);
26+
public getEditable = jest.fn(() => true);
27+
public getMap = jest.fn(() => new Map_(null));
28+
public getVisible = jest.fn(() => true);
29+
public setBounds = jest.fn(
30+
(bounds: google.maps.LatLngBounds | google.maps.LatLngBoundsLiteral) => {}
31+
);
32+
public setDraggable = jest.fn((draggable: boolean) => {});
33+
public setEditable = jest.fn((editable: boolean) => {});
34+
public setMap = jest.fn((map: google.maps.Map | null) => {});
35+
public setOptions = jest.fn(
36+
(options: google.maps.RectangleOptions | null) => {}
37+
);
38+
public setVisible = jest.fn((visible: boolean) => {});
39+
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { KmlLayer } from "./drawing/kml/kmllayer";
3333
import { Point } from "./maps/coordinates/point";
3434
import { Polygon } from "./drawing/polygons/polygon";
3535
import { Polyline } from "./drawing/polygons/polyline";
36+
import { Rectangle } from "./drawing/polygons/rectangle";
3637
import { SearchBox } from "./places/searchbox";
3738
import { Size } from "./maps/coordinates/size";
3839
import { VisibleRegion } from "./maps/maps/visibleregion";
@@ -80,6 +81,7 @@ const initialize = function (): void {
8081
Polygon: Polygon,
8182
Polyline: Polyline,
8283
Circle: Circle,
84+
Rectangle: Rectangle,
8385
OverlayView: OverlayView,
8486
KmlLayer: KmlLayer,
8587
MapCanvasProjection: MapCanvasProjection,
@@ -109,6 +111,7 @@ export {
109111
Point,
110112
Polygon,
111113
Polyline,
114+
Rectangle,
112115
SearchBox,
113116
Size,
114117
StreetViewCoverageLayer,

0 commit comments

Comments
 (0)