UNPKG

@googlemaps/jest-mocks

Version:

[![npm](https://img.shields.io/npm/v/@googlemaps/jest-mocks)][npm-pkg] ![Release](https://github.com/googlemaps/js-jest-mocks/workflows/Release/badge.svg) ![Stable](https://img.shields.io/badge/stability-stable-green) [![Tests/Build](https://github.com/go

1,409 lines (1,373 loc) 72.9 kB
'use strict'; /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; const importLibrary = jest.fn((name) => __awaiter(void 0, void 0, void 0, function* () { switch (name) { case "core": { const { ControlPosition, event, LatLng, LatLngAltitude, LatLngBounds, MapsNetworkError, MapsNetworkErrorEndpoint, MapsRequestError, MapsServerError, MVCArray, MVCObject, Point, Settings, Size, SymbolPath, UnitSystem, } = google.maps; return { ControlPosition, event, LatLng, LatLngAltitude, LatLngBounds, MapsNetworkError, MapsNetworkErrorEndpoint, MapsRequestError, MapsServerError, MVCArray, MVCObject, Point, Settings, Size, SymbolPath, UnitSystem, }; } case "maps": { const { BicyclingLayer, Circle, Data, FeatureType, GroundOverlay, ImageMapType, InfoWindow, KmlLayer, KmlLayerStatus, Map, MapTypeControlStyle, MapTypeId, MapTypeRegistry, MaxZoomService, MaxZoomStatus, OverlayView, Polygon, Polyline, Rectangle, RenderingType, StrokePosition, StyledMapType, TrafficLayer, TransitLayer, WebGLOverlayView, } = google.maps; return { BicyclingLayer, Circle, Data, FeatureType, GroundOverlay, ImageMapType, InfoWindow, KmlLayer, KmlLayerStatus, Map, MapTypeControlStyle, MapTypeId, MapTypeRegistry, MaxZoomService, MaxZoomStatus, OverlayView, Polygon, Polyline, Rectangle, RenderingType, StrokePosition, StyledMapType, TrafficLayer, TransitLayer, WebGLOverlayView, }; } case "places": return google.maps.places; case "geocoding": { const { Geocoder, GeocoderLocationType, GeocoderStatus } = google.maps; return { Geocoder, GeocoderLocationType, GeocoderStatus, }; } case "routes": { const { DirectionsRenderer, DirectionsService, DirectionsStatus, DistanceMatrixElementStatus, DistanceMatrixService, DistanceMatrixStatus, TrafficModel, TransitMode, TransitRoutePreference, TravelMode, VehicleType, } = google.maps; return { DirectionsRenderer, DirectionsService, DirectionsStatus, DistanceMatrixElementStatus, DistanceMatrixService, DistanceMatrixStatus, TrafficModel, TransitMode, TransitRoutePreference, TravelMode, VehicleType, }; } case "marker": { const { Animation, CollisionBehavior, Marker, marker: { AdvancedMarkerClickEvent, AdvancedMarkerElement, PinElement }, } = google.maps; return { AdvancedMarkerClickEvent, AdvancedMarkerElement, Animation, CollisionBehavior, Marker, PinElement, }; } case "geometry": { return google.maps.geometry; } case "elevation": { const { ElevationService, ElevationStatus } = google.maps; return { ElevationService, ElevationStatus, }; } case "streetView": { const { InfoWindow, OverlayView, StreetViewCoverageLayer, StreetViewPanorama, StreetViewPreference, StreetViewService, StreetViewSource, StreetViewStatus, } = google.maps; return { InfoWindow, OverlayView, StreetViewCoverageLayer, StreetViewPanorama, StreetViewPreference, StreetViewService, StreetViewSource, StreetViewStatus, }; } case "journeySharing": { return google.maps.journeySharing; } case "drawing": { return google.maps.drawing; } case "visualization": { return google.maps.visualization; } } throw new TypeError(`unknown library name: ${name}`); })); /** * 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. */ class LatLng { constructor(a, b, c) { this.equals = jest .fn() .mockImplementation((other) => false); this.lat = jest.fn().mockImplementation(() => 0); this.lng = jest.fn().mockImplementation(() => 0); this.toString = jest.fn().mockImplementation(() => ""); this.toUrlValue = jest .fn() .mockImplementation((precision) => ""); this.toJSON = jest .fn() .mockImplementation(() => { return { lat: 0, lng: 0 }; }); } } class LatLngBounds { constructor(sw, ne) { this.contains = jest .fn() .mockImplementation((latLng) => false); this.equals = jest .fn() .mockImplementation((other) => false); this.extend = jest .fn() .mockImplementation((point) => this); this.getCenter = jest .fn() .mockImplementation(() => new google.maps.LatLng({ lat: 0, lng: 0 })); this.getNorthEast = jest .fn() .mockImplementation(() => new google.maps.LatLng({ lat: 0, lng: 0 })); this.getSouthWest = jest .fn() .mockImplementation(() => new google.maps.LatLng({ lat: 0, lng: 0 })); this.intersects = jest .fn() .mockImplementation((other) => false); this.isEmpty = jest.fn().mockImplementation(() => false); this.toJSON = jest .fn() .mockImplementation(() => { return { east: 0, north: 0, south: 0, west: 0 }; }); this.toSpan = jest .fn() .mockImplementation(() => new google.maps.LatLng({ lat: 0, lng: 0 })); this.toString = jest.fn().mockImplementation(() => ""); this.toUrlValue = jest .fn() .mockImplementation((precision) => ""); this.union = jest .fn() .mockImplementation((other) => this); } } /** * 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. */ class LatLngAltitude { constructor(value, noClampNoWrap) { this.lat = 0; this.lng = 0; this.altitude = 0; this.equals = jest .fn() .mockImplementation((other) => false); this.toJSON = jest .fn() .mockImplementation(() => { return { lat: 0, lng: 0, altitude: 0 }; }); } } /** * 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-explicit-any */ const MOCKS_REGISTRY = new Map(); function get(item) { return MOCKS_REGISTRY.get(item.name) || []; } function clearAll() { MOCKS_REGISTRY.clear(); } // Signature to require at least one item function clear(item, ...rest) { for (const ctr of [item, ...rest]) { MOCKS_REGISTRY.delete(ctr.name); } } const mockInstances = { get, clear, clearAll, }; /* Internal */ function __registerMockInstance(ctr, instance) { const existing = MOCKS_REGISTRY.get(ctr.name) || []; MOCKS_REGISTRY.set(ctr.name, [...existing, instance]); } /** * 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-empty-function */ /* eslint-disable @typescript-eslint/no-unused-vars */ class PlacesService { constructor(attrContainer) { this.findPlaceFromPhoneNumber = jest.fn().mockImplementation((request, callback) => { }); this.findPlaceFromQuery = jest.fn().mockImplementation((request, callback) => { }); this.getDetails = jest.fn().mockImplementation((request, callback) => { }); this.nearbySearch = jest.fn().mockImplementation((request, callback) => { }); this.textSearch = jest.fn().mockImplementation((request, callback) => { }); __registerMockInstance(this.constructor, this); } } /** * 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 */ class DirectionsService { constructor() { this.route = jest.fn().mockImplementation((request, callback) => Promise.resolve({ request, routes: [], available_travel_modes: [], geocoded_waypoints: [], })); __registerMockInstance(this.constructor, this); } } /** * 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. */ class Geocoder { constructor() { this.geocode = jest.fn().mockImplementation((request, callback) => Promise.resolve({ results: [], })); __registerMockInstance(this.constructor, this); } } /** * 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. */ const MapsEventListener = { remove: jest.fn(), }; class event { } event.addDomListener = jest.fn(() => MapsEventListener); event.addDomListenerOnce = jest.fn(() => MapsEventListener); event.addListener = jest.fn(() => MapsEventListener); event.addListenerOnce = jest.fn(() => MapsEventListener); event.clearInstanceListeners = jest.fn(() => null); event.clearListeners = jest.fn(() => null); event.hasListeners = jest.fn(() => false); event.removeListener = jest.fn(() => null); event.trigger = jest.fn(() => null); /** * 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-explicit-any */ class MVCObject { constructor() { this.addListener = jest .fn() .mockImplementation((eventName, handler) => MapsEventListener); this.bindTo = jest .fn() .mockImplementation((key, target, targetKey, noNotify) => null); this.changed = jest.fn().mockImplementation((key) => null); this.get = jest.fn().mockImplementation((key) => { }); this.notify = jest.fn().mockImplementation((key) => null); this.set = jest .fn() .mockImplementation((key, value) => null); this.setValues = jest.fn().mockImplementation((values) => null); this.unbind = jest.fn().mockImplementation((key) => null); this.unbindAll = jest.fn().mockImplementation(() => null); const ctor = this.constructor; __registerMockInstance(ctor, this); if (ctor.mockInstances === undefined) { ctor.mockInstances = []; } if (MVCObject._mockClasses === undefined) { MVCObject._mockClasses = []; } ctor.mockInstances.push(this); MVCObject._mockClasses.push(ctor); } } MVCObject._mockClasses = []; MVCObject.mockInstances = []; // if running a test that supports afterEach, then we will cleanup the instances // automatically at the end of each test. if (typeof afterEach === "function") { afterEach(() => { if (MVCObject._mockClasses) { for (const ctor of MVCObject._mockClasses) { ctor.mockInstances = undefined; } } MVCObject._mockClasses = undefined; }); } /** * 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. */ class Autocomplete extends MVCObject { constructor(inputField, opts) { super(); this.getBounds = jest .fn() .mockImplementation(() => null); this.getFields = jest.fn().mockImplementation(() => []); this.getPlace = jest .fn() .mockImplementation(() => ({ name: "" })); this.setBounds = jest .fn() .mockImplementation((bounds) => { }); this.setComponentRestrictions = jest .fn() .mockImplementation((restrictions) => { }); this.setFields = jest .fn() .mockImplementation((fields) => { }); this.setOptions = jest .fn() .mockImplementation((options) => { }); this.setTypes = jest.fn().mockImplementation((types) => { }); } } /** * 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 */ class MaxZoomService { constructor() { this.getMaxZoomAtLatLng = jest.fn().mockImplementation((latLng, callback) => // @ts-expect-error Promise.resolve({ zoom: 0, })); __registerMockInstance(this.constructor, this); } } /** * 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-empty-function */ /* eslint-disable @typescript-eslint/no-unused-vars */ class AutocompleteService { constructor() { this.getPlacePredictions = jest.fn().mockImplementation((request, callback) => Promise.resolve({ predictions: [], })); this.getQueryPredictions = jest .fn() .mockImplementation((request, callback) => { }); __registerMockInstance(this.constructor, this); } } /** * Copyright 2023 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. */ class AutocompleteSessionToken { constructor() { __registerMockInstance(this.constructor, this); } } /** * 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 */ class DistanceMatrixService { constructor() { this.getDistanceMatrix = jest.fn().mockImplementation((request, callback) => Promise.resolve({ destinationAddresses: [], originAddresses: [], rows: [], })); __registerMockInstance(this.constructor, this); } } /** * 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 */ class ElevationService { constructor() { this.getElevationAlongPath = jest.fn().mockImplementation((request, callback) => Promise.resolve({ results: [], })); this.getElevationForLocations = jest.fn().mockImplementation((request, callback) => Promise.resolve({ results: [], })); __registerMockInstance(this.constructor, this); } } /** * 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. */ class StreetViewPanorama extends MVCObject { constructor() { super(...arguments); this.focus = jest.fn().mockImplementation(() => { }); this.controls = []; this.getLinks = jest .fn() .mockImplementation(() => null); this.getLocation = jest .fn() .mockImplementation(() => ({ description: null, latLng: new LatLng(1, 1), pano: "pano", shortDescription: null, })); this.getMotionTracking = jest.fn().mockImplementation(() => false); this.getPano = jest.fn().mockImplementation(() => "pano"); this.getPhotographerPov = jest .fn() .mockImplementation(() => ({ heading: 0, pitch: 0 })); this.getPosition = jest .fn() .mockImplementation(() => new LatLng(1, 1)); this.getPov = jest .fn() .mockImplementation(() => ({ heading: 0, pitch: 0 })); this.getStatus = jest .fn() .mockImplementation(() => google.maps.StreetViewStatus.OK); this.getVisible = jest.fn().mockImplementation(() => true); this.getZoom = jest.fn().mockImplementation(() => 0); this.registerPanoProvider = jest .fn() .mockImplementation((provider, opt_options) => null); this.setLinks = jest .fn() .mockImplementation((inks) => null); this.setMotionTracking = jest .fn() .mockImplementation((motionTracking) => null); this.setOptions = jest .fn() .mockImplementation((options) => null); this.setPano = jest.fn().mockImplementation((pano) => null); this.setPosition = jest .fn() .mockImplementation((latLng) => null); this.setPov = jest .fn() .mockImplementation((pov) => null); this.setVisible = jest .fn() .mockImplementation((flag) => null); this.setZoom = jest.fn().mockImplementation((zoom) => null); } } class FeatureLayer { constructor() { this.featureType = google.maps.FeatureType.ADMINISTRATIVE_AREA_LEVEL_1; this.isAvailable = false; this.style = null; this.addListener = jest.fn((eventName, handler) => MapsEventListener); } } /** * 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. */ const ControlPosition = { TOP_LEFT: 1, TOP_CENTER: 2, TOP: 2, TOP_RIGHT: 3, LEFT_CENTER: 4, LEFT_TOP: 5, LEFT: 5, LEFT_BOTTOM: 6, RIGHT_TOP: 7, RIGHT: 7, RIGHT_CENTER: 8, RIGHT_BOTTOM: 9, BOTTOM_LEFT: 10, BOTTOM_CENTER: 11, BOTTOM: 11, BOTTOM_RIGHT: 12, CENTER: 13, BLOCK_START_INLINE_START: 14, BLOCK_START_INLINE_CENTER: 15, BLOCK_START_INLINE_END: 16, INLINE_START_BLOCK_CENTER: 17, INLINE_START_BLOCK_START: 18, INLINE_START_BLOCK_END: 19, INLINE_END_BLOCK_START: 20, INLINE_END_BLOCK_CENTER: 21, INLINE_END_BLOCK_END: 22, BLOCK_END_INLINE_START: 23, BLOCK_END_INLINE_CENTER: 24, BLOCK_END_INLINE_END: 25, }; /** * 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. */ class Map_ extends MVCObject { constructor(mapDiv, opts) { super(); this.getDatasetFeatureLayer = jest.fn((datasetId) => new FeatureLayer()); this.getFeatureLayer = jest.fn((featureType) => new FeatureLayer()); this.getMapCapabilities = jest.fn(() => { return { isAdvancedMarkersAvailable: false, isDataDrivenStylingAvailable: false, }; }); this.fitBounds = jest .fn() .mockImplementation((bounds, padding) => { return null; }); this.getBounds = jest.fn().mockImplementation(() => new LatLngBounds()); this.getCenter = jest .fn() .mockImplementation(() => new LatLng({ lat: 0, lng: 0 })); this.getClickableIcons = jest.fn().mockImplementation(() => false); this.getDiv = jest.fn().mockImplementation(() => { return jest.fn(); }); this.getHeading = jest.fn().mockImplementation(() => 0); this.getHeadingInteractionEnabled = jest .fn() .mockImplementation(() => null); this.getMapTypeId = jest .fn() .mockImplementation(() => google.maps.MapTypeId.ROADMAP); this.getProjection = jest .fn() .mockImplementation(() => jest.fn()); this.getRenderingType = jest .fn() .mockImplementation(() => google.maps.RenderingType.RASTER); this.getStreetView = jest .fn() .mockImplementation(() => new StreetViewPanorama()); this.getTilt = jest.fn().mockImplementation(() => 0); this.getTiltInteractionEnabled = jest .fn() .mockImplementation(() => null); this.getZoom = jest.fn().mockImplementation(() => 0); this.moveCamera = jest .fn() .mockImplementation((cameraOptions) => { return null; }); this.panBy = jest.fn().mockImplementation((x, y) => { return null; }); this.panTo = jest .fn() .mockImplementation((latLng) => { return null; }); this.panToBounds = jest .fn() .mockImplementation((latLngBounds, padding) => { return null; }); this.setCenter = jest .fn() .mockImplementation((latlng) => { return null; }); this.setHeading = jest.fn().mockImplementation((heading) => { return null; }); this.setHeadingInteractionEnabled = jest .fn() .mockImplementation((headingInteractionEnabled) => { }); this.setMapTypeId = jest .fn() .mockImplementation((mapTypeId) => { return null; }); this.setOptions = jest .fn() .mockImplementation((options) => { return null; }); this.setRenderingType = jest .fn() .mockImplementation((renderingType) => { }); this.setStreetView = jest .fn() .mockImplementation((panorama) => { return null; }); this.setTilt = jest.fn().mockImplementation((tilt) => { return null; }); this.setTiltInteractionEnabled = jest .fn() .mockImplementation((tiltInteractionEnabled) => { }); this.setZoom = jest.fn().mockImplementation((zoom) => { return null; }); this.setClickableIcons = jest .fn() .mockImplementation((clickable) => { return null; }); this.data = new google.maps.Data(); this.controls = []; for (const [_, value] of Object.entries(ControlPosition)) { this.controls[value] = new google.maps.MVCArray(); } this.mapTypes = new google.maps.MVCObject(); this.overlayMapTypes = new google.maps.MVCArray(); } } /** * 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. */ class Circle extends MVCObject { constructor(opt) { super(); this.getBounds = jest .fn() .mockImplementation(() => null); this.getCenter = jest .fn() .mockImplementation(() => new LatLng({ lat: 0, lng: 0 })); this.getDraggable = jest.fn().mockImplementation(() => true); this.getEditable = jest.fn().mockImplementation(() => true); this.getMap = jest .fn() .mockImplementation(() => new Map_(null)); this.getRadius = jest.fn().mockImplementation(() => 0); this.getVisible = jest.fn().mockImplementation(() => true); this.setCenter = jest .fn() .mockImplementation((center) => { }); this.setDraggable = jest .fn() .mockImplementation((draggable) => { }); this.setEditable = jest.fn().mockImplementation((editable) => { }); this.setMap = jest.fn().mockImplementation((map) => { }); this.setOptions = jest .fn() .mockImplementation((options) => { }); this.setRadius = jest.fn().mockImplementation((radius) => { }); this.setVisible = jest.fn().mockImplementation((visible) => { }); } } /** * 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. */ class Feature extends MVCObject { constructor(options) { super(); this.forEachProperty = jest .fn() .mockImplementation((callback) => { return null; }); this.getGeometry = jest .fn() .mockImplementation(() => { return null; }); this.getId = jest .fn() .mockImplementation(() => { return "1"; }); this.getProperty = jest.fn().mockImplementation((name) => { return undefined; }); this.removeProperty = jest.fn().mockImplementation((name) => { return null; }); this.setGeometry = jest .fn() .mockImplementation((newGeometry) => { return null; }); this.setProperty = jest .fn() .mockImplementation((name, newValue) => { return null; }); this.toGeoJson = jest .fn() .mockImplementation((callback) => { return null; }); } } /** * 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. */ class DataPolygon extends MVCObject { constructor(elements) { super(); this.forEachLatLng = jest .fn() .mockImplementation((callback) => { return null; }); this.getArray = jest .fn() .mockImplementation(() => []); this.getAt = jest .fn() .mockImplementation(() => null); this.getLength = jest.fn().mockImplementation(() => 0); this.getType = jest.fn().mockImplementation(() => "MultiPolygon"); } } /** * 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. */ class Data extends MVCObject { constructor(opt) { super(); this.add = jest .fn() .mockImplementation((feature) => { return null; }); this.addGeoJson = jest .fn() .mockImplementation((geoJson, options) => { return []; }); this.contains = jest .fn() .mockImplementation((feature) => { return false; }); this.forEach = jest .fn() .mockImplementation((callback) => { return null; }); this.getControlPosition = jest .fn() .mockImplementation(() => { return ControlPosition.BOTTOM_CENTER; }); this.getControls = jest.fn().mockImplementation(() => { return null; }); this.getDrawingMode = jest.fn().mockImplementation(() => { return null; }); this.getFeatureById = jest .fn() .mockImplementation((id) => { return undefined; }); this.getMap = jest.fn().mockImplementation(() => { return null; }); this.getStyle = jest .fn() .mockImplementation(() => { return null; }); this.loadGeoJson = jest .fn() .mockImplementation((url, options, callback) => { return null; }); this.overrideStyle = jest .fn() .mockImplementation((feature, style) => { return null; }); this.remove = jest .fn() .mockImplementation((feature) => { return null; }); this.revertStyle = jest .fn() .mockImplementation((feature) => { return null; }); this.setControlPosition = jest .fn() .mockImplementation((controlPosition) => { return null; }); this.setControls = jest .fn() .mockImplementation((controls) => { return null; }); this.setDrawingMode = jest .fn() .mockImplementation((drawingMode) => { return null; }); this.setMap = jest .fn() .mockImplementation((map) => { return null; }); this.setStyle = jest .fn() .mockImplementation((style) => { return null; }); this.toGeoJson = jest .fn() .mockImplementation((callback) => { return null; }); } } Data.Feature = jest .fn() .mockImplementation((options) => new Feature(options)); Data.Polygon = jest .fn() .mockImplementation((elements) => new DataPolygon(elements)); /** * 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. */ class MVCArray extends MVCObject { constructor(array) { super(); this.clear = jest.fn().mockImplementation(() => { }); this.forEach = jest .fn() .mockImplementation((callback) => { }); this.getArray = jest.fn().mockImplementation(() => []); this.getAt = jest.fn().mockImplementation((i) => ({})); this.getLength = jest.fn().mockImplementation(() => 0); this.insertAt = jest .fn() .mockImplementation((i, elem) => { }); this.pop = jest.fn().mockImplementation(() => ({})); this.push = jest.fn().mockImplementation((elem) => 0); this.removeAt = jest.fn().mockImplementation((i) => ({})); this.setAt = jest.fn().mockImplementation((i, elem) => { }); } } /** * 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. */ class Point { constructor(x, y) { this.toString = jest.fn().mockImplementation(() => { return ""; }); this.x = x; this.y = y; } equals(other) { return other.x === this.x && other.y === this.y; } } /** * 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. */ class VisibleRegion extends MVCObject { } /** * 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. */ class MapCanvasProjection extends MVCObject { constructor() { super(...arguments); this.fromContainerPixelToLatLng = jest .fn() .mockImplementation((pixel, nowrap) => new LatLng(0, 0)); this.fromDivPixelToLatLng = jest .fn() .mockImplementation((pixel, nowrap) => new LatLng(0, 0)); this.fromLatLngToContainerPixel = jest .fn() .mockImplementation((latLng) => new Point(0, 0)); this.fromLatLngToDivPixel = jest .fn() .mockImplementation((latLng) => new Point(0, 0)); this.getVisibleRegion = jest .fn() .mockImplementation(() => new VisibleRegion()); this.getWorldWidth = jest.fn().mockImplementation(() => 0); } } /** * 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. */ class MapPanes { } /** * 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. */ class Marker extends MVCObject { constructor(opts) { super(); this.getAnimation = jest .fn() .mockImplementation(() => null); this.getClickable = jest.fn().mockImplementation(() => null); this.getCursor = jest .fn() .mockImplementation(() => null); this.getDraggable = jest .fn() .mockImplementation(() => null); this.getIcon = jest .fn() .mockImplementation(() => null); this.getLabel = jest .fn() .mockImplementation(() => null); this.getMap = jest .fn() .mockImplementation(() => null); this.getOpacity = jest .fn() .mockImplementation(() => null); this.getPosition = jest .fn() .mockImplementation(() => new LatLng({ lat: 0, lng: 0 })); this.getShape = jest .fn() .mockImplementation(() => null); this.getTitle = jest .fn() .mockImplementation(() => null); this.getVisible = jest.fn().mockImplementation(() => null); this.getZIndex = jest .fn() .mockImplementation(() => null); this.setAnimation = jest .fn() .mockImplementation((animation) => { }); this.setClickable = jest .fn() .mockImplementation((flag) => { }); this.setCursor = jest .fn() .mockImplementation((cursor) => { }); this.setDraggable = jest .fn() .mockImplementation((flag) => { }); this.setIcon = jest .fn() .mockImplementation((icon) => { }); this.setLabel = jest .fn() .mockImplementation((label) => { }); this.setMap = jest .fn() .mockImplementation((map) => { }); this.setOpacity = jest .fn() .mockImplementation((opacity) => { }); this.setOptions = jest .fn() .mockImplementation((options) => { }); this.setPosition = jest .fn() .mockImplementation((latlng) => { }); this.setShape = jest .fn() .mockImplementation((shape) => { }); this.setTitle = jest .fn() .mockImplementation((title) => { }); this.setVisible = jest .fn() .mockImplementation((visible) => { }); this.setZIndex = jest .fn() .mockImplementation((zIndex) => { }); this.addListener = jest .fn() .mockImplementation((eventName, handler) => MapsEventListener); } } /** * Copyright 2022 Google LLC. All Rights Reserved. * * Licensed under the Apach