diff --git a/src/index.ts b/src/index.ts index 7e0f87990..88964cd9e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,6 +44,7 @@ import { import { StreetViewService } from "./street-view/service/service"; import { ControlPosition } from "./maps/controls/controlposition"; import { MapTypeId } from "./maps/maps/constants"; +import { InfoWindow_ } from "./maps/infowindow/infowindow"; import { event } from "./maps/event/event"; import { mockInstances } from "./registry"; @@ -80,6 +81,7 @@ const initialize = function (): void { MapCanvasProjection: MapCanvasProjection, MapPanes: MapPanes, VisibleRegion: VisibleRegion, + InfoWindow: InfoWindow_, }, }; }; @@ -105,6 +107,7 @@ export { StreetViewPanorama, StreetViewService, VisibleRegion, + InfoWindow_ as InfoWindow, mockInstances, initialize, }; diff --git a/src/maps/infowindow/infowindow.test.ts b/src/maps/infowindow/infowindow.test.ts new file mode 100644 index 000000000..82586ef6d --- /dev/null +++ b/src/maps/infowindow/infowindow.test.ts @@ -0,0 +1,29 @@ +/** + * 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"; +import { InfoWindow_ } from "./infowindow"; + +test("can initialize", () => { + initialize(); + expect(new google.maps.InfoWindow()).toBeTruthy(); +}); + +test("mockInstances available", () => { + initialize(); + const infowindow = new google.maps.InfoWindow(); + expect(InfoWindow_.mockInstances).toMatchObject([infowindow]); +}); diff --git a/src/maps/infowindow/infowindow.ts b/src/maps/infowindow/infowindow.ts new file mode 100644 index 000000000..64b785b28 --- /dev/null +++ b/src/maps/infowindow/infowindow.ts @@ -0,0 +1,66 @@ +/** + * 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 { LatLng } from "../coordinates/latlng"; +import { MVCObject } from "../event/mvcobject"; + +export class InfoWindow_ extends MVCObject implements google.maps.InfoWindow { + public close = jest.fn().mockImplementation((): void => null); + public getContent = jest + .fn() + .mockImplementation((): string | Element | null | Text | undefined => { + return jest.fn() as unknown as Element; + }); + public getPosition = jest + .fn() + .mockImplementation( + (): google.maps.LatLng | null | undefined => + new LatLng({ lat: 0, lng: 0 }) + ); + public getZIndex = jest + .fn() + .mockImplementation((): number | null | undefined => 1); + public open = jest + .fn() + .mockImplementation( + ( + options?: + | google.maps.InfoWindowOpenOptions + | google.maps.Map + | google.maps.StreetViewPanorama, + anchor?: google.maps.MVCObject + ): void => null + ); + public setContent = jest + .fn() + .mockImplementation((content?: string | Element | Text): void => null); + public setOptions = jest + .fn() + .mockImplementation( + (options?: google.maps.InfoWindowOptions): void => null + ); + public setPosition = jest + .fn() + .mockImplementation( + (position?: google.maps.LatLng | google.maps.LatLngLiteral): void => null + ); + public setZIndex = jest + .fn() + .mockImplementation((zIndex?: number): void => null); + constructor(opts?: google.maps.InfoWindowOptions) { + super(); + } +}