Skip to content

Commit b478418

Browse files
feat: add google.maps.Polygon (#204)
1 parent 304f19f commit b478418

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

src/drawing/polygons/polygon.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
19+
beforeEach(() => {
20+
initialize();
21+
});
22+
23+
test("polygon constructor is mocked", () => {
24+
expect(new google.maps.Polygon(null)).toBeTruthy();
25+
});
26+
27+
test("getDraggable returns false", () => {
28+
expect(new google.maps.Polygon(null).getDraggable()).toBe(false);
29+
});
30+
31+
test("getEditable returns false", () => {
32+
expect(new google.maps.Polygon(null).getEditable()).toBe(false);
33+
});
34+
35+
test("getMap returns {}", () => {
36+
expect(new google.maps.Polygon(null).getMap()).toEqual({});
37+
});
38+
39+
test("getPath returns {}", () => {
40+
expect(new google.maps.Polygon(null).getPath()).toEqual({});
41+
});
42+
43+
test("getPaths returns {}", () => {
44+
expect(new google.maps.Polygon(null).getPaths()).toEqual({});
45+
});
46+
47+
test("getVisible returns false", () => {
48+
expect(new google.maps.Polygon(null).getVisible()).toEqual(false);
49+
});
50+
51+
test("setDraggable is mocked", () => {
52+
new google.maps.Polygon(null).setDraggable(true);
53+
});
54+
55+
test("setEditable is mocked", () => {
56+
new google.maps.Polygon(null).setEditable(true);
57+
});
58+
59+
test("setMap is mocked", () => {
60+
new google.maps.Polygon(null).setMap({} as google.maps.Map);
61+
});
62+
63+
test("setOptions is mocked", () => {
64+
new google.maps.Polygon(null).setOptions({});
65+
});
66+
67+
test("setPath is mocked", () => {
68+
new google.maps.Polygon(null).setPath([]);
69+
});
70+
71+
test("setPaths is mocked", () => {
72+
new google.maps.Polygon(null).setPaths([]);
73+
});
74+
75+
test("setVisible is mocked", () => {
76+
new google.maps.Polygon(null).setVisible(true);
77+
});

src/drawing/polygons/polygon.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
19+
export class Polygon extends MVCObject implements google.maps.Polygon {
20+
constructor(opts?: google.maps.PolygonOptions | null) {
21+
super();
22+
}
23+
24+
public getDraggable = jest.fn().mockImplementation((): boolean => false);
25+
public getEditable = jest.fn().mockImplementation((): boolean => false);
26+
public getMap = jest
27+
.fn()
28+
.mockImplementation((): google.maps.Map => ({} as google.maps.Map));
29+
public getPath = jest
30+
.fn()
31+
.mockImplementation(
32+
(): google.maps.MVCArray<google.maps.LatLng> =>
33+
({} as google.maps.MVCArray<google.maps.LatLng>)
34+
);
35+
public getPaths = jest
36+
.fn()
37+
.mockImplementation(
38+
(): google.maps.MVCArray<google.maps.MVCArray<google.maps.LatLng>> =>
39+
({} as google.maps.MVCArray<google.maps.MVCArray<google.maps.LatLng>>)
40+
);
41+
public getVisible = jest.fn().mockImplementation((): boolean => false);
42+
public setDraggable = jest
43+
.fn()
44+
.mockImplementation((draggable: boolean): void => {});
45+
public setEditable = jest
46+
.fn()
47+
.mockImplementation((editable: boolean): void => {});
48+
public setMap = jest
49+
.fn()
50+
.mockImplementation((map: google.maps.Map): void => {});
51+
public setOptions = jest
52+
.fn()
53+
.mockImplementation((options: google.maps.PolygonOptions): void => {});
54+
public setPath = jest
55+
.fn()
56+
.mockImplementation(
57+
(
58+
path:
59+
| google.maps.MVCArray<google.maps.LatLng>
60+
| google.maps.LatLng[]
61+
| google.maps.LatLngLiteral[]
62+
): void => {}
63+
);
64+
public setPaths = jest
65+
.fn()
66+
.mockImplementation(
67+
(
68+
paths:
69+
| google.maps.MVCArray<google.maps.MVCArray<google.maps.LatLng>>
70+
| google.maps.MVCArray<google.maps.LatLng>
71+
| google.maps.LatLng[][]
72+
| google.maps.LatLngLiteral[][]
73+
| google.maps.LatLng[]
74+
| google.maps.LatLngLiteral[]
75+
): void => {}
76+
);
77+
public setVisible = jest
78+
.fn()
79+
.mockImplementation((visible: boolean): void => {});
80+
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Map_ } from "./maps/maps/map";
3030
import { Marker } from "./drawing/marker/marker";
3131
import { OverlayView } from "./drawing/DOM/overlayview";
3232
import { Point } from "./maps/coordinates/point";
33+
import { Polygon } from "./drawing/polygons/polygon";
3334
import { Polyline } from "./drawing/polygons/polyline";
3435
import { SearchBox } from "./places/searchbox";
3536
import { Size } from "./maps/coordinates/size";
@@ -75,6 +76,7 @@ const initialize = function (): void {
7576
Autocomplete: Autocomplete,
7677
SearchBox: SearchBox,
7778
},
79+
Polygon: Polygon,
7880
Polyline: Polyline,
7981
Circle: Circle,
8082
OverlayView: OverlayView,
@@ -101,6 +103,7 @@ export {
101103
Marker,
102104
OverlayView,
103105
Point,
106+
Polygon,
104107
Polyline,
105108
Size,
106109
StreetViewCoverageLayer,

0 commit comments

Comments
 (0)