Skip to content

Commit db5c67f

Browse files
authored
feat: add advanced marker view (#407)
* feat: add mocks for advanced marker view * feat: add mocks for pin view
1 parent 5f46f64 commit db5c67f

File tree

5 files changed

+188
-0
lines changed

5 files changed

+188
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 { AdvancedMarkerView, initialize } from "../../index";
18+
import { mockInstances } from "../../registry";
19+
20+
beforeEach(() => {
21+
initialize();
22+
});
23+
24+
test("advanced marker can initialize", async () => {
25+
const marker = new google.maps.marker.AdvancedMarkerView(null);
26+
expect(marker).toBeTruthy();
27+
});
28+
29+
test("registers mocks", () => {
30+
const advancedMarkerView = new google.maps.marker.AdvancedMarkerView(null);
31+
32+
advancedMarkerView.position = { lat: 0, lng: 0 };
33+
advancedMarkerView.title = "Howdy";
34+
35+
expect(mockInstances.get(AdvancedMarkerView)).toHaveLength(1);
36+
37+
expect(mockInstances.get(AdvancedMarkerView)[0].position).toEqual({
38+
lat: 0,
39+
lng: 0,
40+
});
41+
42+
expect(mockInstances.get(AdvancedMarkerView)[0].title).toBe("Howdy");
43+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
/* eslint-disable @typescript-eslint/no-unused-vars */
18+
19+
import { MapsEventListener } from "../../maps/event/event";
20+
import { __registerMockInstance } from "../../registry";
21+
22+
export class AdvancedMarkerView
23+
implements google.maps.marker.AdvancedMarkerView
24+
{
25+
public collisionBehavior?: google.maps.CollisionBehavior;
26+
public content?: Element;
27+
public draggable?: boolean;
28+
public element?: HTMLElement | SVGElement;
29+
public map?: google.maps.Map;
30+
public position?:
31+
| google.maps.LatLng
32+
| google.maps.LatLngLiteral
33+
| google.maps.LatLngAltitudeLiteral;
34+
public title?: string;
35+
public zIndex?: number;
36+
37+
public addListener = jest
38+
.fn()
39+
.mockImplementation(
40+
(
41+
eventName: string,
42+
handler: (
43+
this: AdvancedMarkerView,
44+
event: google.maps.MapMouseEvent
45+
) => void
46+
): google.maps.MapsEventListener => MapsEventListener
47+
);
48+
49+
constructor(options?: google.maps.marker.AdvancedMarkerViewOptions) {
50+
__registerMockInstance(this.constructor, this);
51+
}
52+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 { PinView, initialize, mockInstances } from "../../index";
18+
19+
beforeEach(() => {
20+
initialize();
21+
});
22+
23+
test("pin view is mocked", async () => {
24+
const pinView = new google.maps.marker.PinView();
25+
26+
expect(pinView).toBeTruthy();
27+
});
28+
29+
test("registers mocks", () => {
30+
const pinView = new google.maps.marker.PinView();
31+
32+
pinView.background = "red";
33+
pinView.borderColor = "blue";
34+
pinView.scale = 2;
35+
36+
const mocks = mockInstances.get(PinView);
37+
38+
expect(mocks).toHaveLength(1);
39+
40+
expect(mockInstances.get(PinView)[0].background).toBe("red");
41+
expect(mockInstances.get(PinView)[0].borderColor).toBe("blue");
42+
expect(mockInstances.get(PinView)[0].scale).toBe(2);
43+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
/* eslint-disable @typescript-eslint/no-unused-vars */
18+
19+
import { MapsEventListener } from "../../maps/event/event";
20+
import { __registerMockInstance } from "../../registry";
21+
22+
export class PinView implements google.maps.marker.PinView {
23+
public background?: string;
24+
public borderColor?: string;
25+
public element?: HTMLElement | SVGElement;
26+
public glyph?: string | Element | URL;
27+
public glyphColor?: string;
28+
public scale?: number;
29+
30+
public addListener = jest
31+
.fn()
32+
.mockImplementation(
33+
(
34+
eventName: string,
35+
handler: (this: PinView, event: MouseEvent) => void
36+
): google.maps.MapsEventListener => MapsEventListener
37+
);
38+
39+
constructor(options?: google.maps.marker.PinViewOptions) {
40+
__registerMockInstance(this.constructor, this);
41+
}
42+
}

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import { StreetViewService } from "./street-view/service/service";
5555
import { ControlPosition } from "./maps/controls/controlposition";
5656
import { MapTypeId } from "./maps/maps/constants";
5757
import { InfoWindow_ } from "./maps/infowindow/infowindow";
58+
import { AdvancedMarkerView } from "./drawing/advanced-marker-view/advanced-marker-view";
59+
import { PinView } from "./drawing/advanced-marker-view/pin-view";
5860
import { FeatureLayer } from "./maps/maps/featurelayer";
5961
import { event } from "./maps/event/event";
6062
import { mockInstances } from "./registry";
@@ -103,6 +105,10 @@ const initialize = function (): void {
103105
MaxZoomService,
104106
DirectionsService,
105107
DistanceMatrixService,
108+
marker: {
109+
PinView,
110+
AdvancedMarkerView,
111+
},
106112
FeatureLayer,
107113
},
108114
};
@@ -143,6 +149,8 @@ export {
143149
MaxZoomService,
144150
DirectionsService,
145151
DistanceMatrixService,
152+
AdvancedMarkerView,
153+
PinView,
146154
FeatureLayer,
147155
mockInstances,
148156
initialize,

0 commit comments

Comments
 (0)