From b108fb29c3d95a34a54dcdd0d77ca3aa6d715a81 Mon Sep 17 00:00:00 2001 From: Eric <43848365+eegli@users.noreply.github.com> Date: Tue, 30 Nov 2021 21:37:23 +0100 Subject: [PATCH 1/4] add data mocks --- src/data.test.ts | 24 ++++++++ src/data.ts | 140 +++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 3 + 3 files changed, 167 insertions(+) create mode 100644 src/data.test.ts create mode 100644 src/data.ts diff --git a/src/data.test.ts b/src/data.test.ts new file mode 100644 index 00000000..0689f984 --- /dev/null +++ b/src/data.test.ts @@ -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(); +}); diff --git a/src/data.ts b/src/data.ts new file mode 100644 index 00000000..9518ec39 --- /dev/null +++ b/src/data.ts @@ -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; + }); +} diff --git a/src/index.ts b/src/index.ts index 2c430936..71e0bf4d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; @@ -46,6 +47,7 @@ const initialize = function (): void { ImageMapType: jest.fn(), Marker: Marker, Map: Map_, + Data: Data, Point: Point, Size: Size, MVCObject: MVCObject, @@ -80,6 +82,7 @@ const initialize = function (): void { export { Marker, Map_ as Map, + Data, Size, MapCanvasProjection, MapPanes, From d5698595d01c318afec9f15e4ee3c27afe1575cd Mon Sep 17 00:00:00 2001 From: Eric <43848365+eegli@users.noreply.github.com> Date: Tue, 30 Nov 2021 21:43:39 +0100 Subject: [PATCH 2/4] adjust eol linter rules --- .eslintrc.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index fbda63ef..30fbfd5c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,7 +10,13 @@ "plugins": ["jest"], "rules": { "no-var": 2, - "prefer-arrow-callback": 2 + "prefer-arrow-callback": 2, + "prettier/prettier": [ + "error", + { + "endOfLine": "auto" + } + ] }, "overrides": [ { From d4858b0523baa7e9732cc043b8417e06663fd2ec Mon Sep 17 00:00:00 2001 From: Eric <43848365+eegli@users.noreply.github.com> Date: Tue, 30 Nov 2021 21:55:10 +0100 Subject: [PATCH 3/4] create data instance in map constructor --- src/map.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/map.ts b/src/map.ts index eadb65fa..16e4e42b 100644 --- a/src/map.ts +++ b/src/map.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { LatLng, LatLngBounds } from "./latlng"; +import { LatLng, LatLngBounds } from './latlng'; -import { MVCObject } from "./mvcobject"; +import { MVCObject } from './mvcobject'; export class Map_ extends MVCObject implements google.maps.Map { controls: Array>; @@ -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() From ebaebc2523460216f5ed432e5da482615bb7c9e3 Mon Sep 17 00:00:00 2001 From: Eric <43848365+eegli@users.noreply.github.com> Date: Tue, 30 Nov 2021 21:55:40 +0100 Subject: [PATCH 4/4] run formatter --- src/map.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/map.ts b/src/map.ts index 16e4e42b..6cd53f4b 100644 --- a/src/map.ts +++ b/src/map.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { LatLng, LatLngBounds } from './latlng'; +import { LatLng, LatLngBounds } from "./latlng"; -import { MVCObject } from './mvcobject'; +import { MVCObject } from "./mvcobject"; export class Map_ extends MVCObject implements google.maps.Map { controls: Array>;