Skip to content

Commit b84b9c2

Browse files
mcreinhardcopybara-github
authored andcommitted
fix: use latest Maps JS API typings
PiperOrigin-RevId: 924919782
1 parent 9d1fe0b commit b84b9c2

15 files changed

Lines changed: 445 additions & 284 deletions

File tree

src/place_building_blocks/place_attribution/place_attribution_test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {html, TemplateResult} from 'lit';
1010

1111
import {Environment} from '../../testing/environment.js';
1212
import {makeFakePlace} from '../../testing/fake_place.js';
13+
import {mapsJsData} from '../../utils/place_utils.js';
1314

1415
import {PlaceAttribution} from './place_attribution.js';
1516

@@ -64,8 +65,8 @@ describe('place attribution test', () => {
6465
const place = makeFakePlace({
6566
id: '1234567890',
6667
attributions: [
67-
{provider: 'Foo', providerURI: 'https://foo.com'},
68-
{provider: 'Bar', providerURI: null}
68+
mapsJsData({provider: 'Foo', providerURI: 'https://foo.com'}),
69+
mapsJsData({provider: 'Bar', providerURI: null})
6970
]
7071
});
7172

src/place_building_blocks/place_data_provider/place_data_provider_test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ describe('PlaceDataProvider', () => {
6363
fetchFieldsSpy.and.callFake(
6464
async ({fields}: google.maps.places.FetchFieldsRequest) => {
6565
if (fields.includes('displayName')) {
66-
place.displayName = 'Fake Place';
66+
Object.defineProperty(place, 'displayName', {
67+
get: () => 'Fake Place',
68+
});
6769
}
6870
if (fields.includes('rating')) {
69-
place.rating = 5;
71+
Object.defineProperty(place, 'rating', {
72+
get: () => 5,
73+
});
7074
}
7175
return {place};
7276
});
@@ -78,6 +82,9 @@ describe('PlaceDataProvider', () => {
7882
Promise<{provider: PlaceDataProvider, fetchFieldsSpy: jasmine.Spy}> {
7983
const fetchFieldsSpy = jasmine.createSpy('fetchFields');
8084
env.fakeGoogleMapsHarness!.placeConstructor = (options) => {
85+
if (!options.id) {
86+
throw new Error('Place constructor requires an id.');
87+
}
8188
const place = makeFakePlace({
8289
id: options.id,
8390
fetchFields,

src/place_building_blocks/place_field_boolean/place_field_boolean_test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Environment} from '../../testing/environment.js';
1313
import {makeFakePlace} from '../../testing/fake_place.js';
1414
import {LifecycleSpyController} from '../../testing/lifecycle_spy.js';
1515
import type {PlaceResult} from '../../utils/googlemaps_types.js';
16+
import {mapsJsData} from '../../utils/place_utils.js';
1617

1718
import {BooleanField, PLACE_BOOLEAN_FIELDS, PlaceFieldBoolean} from './place_field_boolean.js';
1819

@@ -68,7 +69,7 @@ describe('place field boolean test', () => {
6869
servesWine: true,
6970

7071
businessStatus: 'OPERATIONAL' as google.maps.places.BusinessStatus,
71-
regularOpeningHours: {periods: [], weekdayDescriptions: []},
72+
regularOpeningHours: mapsJsData({periods: [], weekdayDescriptions: [], specialDays: []}),
7273
utcOffsetMinutes: 0,
7374
isOpen: async () => true,
7475
});
@@ -104,7 +105,7 @@ describe('place field boolean test', () => {
104105
servesWine: false,
105106

106107
businessStatus: 'OPERATIONAL' as google.maps.places.BusinessStatus,
107-
regularOpeningHours: {periods: [], weekdayDescriptions: []},
108+
regularOpeningHours: mapsJsData({periods: [], weekdayDescriptions: [], specialDays: []}),
108109
utcOffsetMinutes: 0,
109110
isOpen: async () => false,
110111
});
@@ -247,7 +248,7 @@ describe('place field boolean test', () => {
247248
const openPlace = makeFakePlace({
248249
id: '1234567890',
249250
businessStatus: 'OPERATIONAL' as google.maps.places.BusinessStatus,
250-
regularOpeningHours: {periods: [], weekdayDescriptions: []},
251+
regularOpeningHours: mapsJsData({periods: [], weekdayDescriptions: [], specialDays: []}),
251252
utcOffsetMinutes: 0,
252253
isOpen: async () => true,
253254
});
@@ -277,7 +278,7 @@ describe('place field boolean test', () => {
277278
const isOpenSpy = jasmine.createSpy('isOpen');
278279
const noBusinessStatusPlace = makeFakePlace({
279280
id: '1234567890',
280-
regularOpeningHours: {periods: [], weekdayDescriptions: []},
281+
regularOpeningHours: mapsJsData({periods: [], weekdayDescriptions: [], specialDays: []}),
281282
isOpen: isOpenSpy,
282283
});
283284
const noOpeningHoursPlace = makeFakePlace({
@@ -289,7 +290,7 @@ describe('place field boolean test', () => {
289290
const noUtcOffsetPlace = makeFakePlace({
290291
id: '1234567890',
291292
businessStatus: 'OPERATIONAL' as google.maps.places.BusinessStatus,
292-
regularOpeningHours: {periods: [], weekdayDescriptions: []},
293+
regularOpeningHours: mapsJsData({periods: [], weekdayDescriptions: [], specialDays: []}),
293294
isOpen: isOpenSpy,
294295
});
295296

@@ -311,7 +312,7 @@ describe('place field boolean test', () => {
311312
const place = makeFakePlace({
312313
id: '1234567890',
313314
businessStatus: 'OPERATIONAL' as google.maps.places.BusinessStatus,
314-
regularOpeningHours: {periods: [], weekdayDescriptions: []},
315+
regularOpeningHours: mapsJsData({periods: [], weekdayDescriptions: [], specialDays: []}),
315316
utcOffsetMinutes: 0,
316317
isOpen: isOpenSpy,
317318
});
@@ -350,7 +351,7 @@ describe('place field boolean test', () => {
350351
const place = makeFakePlace({
351352
id: '1234567890',
352353
businessStatus: 'OPERATIONAL' as google.maps.places.BusinessStatus,
353-
regularOpeningHours: {periods: [], weekdayDescriptions: []},
354+
regularOpeningHours: mapsJsData({periods: [], weekdayDescriptions: [], specialDays: []}),
354355
utcOffsetMinutes: 0,
355356
});
356357
const [el] = await prepareState(html`

src/place_building_blocks/place_field_text/place_field_text.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,16 @@ export class PlaceFieldText extends PlaceDataConsumer {
286286
}
287287
}
288288

289-
private renderBusinessStatus(status: google.maps.places.BusinessStatus|null|
290-
undefined): string|null|undefined {
289+
private renderBusinessStatus(
290+
status: google.maps.places.BusinessStatusString|null|undefined): string
291+
|null|undefined {
291292
if (!status) return status;
292293
switch (status) {
293-
case 'CLOSED_PERMANENTLY' as google.maps.places.BusinessStatus:
294+
case 'CLOSED_PERMANENTLY':
294295
return this.getMsg('PLACE_CLOSED_PERMANENTLY');
295-
case 'CLOSED_TEMPORARILY' as google.maps.places.BusinessStatus:
296+
case 'CLOSED_TEMPORARILY':
296297
return this.getMsg('PLACE_CLOSED_TEMPORARILY');
297-
case 'OPERATIONAL' as google.maps.places.BusinessStatus:
298+
case 'OPERATIONAL':
298299
return this.getMsg('PLACE_OPERATIONAL');
299300
default:
300301
return undefined;

src/place_building_blocks/place_field_text/place_field_text_test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Environment} from '../../testing/environment.js';
1313
import {FakeLatLng} from '../../testing/fake_lat_lng.js';
1414
import {makeFakePlace} from '../../testing/fake_place.js';
1515
import type {PlaceResult} from '../../utils/googlemaps_types.js';
16+
import {mapsJsData} from '../../utils/place_utils.js';
1617

1718
import {PLACE_RESULT_TEXT_FIELDS, PLACE_TEXT_FIELDS, PlaceFieldText, TextField} from './place_field_text.js';
1819

@@ -33,10 +34,10 @@ const fakePlace = makeFakePlace({
3334
internationalPhoneNumber: '+1 234-567-8910',
3435
location: new FakeLatLng(1, 2),
3536
nationalPhoneNumber: '(234) 567-8910',
36-
plusCode: {
37+
plusCode: mapsJsData({
3738
compoundCode: '1234+AB Some Place',
3839
globalCode: 'ABCD1234+AB',
39-
},
40+
}),
4041
rating: 4.5,
4142
types: ['restaurant'],
4243
userRatingCount: 123,

src/place_building_blocks/place_opening_hours/place_opening_hours_test.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {Environment} from '../../testing/environment.js';
1212
import {makeFakePlace} from '../../testing/fake_place.js';
1313
import {LifecycleSpyController} from '../../testing/lifecycle_spy.js';
1414
import type {Place, PlaceResult} from '../../utils/googlemaps_types.js';
15+
import {mapsJsData} from '../../utils/place_utils.js';
1516
import {PlaceFieldBoolean} from '../place_field_boolean/place_field_boolean.js';
1617
import {PlaceFieldText} from '../place_field_text/place_field_text.js';
1718

@@ -21,16 +22,16 @@ import {PlaceOpeningHours} from './place_opening_hours.js';
2122
const FAKE_PLACE_PROPS: Pick<Place, 'id'>&Partial<Place> = {
2223
id: '1234567890',
2324
businessStatus: 'OPERATIONAL' as google.maps.places.BusinessStatus,
24-
regularOpeningHours: {
25+
regularOpeningHours: mapsJsData({
2526
periods: [
26-
{
27-
open: {day: 0, hour: 10, minute: 0},
28-
close: {day: 0, hour: 20, minute: 0},
29-
},
30-
{
31-
open: {day: 6, hour: 10, minute: 0},
32-
close: {day: 6, hour: 21, minute: 30},
33-
},
27+
mapsJsData({
28+
open: mapsJsData({day: 0, hour: 10, minute: 0}),
29+
close: mapsJsData({day: 0, hour: 20, minute: 0}),
30+
}),
31+
mapsJsData({
32+
open: mapsJsData({day: 6, hour: 10, minute: 0}),
33+
close: mapsJsData({day: 6, hour: 21, minute: 30}),
34+
}),
3435
],
3536
weekdayDescriptions: [
3637
'Monday: Closed',
@@ -41,7 +42,8 @@ const FAKE_PLACE_PROPS: Pick<Place, 'id'>&Partial<Place> = {
4142
'Saturday: 10:00 AM - 9:30 PM',
4243
'Sunday: 10:00 AM - 8:00 PM',
4344
],
44-
},
45+
specialDays: [],
46+
}),
4547
utcOffsetMinutes: 0, // Important! Specifies when regularOpeningHours occur.
4648
};
4749

@@ -143,15 +145,16 @@ describe('PlaceOpeningHours', () => {
143145
it('labels place as open 24 hours when close time is null', async () => {
144146
const place = makeFakePlace({
145147
...FAKE_PLACE_PROPS,
146-
regularOpeningHours: {
148+
regularOpeningHours: mapsJsData({
147149
periods: [
148-
{
149-
open: {day: 0, hour: 0, minute: 0},
150+
mapsJsData({
151+
open: mapsJsData({day: 0, hour: 0, minute: 0}),
150152
close: null,
151-
},
153+
}),
152154
],
153155
weekdayDescriptions: [],
154-
},
156+
specialDays: [],
157+
}),
155158
});
156159
const el = await prepareState({place});
157160

@@ -161,10 +164,11 @@ describe('PlaceOpeningHours', () => {
161164
it('omits closing time when data is insufficient', async () => {
162165
const place = makeFakePlace({
163166
...FAKE_PLACE_PROPS,
164-
regularOpeningHours: {
167+
regularOpeningHours: mapsJsData({
165168
periods: [],
166169
weekdayDescriptions: [],
167-
},
170+
specialDays: [],
171+
}),
168172
});
169173
const el = await prepareState({place});
170174

src/place_building_blocks/place_photo_gallery/place_photo_gallery_test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Environment} from '../../testing/environment.js';
1313
import {makeFakePhoto, makeFakePlace, makeFakePlacePhoto} from '../../testing/fake_place.js';
1414
import {getDeepActiveElement} from '../../utils/deep_element_access.js';
1515
import type {Place, PlaceResult} from '../../utils/googlemaps_types.js';
16+
import {mapsJsData} from '../../utils/place_utils.js';
1617

1718
import {PlacePhotoGallery} from './place_photo_gallery.js';
1819

@@ -23,39 +24,45 @@ const fakePlace = makeFakePlace({
2324
makeFakePhoto(
2425
{
2526
authorAttributions: [
26-
{
27+
mapsJsData({
2728
displayName: 'Author A1',
2829
photoURI: '',
2930
uri: 'https://www.google.com/maps/contrib/A1',
30-
},
31-
{
31+
}),
32+
mapsJsData({
3233
displayName: 'Author A2',
3334
photoURI: '',
3435
uri: '',
35-
},
36+
}),
3637
],
3738
heightPx: 1000,
3839
widthPx: 2000,
40+
googleMapsURI: null,
41+
flagContentURI: null,
3942
},
4043
'https://lh3.googleusercontent.com/places/A'),
4144
makeFakePhoto(
4245
{
4346
authorAttributions: [
44-
{
47+
mapsJsData({
4548
displayName: 'Author B1',
4649
photoURI: '',
4750
uri: 'https://www.google.com/maps/contrib/B1',
48-
},
51+
}),
4952
],
5053
heightPx: 2000,
5154
widthPx: 1000,
55+
googleMapsURI: null,
56+
flagContentURI: null,
5257
},
5358
'https://lh3.googleusercontent.com/places/B'),
5459
makeFakePhoto(
5560
{
5661
authorAttributions: [],
5762
heightPx: 1340,
5863
widthPx: 1420,
64+
googleMapsURI: null,
65+
flagContentURI: null,
5966
},
6067
'https://lh3.googleusercontent.com/places/C'),
6168
],

src/place_building_blocks/place_reviews/place_reviews_test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {map} from 'lit/directives/map.js';
1111

1212
import {Environment} from '../../testing/environment.js';
1313
import {makeFakePlace, SAMPLE_FAKE_PLACE} from '../../testing/fake_place.js';
14+
import {mapsJsData} from '../../utils/place_utils.js';
1415

1516
import {PlaceReviews} from './place_reviews.js';
1617

@@ -63,18 +64,24 @@ describe('PlaceReviews', () => {
6364
it('renders the right URIs', async () => {
6465
const place = makeFakePlace({
6566
id: '',
66-
reviews: [{
67-
authorAttribution: {
67+
reviews: [mapsJsData({
68+
authorAttribution: mapsJsData({
6869
displayName: 'Author',
6970
photoURI: 'https://lh3.googlusercontent.com/a/1',
7071
uri: 'https://www.google.com/maps/contrib/1/reviews',
71-
},
72+
}),
7273
publishTime: new Date(1234567890),
7374
rating: 5,
7475
relativePublishTimeDescription: '1 month ago',
7576
text: '',
7677
textLanguageCode: 'en',
77-
}],
78+
flagContentURI: null,
79+
googleMapsURI: null,
80+
originalText: null,
81+
originalTextLanguageCode: null,
82+
visitDateMonth: null,
83+
visitDateYear: null,
84+
})],
7885
});
7986
const [reviews] = await prepareState(html`
8087
<gmpx-place-reviews .place=${place}></gmpx-place-reviews>

src/store_locator/store_locator_test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {FakeMapElement} from '../testing/fake_gmp_components.js';
1717
import {FakeLatLng, FakeLatLngBounds} from '../testing/fake_lat_lng.js';
1818
import {Deferred} from '../utils/deferred.js';
1919
import type {LatLngLiteral, Place} from '../utils/googlemaps_types.js';
20+
import {mapsJsData} from '../utils/place_utils.js';
2021

2122
import {DistanceMeasurer} from './distances.js';
2223
import {FeatureSet, StoreLocatorListing} from './interfaces.js';
@@ -179,11 +180,11 @@ describe('StoreLocator', () => {
179180
spyOnProperty(placePicker!, 'value').and.returnValue({
180181
id: 'foo_origin_id',
181182
location: origin,
182-
addressComponents: [{
183+
addressComponents: [mapsJsData({
183184
types: ['foo', 'country'],
184185
shortText: 'US',
185186
longText: 'United States'
186-
}],
187+
})],
187188
} as Partial<Place>as Place);
188189

189190
// Distance Matrix will set Location B as closer
@@ -222,8 +223,8 @@ describe('StoreLocator', () => {
222223
spyOnProperty(placePicker!, 'value').and.returnValue({
223224
id: 'foo_origin_id',
224225
location: new FakeLatLng(10, 10),
225-
addressComponents:
226-
[{types: ['foo', 'country'], shortText: 'CA', longText: 'Canada'}],
226+
addressComponents: [mapsJsData(
227+
{types: ['foo', 'country'], shortText: 'CA', longText: 'Canada'})],
227228
} as Partial<Place>as Place);
228229

229230
// Distance Matrix will set Location B as closer

src/testing/fake_google_maps.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ export class FakeGoogleMapsHarness {
2222
* Override this function to customize how `google.maps.places.Place` is
2323
* instantiated.
2424
*/
25-
placeConstructor = (options: google.maps.places.PlaceOptions) =>
26-
makeFakePlace({id: options.id});
25+
placeConstructor =
26+
(options: google.maps.places.PlaceOptions) => {
27+
if (!options.id) {
28+
throw new Error('Place constructor requires an id.');
29+
}
30+
return makeFakePlace({id: options.id});
31+
}
2732

2833
/**
2934
* Override this function to control the response of a

0 commit comments

Comments
 (0)