Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/testing/fake_gmp_components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
26 changes: 20 additions & 6 deletions src/testing/fake_lat_lng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand All @@ -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');
}
}
4 changes: 2 additions & 2 deletions src/testing/fake_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = {}):
DirectionsRoute {
Expand Down