Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: google.maps.Data object mocks #142

Merged
merged 4 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"plugins": ["jest"],
"rules": {
"no-var": 2,
"prefer-arrow-callback": 2
"prefer-arrow-callback": 2,
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
},
"overrides": [
{
Expand Down
24 changes: 24 additions & 0 deletions src/data.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2019 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";

test("data object is mocked", () => {
initialize();
expect(new google.maps.Data(null)).toBeTruthy();
const map = new google.maps.Map(null);
expect(map.data).toBeTruthy();
});
140 changes: 140 additions & 0 deletions src/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* Copyright 2019 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 "./mvcobject";

export class Data extends MVCObject implements google.maps.Data {
constructor(opt?: google.maps.Data.DataOptions | null) {
super();
}
public add = jest
.fn()
.mockImplementation(
(
feature?:
| google.maps.Data.Feature
| null
| google.maps.Data.FeatureOptions
) => {
return null;
}
);
public addGeoJson = jest
.fn()
.mockImplementation(
(geoJson: object, options?: google.maps.Data.GeoJsonOptions | null) => {
return [];
}
);
public contains = jest
.fn()
.mockImplementation((feature: google.maps.Data.Feature) => {
return false;
});
public forEach = jest
.fn()
.mockImplementation((callback: (a: google.maps.Data.Feature) => void) => {
return null;
});
public getControlPosition = jest.fn().mockImplementation(() => {
return null;
});
public getControls = jest.fn().mockImplementation(() => {
return null;
});
public getDrawingMode = jest.fn().mockImplementation(() => {
return null;
});
public getFeatureById = jest
.fn()
.mockImplementation((id: number | string) => {
return undefined;
});
public getMap = jest.fn().mockImplementation(() => {
return null;
});
public getStyle = jest.fn().mockImplementation(() => {
return null;
});
public loadGeoJson = jest
.fn()
.mockImplementation(
(
url: string,
options?: google.maps.Data.GeoJsonOptions | null,
callback?: (a: google.maps.Data.Feature[]) => void
) => {
return null;
}
);
public overrideStyle = jest
.fn()
.mockImplementation(
(
feature: google.maps.Data.Feature,
style: google.maps.Data.StyleOptions
) => {
return null;
}
);
public remove = jest
.fn()
.mockImplementation((feature: google.maps.Data.Feature) => {
return null;
});
public revertStyle = jest
.fn()
.mockImplementation((feature?: google.maps.Data.Feature | null) => {
return null;
});
public setControlPosition = jest
.fn()
.mockImplementation((controlPosition: google.maps.ControlPosition) => {
return null;
});
public setControls = jest
.fn()
.mockImplementation((controls: string[] | null) => {
return null;
});
public setDrawingMode = jest
.fn()
.mockImplementation((drawingMode: string | null) => {
return null;
});
public setMap = jest
.fn()
.mockImplementation((map: google.maps.Map | null) => {
return null;
});
public setStyle = jest
.fn()
.mockImplementation(
(
style:
| google.maps.Data.StylingFunction
| google.maps.Data.StyleOptions
| null
) => {
return null;
}
);
public toGeoJson = jest
.fn()
.mockImplementation((callback: (a: object) => void) => {
return null;
});
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { LatLng, LatLngBounds } from "./latlng";

import { Autocomplete } from "./places/autocomplete";
import { Circle } from "./circle";
import { Data } from "./data";
import { MVCArray } from "./mvcarray";
import { MVCObject } from "./mvcobject";
import { MapCanvasProjection } from "./mapcanvasprojection";
Expand All @@ -46,6 +47,7 @@ const initialize = function (): void {
ImageMapType: jest.fn(),
Marker: Marker,
Map: Map_,
Data: Data,
Point: Point,
Size: Size,
MVCObject: MVCObject,
Expand Down Expand Up @@ -80,6 +82,7 @@ const initialize = function (): void {
export {
Marker,
Map_ as Map,
Data,
Size,
MapCanvasProjection,
MapPanes,
Expand Down
1 change: 1 addition & 0 deletions src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Map_ extends MVCObject implements google.maps.Map {

constructor(mapDiv: Element | null, opts?: google.maps.MapOptions) {
super();
this.data = new google.maps.Data();
}
public fitBounds = jest
.fn()
Expand Down