Merge pull request #1134 from Safelite/feature/humphries/INSR-8688

INSR-8688: Add address autocomplete, fix edit location navigation
This commit is contained in:
AHumphriesSL 2026-03-06 11:29:28 -05:00 committed by GitHub
commit 7c7f7b5f90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 200 additions and 89 deletions

View file

@ -10,11 +10,69 @@ import { getRandomString, getRandomInt, getRandomBoolean } from '@/helpers/data-
import navigationScenarios from '@/router/router-constants/navigation-scenarios.js';
import { useMainStore } from '@/store/index.js';
/** @ignore */
function setupMocks({
storeData,
props
}) {
const mountOptions = getMountOptions({
router: {
navigate: jest.fn(),
navigateWithSpinner: jest.fn()
},
loadScript: jest.fn().mockResolvedValue()
});
if (storeData) mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: storeData
}
})];
window.google = {
maps: {
event: {
addListener: jest
.fn()
.mockImplementation((element, eventName, callbackFunction) => {
/** @ignore */
function interceptedCallbackFunction(e) {
callbackFunction(e.detail);
}
// selectedPlace = "Woogly";
element.addEventListener(eventName, interceptedCallbackFunction);
}),
removeListener: jest.fn(),
clearInstanceListeners: jest.fn()
},
places: {
Autocomplete: jest.fn().mockImplementation((el) => el),
AutocompleteService: jest.fn().mockImplementation(() => {
return {
getPlacePredictions: (request, callback) => {
// Throwing an error here guarantees that the function that calls it finishes
throw new Error();
}
};
}),
PlacesService: jest.fn().mockImplementation(() => {}),
AutocompleteSessionToken: jest.fn().mockImplementation(() => {})
}
}
};
if (props) mountOptions.propsData = props;
const wrapper = shallowMount(contactDetails, mountOptions);
return { wrapper };
}
describe('contactDetails.vue', () => {
describe('Rendering', () => {
test('Should render site header', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const siteHeader = wrapper.findComponent({ ref: 'siteHeader' });
@ -24,7 +82,7 @@ describe('contactDetails.vue', () => {
});
test('Should render sub title', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const siteSubHeader = wrapper.findComponent({ ref: 'siteSubHeader' });
@ -34,7 +92,7 @@ describe('contactDetails.vue', () => {
});
test('Should render appointment information alert', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const appointmentInformationAlert = wrapper.findComponent({ ref: 'appointmentInformationAlert' });
@ -44,8 +102,6 @@ describe('contactDetails.vue', () => {
});
test('Should render same as policy address question subcomponent if service zip is same as customer zip', async () => {
// Arrange
const mountOptions = getMountOptions();
const customerStreetAddress = getRandomString(10, 50);
const customerStreetAddress2 = getRandomString(0, 50);
const customerCity = getRandomString(4, 20);
@ -55,7 +111,7 @@ describe('contactDetails.vue', () => {
const serviceCity = getRandomString(4, 20);
const serviceState = getRandomString(2, 2);
const zipCode = getRandomInt(10000, 99999).toString();
const mainInitialState = {
const storeData = {
order: {
customer: {
address: {
@ -75,12 +131,7 @@ describe('contactDetails.vue', () => {
}
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(contactDetails, mountOptions);
const { wrapper } = setupMocks({ storeData });
await wrapper.vm.$nextTick();
@ -92,8 +143,6 @@ describe('contactDetails.vue', () => {
});
test('Should not render same as policy address question subcomponent if service zip is different from customer zip', () => {
// Arrange
const mountOptions = getMountOptions();
const firstName = getRandomString(4, 15);
const lastName = getRandomString(4, 15);
const emailAddress = getRandomString(10, 20);
@ -101,7 +150,7 @@ describe('contactDetails.vue', () => {
const testZipCode = getRandomInt(10000, 99999);
const customerZipCode = testZipCode.toString();
const serviceZipCode = (testZipCode + 1).toString();
const mainInitialState = {
const storeData = {
order: {
customer: {
firstName,
@ -119,12 +168,7 @@ describe('contactDetails.vue', () => {
}
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(contactDetails, mountOptions);
const { wrapper } = setupMocks({ storeData });
// Act
const sameAsPolicyAddressQuestion = wrapper.findComponent({ ref: 'sameAsPolicyAddressQuestion' });
@ -134,7 +178,7 @@ describe('contactDetails.vue', () => {
});
test('Should render address question subcomponent', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const addressQuestion = wrapper.findComponent({ ref: 'addressQuestion' });
@ -144,7 +188,7 @@ describe('contactDetails.vue', () => {
});
test('Should render apartment question subcomponent', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const address2Question = wrapper.findComponent({ ref: 'address2Question' });
@ -154,7 +198,7 @@ describe('contactDetails.vue', () => {
});
test('Should render city question subcomponent', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const cityQuestion = wrapper.findComponent({ ref: 'cityQuestion' });
@ -164,7 +208,7 @@ describe('contactDetails.vue', () => {
});
test('Should render state question subcomponent', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const stateQuestion = wrapper.findComponent({ ref: 'stateQuestion' });
@ -174,7 +218,7 @@ describe('contactDetails.vue', () => {
});
test('Should render zip code question subcomponent', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const zipCodeQuestion = wrapper.findComponent({ ref: 'zipCodeQuestion' });
@ -184,7 +228,7 @@ describe('contactDetails.vue', () => {
});
test('Should render change zip code alert', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const changeZipCodeAlert = wrapper.findComponent({ ref: 'changeZipCodeAlert' });
@ -194,7 +238,7 @@ describe('contactDetails.vue', () => {
});
test('Should render vehicle protected question subcomponent', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const vehicleProtectedQuestion = wrapper.findComponent({ ref: 'vehicleProtectedQuestion' });
@ -204,7 +248,7 @@ describe('contactDetails.vue', () => {
});
test('Should render technician notes textarea question subcomponent', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const notesQuestion = wrapper.findComponent({ ref: 'notesQuestion' });
@ -214,7 +258,7 @@ describe('contactDetails.vue', () => {
});
test('Should render clearance text subcomponent', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const clearanceText = wrapper.findComponent({ ref: 'clearanceText' });
@ -224,7 +268,7 @@ describe('contactDetails.vue', () => {
});
test('Should render site footer', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions());
const { wrapper } = setupMocks({});
// Act
const footer = wrapper.findComponent({ ref: 'siteFooter' });
@ -234,8 +278,6 @@ describe('contactDetails.vue', () => {
});
test('Mocked store yields expected data', () => {
// Arrange
const mountOptions = getMountOptions();
const address = getRandomString(10, 50);
const address2 = getRandomString(0, 50);
const city = getRandomString(4, 20);
@ -243,7 +285,7 @@ describe('contactDetails.vue', () => {
const zipCode = getRandomInt(10000, 99999).toString();
const notesForTechnician = getRandomString(1, 100);
const isVehicleProtected = getRandomBoolean();
const mainInitialState = {
const storeData = {
order: {
serviceLocation: {
address,
@ -258,13 +300,8 @@ describe('contactDetails.vue', () => {
}
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(contactDetails, mountOptions);
const { wrapper } = setupMocks({ storeData });
// Assert
expect(wrapper.vm.address).toBe(address);
@ -280,11 +317,7 @@ describe('contactDetails.vue', () => {
describe('Navigation', () => {
test('Back button clicked triggers navigation', () => {
// Arrange
const wrapper = shallowMount(contactDetails, getMountOptions({
router: {
navigateWithSpinner: jest.fn()
}
}));
const { wrapper } = setupMocks({});
wrapper.vm.navigateBack = baseMixin.methods.navigateBack;
// Act
@ -295,41 +328,25 @@ describe('contactDetails.vue', () => {
expect(wrapper.vm.$router.navigateWithSpinner)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_BACK, undefined);
});
test('Forward button clicked triggers appropriate navigation', () => {
test('Forward button clicked triggers appropriate navigation', async () => {
// Arrange
const mountOptions = getMountOptions({
router: {
navigate: jest.fn()
},
navigationScenarios
});
const mainInitialState = {
const storeData = {
order: {
serviceLocation: { IsSafeliteProvider: true }
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(contactDetails, mountOptions);
const { wrapper } = setupMocks({ storeData });
// Act
wrapper.vm.forwardButtonAction();
await wrapper.vm.forwardButtonAction();
// Assert
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
expect(wrapper.vm.$router.navigate)
.toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD, undefined);
});
test('Forward button click updates service location info', () => {
test('Forward button click updates service location info', async () => {
// Arrange
const mountOptions = getMountOptions({
router: {
navigate: jest.fn()
}
});
const provider = {
address: {
city: getRandomString(4, 20),
@ -342,19 +359,14 @@ describe('contactDetails.vue', () => {
phoneNumber: getRandomInt(1000000000, 9999999999).toString(),
providerNumber: getRandomInt(100000, 999999).toString()
}
const mainInitialState = {
const storeData = {
order: {
serviceLocation: {
provider
}
}
};
mountOptions.global.plugins = [createTestingPinia({
initialState: {
main: mainInitialState
}
})];
const wrapper = shallowMount(contactDetails, mountOptions);
const { wrapper } = setupMocks({ storeData });
const address = getRandomString(10, 50);
const address2 = getRandomString(0, 50);
const city = getRandomString(4, 20);
@ -371,7 +383,7 @@ describe('contactDetails.vue', () => {
});
// Act
wrapper.vm.forwardButtonAction();
await wrapper.vm.forwardButtonAction();
// Assert
expect(useMainStore().updateServiceLocation).toHaveBeenCalledWith({
@ -383,21 +395,16 @@ describe('contactDetails.vue', () => {
});
});
test('Forward button click updates notes for technician', () => {
test('Forward button click updates notes for technician', async () => {
// Arrange
const mountOptions = getMountOptions({
router: {
navigate: jest.fn()
}
});
const wrapper = shallowMount(contactDetails, mountOptions);
const { wrapper } = setupMocks({});
const notesForTechnician = getRandomString(1, 100);
wrapper.setData({
notesForTechnician
});
// Act
wrapper.vm.forwardButtonAction();
await wrapper.vm.forwardButtonAction();
// Assert
expect(useMainStore().updateContactInfo).toHaveBeenCalledWith({

View file

@ -133,6 +133,7 @@ import errorMessages from '@/constants/error-messages';
import { required } from '@/helpers/validation-rules';
import widgetFields from '@/constants/cms-widget-fields';
import states from '@/constants/states';
import applicationConfig from '@/constants/application-config';
// DEFINE VALIDATION RULES
defineRule('street-address-required', required(errorMessages.SERVICE_ADDRESS_REQUIRED));
@ -157,8 +158,9 @@ export default {
async beforeRouteEnter(to, from, next) {
const cmsContent = await fetchCmsContentForPage(to.query.issPage);
next((vm) => {
next(async (vm) => {
vm.setCmsContent(cmsContent);
await vm.setupAddressLookup();
});
},
data() {
@ -239,7 +241,7 @@ export default {
/**
* @summary Steps to perform when forward button clicked.
*/
forwardButtonAction() {
async forwardButtonAction() {
const contactInfo = {
notesForTechnician: this.notesForTechnician
};
@ -247,6 +249,8 @@ export default {
const provider = useMainStore().serviceLocation.provider;
await this.geocodeAddress();
useMainStore().updateServiceLocation({
address: this.address,
address2: this.address2,
@ -267,7 +271,100 @@ export default {
this.address = '';
this.address2 = '';
this.city = '';
}
},
async setupAddressLookup() {
const apiKey = applicationConfig.GOOGLE_PLACES_API_KEY;
await this.$loadScript(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places&callback=Function.prototype`)
.catch(() => {
// Failed to fetch script
window.console.warn('Unable to load Google Places API script');
});
},
geocodeAddress() {
const autoCompletePromise = new Promise((resolve, reject) => {
try {
// Get Autocomplete Service
const acService = new window.google.maps.places.AutocompleteService();
// Get Places Service, needs pseudo element (or a map)
const placeService = new window.google.maps.places.PlacesService(document.createElement('div'));
// Create Autocomplete Session token, multiple requests one pricing hit
const acSessionToken = new window.google.maps.places.AutocompleteSessionToken();
const addressValue = `${this.address}, ${this.city}, ${this.state} ${this.zipCode}`;
acService.getPlacePredictions(
{
input: addressValue,
type: ['geocode'],
componentRestrictions: { country: ['us'] },
sessionToken: acSessionToken
},
(predictions) => {
if (predictions && predictions.length > 0) {
const firstPrediction = predictions[0];
if (firstPrediction.place_id) {
placeService.getDetails(
{
placeId: firstPrediction.place_id,
fields: ['address_components'],
sessionToken: acSessionToken
},
(details) => {
this.fillInAddress(details);
resolve();
}
);
} else {
resolve();
}
} else {
resolve();
}
}
);
} catch (error) {
window.console.warn('Error initializing Google Places API services', error);
resolve();
}
});
return autoCompletePromise;
},
async fillInAddress(googlePlace) {
let processedStreetAddress = false;
let processedRoute = false;
for (const component of googlePlace.address_components) {
const componentType = component.types[0];
switch (componentType) {
case 'street_number': {
if (processedRoute) {
this.address = `${component.long_name} ${this.address}`;
} else {
this.address = component.long_name;
}
processedStreetAddress = true;
break;
}
case 'route': {
if (processedStreetAddress) {
this.address += ` ${component.short_name}`;
} else {
this.address = component.short_name;
}
processedRoute = true;
break;
}
case 'locality': {
this.city = component.long_name;
break;
}
default:
}
}
},
}
};
</script>

View file

@ -389,7 +389,6 @@ export default {
}
this.smsPhoneNumber = this.getSMSPhoneFromStore();
if (this.isPayInAdvanceDisabled) {
console.log('Pay in Advance is disabled, defaulting to Pay at Time of Service');
this.paymentMethod = paymentMethods.PAY_AT_TIME_OF_SERVICE;
}
},
@ -442,8 +441,11 @@ export default {
handleEditClicked(section) {
switch (section) {
case 'location':
const scenario = this.mainStore.isMobileAppointment
? this.navigationScenarios.EDIT_SERVICE_LOCATION_MOBILE
: this.navigationScenarios.EDIT_SERVICE_LOCATION_INSHOP;
this.$router.navigateWithSpinner(
this.navigationScenarios.EDIT_SERVICE_LOCATION,
scenario,
this.$route
);
break;

View file

@ -105,7 +105,8 @@ const navigationScenarios = Object.freeze({
PAY_IN_ADVANCE_ERROR: 'PAY_IN_ADVANCE_ERROR',
PAY_IN_ADVANCE_CREDIT_CARD_ERROR: 'PAY_IN_ADVANCE_CREDIT_CARD_ERROR',
PAY_IN_ADVANCE_SUCCESS: 'PAY_IN_ADVANCE_SUCCESS',
EDIT_SERVICE_LOCATION: 'EDIT_SERVICE_LOCATION',
EDIT_SERVICE_LOCATION_INSHOP: 'EDIT_SERVICE_LOCATION_INSHOP',
EDIT_SERVICE_LOCATION_MOBILE: 'EDIT_SERVICE_LOCATION_MOBILE',
EDIT_SCHEDULE: 'EDIT_SCHEDULE',
EDIT_WIPERS: 'EDIT_WIPERS',

View file

@ -638,9 +638,13 @@ const routingTable = () => [
destinationIssPageValue: issPageValues.PAYMENT_PAGE
},
{
scenario: navigationScenarios.EDIT_SERVICE_LOCATION,
scenario: navigationScenarios.EDIT_SERVICE_LOCATION_INSHOP,
destinationIssPageValue: issPageValues.SCHEDULE_PAGE
},
{
scenario: navigationScenarios.EDIT_SERVICE_LOCATION_MOBILE,
destinationIssPageValue: issPageValues.CONTACT_DETAILS
},
{
scenario: navigationScenarios.EDIT_SCHEDULE,
destinationIssPageValue: issPageValues.SCHEDULE_PAGE