Skip to content
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
43 changes: 43 additions & 0 deletions src/drawing/advanced-marker-view/advanced-marker-view.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2022 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 { AdvancedMarkerView, initialize } from "../../index";
import { mockInstances } from "../../registry";

beforeEach(() => {
initialize();
});

test("advanced marker can initialize", async () => {
const marker = new google.maps.marker.AdvancedMarkerView(null);
expect(marker).toBeTruthy();
});

test("registers mocks", () => {
const advancedMarkerView = new google.maps.marker.AdvancedMarkerView(null);

advancedMarkerView.position = { lat: 0, lng: 0 };
advancedMarkerView.title = "Howdy";

expect(mockInstances.get(AdvancedMarkerView)).toHaveLength(1);

expect(mockInstances.get(AdvancedMarkerView)[0].position).toEqual({
lat: 0,
lng: 0,
});

expect(mockInstances.get(AdvancedMarkerView)[0].title).toBe("Howdy");
});
52 changes: 52 additions & 0 deletions src/drawing/advanced-marker-view/advanced-marker-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2022 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.
*/

/* eslint-disable @typescript-eslint/no-unused-vars */

import { MapsEventListener } from "../../maps/event/event";
import { __registerMockInstance } from "../../registry";

export class AdvancedMarkerView
implements google.maps.marker.AdvancedMarkerView
{
public collisionBehavior?: google.maps.CollisionBehavior;
public content?: Element;
public draggable?: boolean;
public element?: HTMLElement | SVGElement;
public map?: google.maps.Map;
public position?:
| google.maps.LatLng
| google.maps.LatLngLiteral
| google.maps.LatLngAltitudeLiteral;
public title?: string;
public zIndex?: number;

public addListener = jest
.fn()
.mockImplementation(
(
eventName: string,
handler: (
this: AdvancedMarkerView,
event: google.maps.MapMouseEvent
) => void
): google.maps.MapsEventListener => MapsEventListener
);

constructor(options?: google.maps.marker.AdvancedMarkerViewOptions) {
__registerMockInstance(this.constructor, this);
}
}
43 changes: 43 additions & 0 deletions src/drawing/advanced-marker-view/pin-view.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2022 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 { PinView, initialize, mockInstances } from "../../index";

beforeEach(() => {
initialize();
});

test("pin view is mocked", async () => {
const pinView = new google.maps.marker.PinView();

expect(pinView).toBeTruthy();
});

test("registers mocks", () => {
const pinView = new google.maps.marker.PinView();

pinView.background = "red";
pinView.borderColor = "blue";
pinView.scale = 2;

const mocks = mockInstances.get(PinView);

expect(mocks).toHaveLength(1);

expect(mockInstances.get(PinView)[0].background).toBe("red");
expect(mockInstances.get(PinView)[0].borderColor).toBe("blue");
expect(mockInstances.get(PinView)[0].scale).toBe(2);
});
42 changes: 42 additions & 0 deletions src/drawing/advanced-marker-view/pin-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright 2022 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.
*/

/* eslint-disable @typescript-eslint/no-unused-vars */

import { MapsEventListener } from "../../maps/event/event";
import { __registerMockInstance } from "../../registry";

export class PinView implements google.maps.marker.PinView {
public background?: string;
public borderColor?: string;
public element?: HTMLElement | SVGElement;
public glyph?: string | Element | URL;
public glyphColor?: string;
public scale?: number;

public addListener = jest
.fn()
.mockImplementation(
(
eventName: string,
handler: (this: PinView, event: MouseEvent) => void
): google.maps.MapsEventListener => MapsEventListener
);

constructor(options?: google.maps.marker.PinViewOptions) {
__registerMockInstance(this.constructor, this);
}
}
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ 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 { AdvancedMarkerView } from "./drawing/advanced-marker-view/advanced-marker-view";
import { PinView } from "./drawing/advanced-marker-view/pin-view";
import { FeatureLayer } from "./maps/maps/featurelayer";
import { event } from "./maps/event/event";
import { mockInstances } from "./registry";
Expand Down Expand Up @@ -103,6 +105,10 @@ const initialize = function (): void {
MaxZoomService,
DirectionsService,
DistanceMatrixService,
marker: {
PinView,
AdvancedMarkerView,
},
FeatureLayer,
},
};
Expand Down Expand Up @@ -143,6 +149,8 @@ export {
MaxZoomService,
DirectionsService,
DistanceMatrixService,
AdvancedMarkerView,
PinView,
FeatureLayer,
mockInstances,
initialize,
Expand Down