Skip to content

Commit

Permalink
internal
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 549768635
  • Loading branch information
mcreinhard authored and copybara-github committed Jul 20, 2023
1 parent 0fd82f8 commit a1bbe0e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/testing/fake_gmp_components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
*/

import {LitElement} from 'lit';
import {customElement} from 'lit/decorators.js';

declare global {
interface HTMLElementTagNameMap {
'gmp-map': FakeMapElement;
}
}

@customElement('gmp-map')
export class FakeMapElement extends LitElement {
readonly innerMap = {} as google.maps.Map;
}
4 changes: 2 additions & 2 deletions src/testing/fake_lat_lng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 26 additions & 3 deletions src/testing/fake_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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.
*
Expand All @@ -28,5 +39,17 @@ const EMPTY_FAKE_ROUTE: DirectionsRoute = {
*/
export function makeFakeRoute(fields: Partial<DirectionsRoute> = {}):
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> = {}):
DirectionsLeg {
return {...EMPTY_FAKE_LEG, ...fields};
}
2 changes: 1 addition & 1 deletion src/utils/place_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down

0 comments on commit a1bbe0e

Please sign in to comment.