Skip to content
Merged
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
12 changes: 10 additions & 2 deletions src/components/AddressSearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function AddressSearch(props) {
postal_code: zipCode,
administrative_area_level_1: state,
administrative_area_level_2: stateFallback,
country,
country: countryPrimary,
} = GooglePlacesUtils.getAddressComponents(addressComponents, {
street_number: 'long_name',
route: 'long_name',
Expand All @@ -142,7 +142,15 @@ function AddressSearch(props) {

// Make sure that the order of keys remains such that the country is always set above the state.
// Refer to https://github.com/Expensify/App/issues/15633 for more information.
const {state: stateAutoCompleteFallback = '', city: cityAutocompleteFallback = ''} = GooglePlacesUtils.getPlaceAutocompleteTerms(autocompleteData.terms);
const {
country: countryFallbackLongName = '',
state: stateAutoCompleteFallback = '',
city: cityAutocompleteFallback = '',
} = GooglePlacesUtils.getPlaceAutocompleteTerms(autocompleteData.terms);

const countryFallback = _.findKey(CONST.ALL_COUNTRIES, (country) => country === countryFallbackLongName);

const country = countryPrimary || countryFallback;

const values = {
street: `${streetNumber} ${streetName}`.trim(),
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/GooglePlacesUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ const addressComponents = [
types: ['postal_code'],
},
];

const autoCompleteTerms = [
{offset: 0, value: 'Bangladesh Border Road'},
{offset: 24, value: 'Bangladesh'},
];

describe('GooglePlacesUtilsTest', () => {
describe('getAddressComponents', () => {
it('should find address components by type', () => {
Expand Down Expand Up @@ -189,4 +195,14 @@ describe('GooglePlacesUtilsTest', () => {
expect(executionTime).toBeLessThan(5.0);
});
});
describe('getPlaceAutocompleteTerms', () => {
it('should find auto complete terms', () => {
expect(GooglePlacesUtils.getPlaceAutocompleteTerms(autoCompleteTerms)).toStrictEqual({
country: 'Bangladesh',
state: 'Bangladesh Border Road',
city: '',
street: '',
});
});
});
});