Skip to content

Commit 32be055

Browse files
authored
feat: InfoWindow mocks (#182)
1 parent f4c6ed9 commit 32be055

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
import { StreetViewService } from "./street-view/service/service";
4545
import { ControlPosition } from "./maps/controls/controlposition";
4646
import { MapTypeId } from "./maps/maps/constants";
47+
import { InfoWindow_ } from "./maps/infowindow/infowindow";
4748
import { event } from "./maps/event/event";
4849
import { mockInstances } from "./registry";
4950

@@ -80,6 +81,7 @@ const initialize = function (): void {
8081
MapCanvasProjection: MapCanvasProjection,
8182
MapPanes: MapPanes,
8283
VisibleRegion: VisibleRegion,
84+
InfoWindow: InfoWindow_,
8385
},
8486
};
8587
};
@@ -105,6 +107,7 @@ export {
105107
StreetViewPanorama,
106108
StreetViewService,
107109
VisibleRegion,
110+
InfoWindow_ as InfoWindow,
108111
mockInstances,
109112
initialize,
110113
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright 2019 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+
import { InfoWindow_ } from "./infowindow";
19+
20+
test("can initialize", () => {
21+
initialize();
22+
expect(new google.maps.InfoWindow()).toBeTruthy();
23+
});
24+
25+
test("mockInstances available", () => {
26+
initialize();
27+
const infowindow = new google.maps.InfoWindow();
28+
expect(InfoWindow_.mockInstances).toMatchObject([infowindow]);
29+
});

src/maps/infowindow/infowindow.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Copyright 2019 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 { LatLng } from "../coordinates/latlng";
18+
import { MVCObject } from "../event/mvcobject";
19+
20+
export class InfoWindow_ extends MVCObject implements google.maps.InfoWindow {
21+
public close = jest.fn().mockImplementation((): void => null);
22+
public getContent = jest
23+
.fn()
24+
.mockImplementation((): string | Element | null | Text | undefined => {
25+
return jest.fn() as unknown as Element;
26+
});
27+
public getPosition = jest
28+
.fn()
29+
.mockImplementation(
30+
(): google.maps.LatLng | null | undefined =>
31+
new LatLng({ lat: 0, lng: 0 })
32+
);
33+
public getZIndex = jest
34+
.fn()
35+
.mockImplementation((): number | null | undefined => 1);
36+
public open = jest
37+
.fn()
38+
.mockImplementation(
39+
(
40+
options?:
41+
| google.maps.InfoWindowOpenOptions
42+
| google.maps.Map
43+
| google.maps.StreetViewPanorama,
44+
anchor?: google.maps.MVCObject
45+
): void => null
46+
);
47+
public setContent = jest
48+
.fn()
49+
.mockImplementation((content?: string | Element | Text): void => null);
50+
public setOptions = jest
51+
.fn()
52+
.mockImplementation(
53+
(options?: google.maps.InfoWindowOptions): void => null
54+
);
55+
public setPosition = jest
56+
.fn()
57+
.mockImplementation(
58+
(position?: google.maps.LatLng | google.maps.LatLngLiteral): void => null
59+
);
60+
public setZIndex = jest
61+
.fn()
62+
.mockImplementation((zIndex?: number): void => null);
63+
constructor(opts?: google.maps.InfoWindowOptions) {
64+
super();
65+
}
66+
}

0 commit comments

Comments
 (0)