Skip to content

Commit 1fd22a2

Browse files
authored
feat: data.polygon mock and add feature to registry (#305)
1 parent 544c665 commit 1fd22a2

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

src/drawing/data/data.feature.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
export class Feature implements google.maps.Data.Feature {
18-
constructor(options?: google.maps.Data.FeatureOptions | null) {}
17+
import { MVCObject } from "../../maps/event/mvcobject";
18+
19+
export class Feature extends MVCObject implements google.maps.Data.Feature {
20+
constructor(options?: google.maps.Data.FeatureOptions | null) {
21+
super();
22+
}
1923
public forEachProperty = jest
2024
.fn()
2125
.mockImplementation((callback: (a: any, b: string) => void) => {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
test("feature object is mocked", () => {
20+
initialize();
21+
expect(new google.maps.Data.Polygon(null)).toBeTruthy();
22+
});

src/drawing/data/data.polygon.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 DataPolygon extends MVCObject implements google.maps.Data.Polygon {
20+
constructor(
21+
elements?:
22+
| google.maps.MVCArray<google.maps.MVCArray<google.maps.LatLng>>
23+
| google.maps.MVCArray<google.maps.LatLng>
24+
| google.maps.LatLng[][]
25+
| google.maps.LatLngLiteral[][]
26+
| google.maps.LatLng[]
27+
| google.maps.LatLngLiteral[]
28+
) {
29+
super();
30+
}
31+
public forEachLatLng = jest
32+
.fn()
33+
.mockImplementation((callback: (a: google.maps.LatLng) => void): void => {
34+
return null;
35+
});
36+
public getArray = jest
37+
.fn()
38+
.mockImplementation(
39+
(): google.maps.MVCArray<google.maps.LatLng>[] =>
40+
[] as google.maps.MVCArray<google.maps.LatLng>[]
41+
);
42+
public getAt = jest
43+
.fn()
44+
.mockImplementation(
45+
(): google.maps.MVCArray<google.maps.LatLng> | null => null
46+
);
47+
public getLength = jest.fn().mockImplementation((): number => 0);
48+
public getType = jest.fn().mockImplementation((): string => "MultiPolygon");
49+
}

src/drawing/data/data.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { ControlPosition } from "../../maps/controls/controlposition";
1818
import { MVCObject } from "../../maps/event/mvcobject";
1919
import { Feature } from "./data.feature";
20+
import { DataPolygon } from "./data.polygon";
2021

2122
export class Data extends MVCObject implements google.maps.Data {
2223
constructor(opt?: google.maps.Data.DataOptions | null) {
@@ -29,6 +30,19 @@ export class Data extends MVCObject implements google.maps.Data {
2930
options?: google.maps.Data.FeatureOptions | null
3031
): google.maps.Data.Feature => new Feature(options)
3132
);
33+
public static Polygon = jest
34+
.fn()
35+
.mockImplementation(
36+
(
37+
elements?:
38+
| google.maps.MVCArray<google.maps.MVCArray<google.maps.LatLng>>
39+
| google.maps.MVCArray<google.maps.LatLng>
40+
| google.maps.LatLng[][]
41+
| google.maps.LatLngLiteral[][]
42+
| google.maps.LatLng[]
43+
| google.maps.LatLngLiteral[]
44+
): google.maps.Data.Polygon => new DataPolygon(elements)
45+
);
3246
public add = jest
3347
.fn()
3448
.mockImplementation(

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { AutocompleteService } from "./places/autocomplete-service/autocomplete-
2727
import { DistanceMatrixService } from "./routes/distance-matrix-service/distance-matrix-service";
2828
import { Circle } from "./drawing/polygons/circle";
2929
import { Data } from "./drawing/data/data";
30+
import { DataPolygon } from "./drawing/data/data.polygon";
3031
import { Feature } from "./drawing/data/data.feature";
3132
import { MVCArray } from "./maps/event/mvcarray";
3233
import { MVCObject } from "./maps/event/mvcobject";
@@ -112,6 +113,7 @@ export {
112113
Geocoder,
113114
Circle,
114115
Data,
116+
DataPolygon,
115117
event,
116118
Feature,
117119
LatLng,

0 commit comments

Comments
 (0)