From 522810b3082ae8b107576a9c21544992aa24f2e5 Mon Sep 17 00:00:00 2001 From: Michael Reinhard Date: Thu, 20 Jul 2023 16:09:39 -0700 Subject: [PATCH] internal PiperOrigin-RevId: 549768635 --- src/testing/fake_gmp_components.ts | 2 -- src/testing/fake_lat_lng.ts | 4 ++-- src/testing/fake_route.ts | 29 ++++++++++++++++++++++++++--- src/utils/place_utils.ts | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/testing/fake_gmp_components.ts b/src/testing/fake_gmp_components.ts index 249bbbc..8cb2bc6 100644 --- a/src/testing/fake_gmp_components.ts +++ b/src/testing/fake_gmp_components.ts @@ -19,7 +19,6 @@ */ import {LitElement} from 'lit'; -import {customElement} from 'lit/decorators.js'; declare global { interface HTMLElementTagNameMap { @@ -27,7 +26,6 @@ declare global { } } -@customElement('gmp-map') export class FakeMapElement extends LitElement { readonly innerMap = {} as google.maps.Map; } diff --git a/src/testing/fake_lat_lng.ts b/src/testing/fake_lat_lng.ts index 8b3750a..2097b25 100644 --- a/src/testing/fake_lat_lng.ts +++ b/src/testing/fake_lat_lng.ts @@ -15,8 +15,8 @@ type LatLngBoundsLiteral = google.maps.LatLngBoundsLiteral; */ export class FakeLatLng implements LatLng { constructor( - private readonly latitude: number, - private readonly longitude: number, + private readonly latitude = 0, + private readonly longitude = 0, ) {} lat(): number { diff --git a/src/testing/fake_route.ts b/src/testing/fake_route.ts index 1f18206..5bf9d8e 100644 --- a/src/testing/fake_route.ts +++ b/src/testing/fake_route.ts @@ -4,9 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -import {FakeLatLngBounds} from './fake_lat_lng.js'; +import {FakeLatLng, FakeLatLngBounds} from './fake_lat_lng.js'; type DirectionsRoute = google.maps.DirectionsRoute; +type DirectionsLeg = google.maps.DirectionsLeg; const EMPTY_FAKE_ROUTE: DirectionsRoute = { bounds: new FakeLatLngBounds(), @@ -19,6 +20,16 @@ const EMPTY_FAKE_ROUTE: DirectionsRoute = { waypoint_order: [], }; +const EMPTY_FAKE_LEG: DirectionsLeg = { + end_address: '', + end_location: new FakeLatLng(), + start_address: '', + start_location: new FakeLatLng(), + steps: [], + traffic_speed_entry: [], + via_waypoints: [], +}; + /** * Makes a fake `google.maps.DirectionsRoute` object for testing purposes. * @@ -28,5 +39,17 @@ const EMPTY_FAKE_ROUTE: DirectionsRoute = { */ export function makeFakeRoute(fields: Partial = {}): DirectionsRoute { - return {...EMPTY_FAKE_ROUTE, ...fields}; -} + return {...EMPTY_FAKE_ROUTE, ...fields}; + } + +/** + * Makes a fake `google.maps.DirectionsLeg` object for testing purposes. + * + * @param fields - An object of fields of the `DirectionsLeg`. Any fields not + * provided will default to empty strings, empty arrays, or the LatLng + * (0, 0). + */ +export function makeFakeLeg(fields: Partial = {}): + DirectionsLeg { + return {...EMPTY_FAKE_LEG, ...fields}; + } diff --git a/src/utils/place_utils.ts b/src/utils/place_utils.ts index 737e46a..ee8cd65 100644 --- a/src/utils/place_utils.ts +++ b/src/utils/place_utils.ts @@ -59,7 +59,7 @@ function isPlace(data: LatLng|LatLngLiteral|Place): data is Place { return data.hasOwnProperty('id'); } -function isLatLng(data: LatLng|LatLngLiteral): data is LatLng { +export function isLatLng(data: LatLng|LatLngLiteral): data is LatLng { return typeof data.lat === 'function'; }