Skip to content

Commit 1f579de

Browse files
mcreinhardcopybara-github
authored andcommitted
internal
PiperOrigin-RevId: 550012834
1 parent 3b94419 commit 1f579de

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

src/place_picker/place_picker_test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
// import 'jasmine'; (google3-only)
8-
import '../testing/fake_gmp_components.js';
98

109
import {html, TemplateResult} from 'lit';
1110

@@ -68,6 +67,10 @@ const FAKE_PLACES_LIBRARY = {
6867
describe('PlacePicker', () => {
6968
const env = new Environment();
7069

70+
beforeAll(() => {
71+
env.defineFakeMapElement();
72+
});
73+
7174
async function prepareState(template?: TemplateResult) {
7275
const root =
7376
env.render(template ?? html`<gmpx-place-picker></gmpx-place-picker>`);

src/testing/environment.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import {ReactiveElement, render as litRender, TemplateResult} from 'lit';
1010

1111
import {APILoader} from '../api_loader/api_loader.js';
12-
import {FAKE_GOOGLE_MAPS} from '../testing/fake_google_maps.js';
12+
13+
import {FakeMapElement} from './fake_gmp_components.js';
14+
import {FAKE_GOOGLE_MAPS} from './fake_google_maps.js';
1315

1416
declare global {
1517
module jasmine {
@@ -97,6 +99,11 @@ export class Environment {
9799
return root;
98100
}
99101

102+
defineFakeMapElement() {
103+
if (!customElements.get('gmp-map')) {
104+
customElements.define('gmp-map', FakeMapElement);
105+
}
106+
}
100107

101108
/**
102109
* Waits for all Lit `ReactiveElement` children of the given parent node to

src/testing/fake_gmp_components.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
*/
2020

2121
import {LitElement} from 'lit';
22-
import {customElement} from 'lit/decorators.js';
2322

2423
declare global {
2524
interface HTMLElementTagNameMap {
2625
'gmp-map': FakeMapElement;
2726
}
2827
}
2928

30-
@customElement('gmp-map')
3129
export class FakeMapElement extends LitElement {
3230
readonly innerMap = {} as google.maps.Map;
3331
}

src/testing/fake_lat_lng.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type LatLngBoundsLiteral = google.maps.LatLngBoundsLiteral;
1515
*/
1616
export class FakeLatLng implements LatLng {
1717
constructor(
18-
private readonly latitude: number,
19-
private readonly longitude: number,
18+
private readonly latitude = 0,
19+
private readonly longitude = 0,
2020
) {}
2121

2222
lat(): number {

src/testing/fake_route.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {FakeLatLngBounds} from './fake_lat_lng.js';
7+
import {FakeLatLng, FakeLatLngBounds} from './fake_lat_lng.js';
88

99
type DirectionsRoute = google.maps.DirectionsRoute;
10+
type DirectionsLeg = google.maps.DirectionsLeg;
1011

1112
const EMPTY_FAKE_ROUTE: DirectionsRoute = {
1213
bounds: new FakeLatLngBounds(),
@@ -19,6 +20,16 @@ const EMPTY_FAKE_ROUTE: DirectionsRoute = {
1920
waypoint_order: [],
2021
};
2122

23+
const EMPTY_FAKE_LEG: DirectionsLeg = {
24+
end_address: '',
25+
end_location: new FakeLatLng(),
26+
start_address: '',
27+
start_location: new FakeLatLng(),
28+
steps: [],
29+
traffic_speed_entry: [],
30+
via_waypoints: [],
31+
};
32+
2233
/**
2334
* Makes a fake `google.maps.DirectionsRoute` object for testing purposes.
2435
*
@@ -28,5 +39,17 @@ const EMPTY_FAKE_ROUTE: DirectionsRoute = {
2839
*/
2940
export function makeFakeRoute(fields: Partial<DirectionsRoute> = {}):
3041
DirectionsRoute {
31-
return {...EMPTY_FAKE_ROUTE, ...fields};
32-
}
42+
return {...EMPTY_FAKE_ROUTE, ...fields};
43+
}
44+
45+
/**
46+
* Makes a fake `google.maps.DirectionsLeg` object for testing purposes.
47+
*
48+
* @param fields - An object of fields of the `DirectionsLeg`. Any fields not
49+
* provided will default to empty strings, empty arrays, or the LatLng
50+
* (0, 0).
51+
*/
52+
export function makeFakeLeg(fields: Partial<DirectionsLeg> = {}):
53+
DirectionsLeg {
54+
return {...EMPTY_FAKE_LEG, ...fields};
55+
}

src/utils/place_utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function isPlace(data: LatLng|LatLngLiteral|Place): data is Place {
5959
return data.hasOwnProperty('id');
6060
}
6161

62-
function isLatLng(data: LatLng|LatLngLiteral): data is LatLng {
62+
export function isLatLng(data: LatLng|LatLngLiteral): data is LatLng {
6363
return typeof data.lat === 'function';
6464
}
6565

0 commit comments

Comments
 (0)