diff --git a/src/testing/fake_gmp_components.ts b/src/testing/fake_gmp_components.ts index 8cb2bc6..870a346 100644 --- a/src/testing/fake_gmp_components.ts +++ b/src/testing/fake_gmp_components.ts @@ -27,5 +27,8 @@ declare global { } export class FakeMapElement extends LitElement { - readonly innerMap = {} as google.maps.Map; + readonly innerMap = { + fitBounds: + (bounds: google.maps.LatLngBounds|google.maps.LatLngBoundsLiteral) => {} + } as google.maps.Map; } diff --git a/src/testing/fake_lat_lng.ts b/src/testing/fake_lat_lng.ts index 8b3750a..864221b 100644 --- a/src/testing/fake_lat_lng.ts +++ b/src/testing/fake_lat_lng.ts @@ -40,14 +40,22 @@ export class FakeLatLng implements LatLng { } } +function isLatLngBoundsLiteral(bounds: LatLngBounds|LatLngBoundsLiteral): + bounds is LatLngBoundsLiteral { + return (typeof (bounds as LatLngBoundsLiteral).north === 'number'); +} + /** * A fake `LatLngBounds` class for testing purposes, that does not depend on the * `google.maps.LatLngBounds` constructor loaded by the API. */ export class FakeLatLngBounds implements LatLngBounds { - constructor( - private readonly boundsLiteral: - LatLngBoundsLiteral = {north: 0, south: 0, east: 0, west: 0}) {} + constructor(private readonly boundsLiteral: LatLngBoundsLiteral = { + north: -90, + south: 90, + east: -180, + west: 180 + }) {} getNorthEast(): LatLng { return new FakeLatLng(this.boundsLiteral.north, this.boundsLiteral.east); @@ -58,6 +66,15 @@ export class FakeLatLngBounds implements LatLngBounds { toJSON(): LatLngBoundsLiteral { return this.boundsLiteral; } + union(other: LatLngBounds|LatLngBoundsLiteral): LatLngBounds { + const {north, south, east, west} = this.boundsLiteral; + const otherLiteral = isLatLngBoundsLiteral(other) ? other : other.toJSON(); + this.boundsLiteral.north = Math.max(north, otherLiteral.north); + this.boundsLiteral.south = Math.min(south, otherLiteral.south); + this.boundsLiteral.east = Math.max(east, otherLiteral.east); + this.boundsLiteral.west = Math.min(west, otherLiteral.west); + return this; + } contains(latLng: LatLng|LatLngLiteral): boolean { throw new Error('contains is not implemented'); @@ -83,7 +100,4 @@ export class FakeLatLngBounds implements LatLngBounds { toUrlValue(precision?: number): string { throw new Error('toUrlValue is not implemented'); } - union(other: LatLngBounds|LatLngBoundsLiteral): LatLngBounds { - throw new Error('union is not implemented'); - } } diff --git a/src/testing/fake_route.ts b/src/testing/fake_route.ts index 39d32e1..6a71f3e 100644 --- a/src/testing/fake_route.ts +++ b/src/testing/fake_route.ts @@ -34,8 +34,8 @@ const EMPTY_FAKE_LEG: DirectionsLeg = { * Makes a fake `google.maps.DirectionsRoute` object for testing purposes. * * @param fields - An object of fields of the `DirectionsRoute`. Any fields not - * provided will default to empty strings, empty arrays, or the LatLngBounds - * 0/0/0/0. + * provided will default to empty strings, empty arrays, or an empty + * LatLngBounds. */ export function makeFakeRoute(fields: Partial = {}): DirectionsRoute {