Skip to content

Commit d911c6e

Browse files
mcreinhardcopybara-github
authored andcommitted
internal
PiperOrigin-RevId: 552027916
1 parent 8c4cce4 commit d911c6e

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/testing/fake_gmp_components.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ declare global {
2727
}
2828

2929
export class FakeMapElement extends LitElement {
30-
readonly innerMap = {} as google.maps.Map;
30+
readonly innerMap = {
31+
fitBounds:
32+
(bounds: google.maps.LatLngBounds|google.maps.LatLngBoundsLiteral) => {}
33+
} as google.maps.Map;
3134
}

src/testing/fake_lat_lng.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ export class FakeLatLng implements LatLng {
4040
}
4141
}
4242

43+
function isLatLngBoundsLiteral(bounds: LatLngBounds|LatLngBoundsLiteral):
44+
bounds is LatLngBoundsLiteral {
45+
return (typeof (bounds as LatLngBoundsLiteral).north === 'number');
46+
}
47+
4348
/**
4449
* A fake `LatLngBounds` class for testing purposes, that does not depend on the
4550
* `google.maps.LatLngBounds` constructor loaded by the API.
4651
*/
4752
export class FakeLatLngBounds implements LatLngBounds {
48-
constructor(
49-
private readonly boundsLiteral:
50-
LatLngBoundsLiteral = {north: 0, south: 0, east: 0, west: 0}) {}
53+
constructor(private readonly boundsLiteral: LatLngBoundsLiteral = {
54+
north: -90,
55+
south: 90,
56+
east: -180,
57+
west: 180
58+
}) {}
5159

5260
getNorthEast(): LatLng {
5361
return new FakeLatLng(this.boundsLiteral.north, this.boundsLiteral.east);
@@ -58,6 +66,15 @@ export class FakeLatLngBounds implements LatLngBounds {
5866
toJSON(): LatLngBoundsLiteral {
5967
return this.boundsLiteral;
6068
}
69+
union(other: LatLngBounds|LatLngBoundsLiteral): LatLngBounds {
70+
const {north, south, east, west} = this.boundsLiteral;
71+
const otherLiteral = isLatLngBoundsLiteral(other) ? other : other.toJSON();
72+
this.boundsLiteral.north = Math.max(north, otherLiteral.north);
73+
this.boundsLiteral.south = Math.min(south, otherLiteral.south);
74+
this.boundsLiteral.east = Math.max(east, otherLiteral.east);
75+
this.boundsLiteral.west = Math.min(west, otherLiteral.west);
76+
return this;
77+
}
6178

6279
contains(latLng: LatLng|LatLngLiteral): boolean {
6380
throw new Error('contains is not implemented');
@@ -83,7 +100,4 @@ export class FakeLatLngBounds implements LatLngBounds {
83100
toUrlValue(precision?: number): string {
84101
throw new Error('toUrlValue is not implemented');
85102
}
86-
union(other: LatLngBounds|LatLngBoundsLiteral): LatLngBounds {
87-
throw new Error('union is not implemented');
88-
}
89103
}

src/testing/fake_route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const EMPTY_FAKE_LEG: DirectionsLeg = {
3434
* Makes a fake `google.maps.DirectionsRoute` object for testing purposes.
3535
*
3636
* @param fields - An object of fields of the `DirectionsRoute`. Any fields not
37-
* provided will default to empty strings, empty arrays, or the LatLngBounds
38-
* 0/0/0/0.
37+
* provided will default to empty strings, empty arrays, or an empty
38+
* LatLngBounds.
3939
*/
4040
export function makeFakeRoute(fields: Partial<DirectionsRoute> = {}):
4141
DirectionsRoute {

0 commit comments

Comments
 (0)