Removing unnecessary methods

This commit is contained in:
Michaela Brydon 2024-01-22 10:45:08 -05:00
parent cc638bc709
commit 002ef3726d
3 changed files with 35 additions and 39 deletions

View file

@ -8,6 +8,7 @@ Object {
},
"sections": Array [],
"widget": Object {
"damageLocations": "DamageLocationsWidget",
"footer": "SiteFooterWidget",
"orderDetails": "OrderDetailsContent",
"serviceSummary": "ServiceSummaryContent",

View file

@ -9,6 +9,7 @@ import { useMainStore } from '@/store';
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
import settleAllPromises from '@/helpers/layout-helper.js';
import widgetFields from '@/constants/cms-widget-fields.js';
import { toTitleCase, formatAddress, toDisplayPhoneNumber } from '@/helpers/text-helper.js';
// Mock fetchCmsContentForPage
jest.mock('@/helpers/cms-content-helper', () => ({
@ -57,6 +58,11 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu
return { wrapper };
}
beforeEach(() => {
formatAddress.mockClear();
toDisplayPhoneNumber.mockClear();
});
describe('tpa-submit', () => {
test('returns the initial data', () => {
// Arrange
@ -337,11 +343,12 @@ describe('tpa-submit', () => {
expect(vehicleSection.lines).toStrictEqual(expectedLines);
}
);
// TODO update because this case is now much more complicated
test.each([
['Apple sauce', 'Apple sauce'],
['', ''],
['', undefined],
['', null]
['Apple sauce', 'Apple sauce']// ,
// ['', ''],
// ['', undefined],
// ['', null]
])(
'damage line is %p when store damage is %p',
async (damageLine, storeDamage) => {
@ -386,15 +393,12 @@ describe('tpa-submit', () => {
const preferredShopSection = wrapper.vm.sections[preferredShopSectionIndex];
expect(preferredShopSection.lines.length).toBe(3);
});
test.each([
['some value', 'some value'],
['', ''],
['', null],
['', undefined]
])('first line is %p when company name is %p', async (line, companyName) => {
test('first line is value returned from toTitleCase method', async () => {
// Arrange
const initialData = { companyName };
const initialData = { companyName: 'some value' };
const { wrapper } = getMountedComponent({}, initialData);
const expectedName = 'some expected name';
toTitleCase.mockImplementationOnce(() => expectedName);
const preferredShopSectionIndex = 2;
// Act
@ -407,7 +411,7 @@ describe('tpa-submit', () => {
// Assert
const preferredShopSection = wrapper.vm.sections[preferredShopSectionIndex];
expect(preferredShopSection.lines[0]).toBe(line);
expect(preferredShopSection.lines[0]).toBe(expectedName);
});
test('second line is expected and formatAddress called', async () => {
// Arrange
@ -426,7 +430,7 @@ describe('tpa-submit', () => {
};
const { wrapper } = getMountedComponent(initialStore);
const line = 'some returned line';
wrapper.vm.formatAddress = jest.fn().mockImplementationOnce(() => line);
formatAddress.mockImplementationOnce(() => line);
const preferredShopSectionIndex = 2;
// Act
@ -440,8 +444,8 @@ describe('tpa-submit', () => {
// Assert
const preferredShopSection = wrapper.vm.sections[preferredShopSectionIndex];
expect(preferredShopSection.lines[1]).toBe(line);
expect(wrapper.vm.formatAddress).toHaveBeenCalledTimes(1);
expect(wrapper.vm.formatAddress).toHaveBeenCalledWith(
expect(formatAddress).toHaveBeenCalledTimes(1);
expect(formatAddress).toHaveBeenCalledWith(
address.streetAddress,
null,
address.city,
@ -461,7 +465,7 @@ describe('tpa-submit', () => {
};
const { wrapper } = getMountedComponent(initialStore);
const expectedLine = 'returned from to display phone num';
wrapper.vm.toDisplayPhoneNumber = jest.fn().mockImplementationOnce(() => expectedLine);
toDisplayPhoneNumber.mockImplementationOnce(() => expectedLine);
const preferredShopSectionIndex = 2;
// Act
@ -475,7 +479,7 @@ describe('tpa-submit', () => {
// Assert
const preferredShopSection = wrapper.vm.sections[preferredShopSectionIndex];
expect(preferredShopSection.lines[2]).toBe(expectedLine);
expect(wrapper.vm.toDisplayPhoneNumber).toHaveBeenCalledWith(phoneNumber);
expect(toDisplayPhoneNumber).toHaveBeenCalledWith(phoneNumber);
});
});
test('contact info section has expected content', async () => {
@ -498,7 +502,7 @@ describe('tpa-submit', () => {
const expectedLine1 = 'Jones Eddison';
const expectedLine2 = emailAddress;
const expectedLine3 = 'some value returned';
wrapper.vm.toDisplayPhoneNumber = jest.fn().mockImplementation((number) => (number === phoneNumber ? expectedLine3 : ''));
toDisplayPhoneNumber.mockImplementation((number) => (number === phoneNumber ? expectedLine3 : ''));
const contactInfoSectionIndex = 3;
// Act
@ -514,7 +518,7 @@ describe('tpa-submit', () => {
expect(contactInfoSection.lines[0]).toBe(expectedLine1);
expect(contactInfoSection.lines[1]).toBe(expectedLine2);
expect(contactInfoSection.lines[2]).toBe(expectedLine3);
expect(wrapper.vm.toDisplayPhoneNumber).toHaveBeenCalledWith(phoneNumber);
expect(toDisplayPhoneNumber).toHaveBeenCalledWith(phoneNumber);
});
});
describe('computed', () => {

View file

@ -171,7 +171,7 @@ export default {
},
subHeaderBodyTwo() {
const cmsContent = this.getCmsContent(this.widget.siteSubHeader, widgetFields.CONTENT_GROUP_WIDGET.BODY_TEXT_2);
return this.getStringWithCustomValues(cmsContent, this.customValueMap);
return getStringWithCustomValues(cmsContent, this.customValueMap);
},
serviceSummaryText() {
return this.getCmsContent(this.widget.serviceSummary, widgetFields.TEXT_BLOCK_WIDGET.TEXT);
@ -181,7 +181,7 @@ export default {
},
orderDetailsBody() {
const orderDetailsBodyText = this.getCmsContent(this.widget.orderDetails, widgetFields.CONTENT_GROUP_WIDGET.BODY_TEXT);
return this.processIfStatements(orderDetailsBodyText, 'custom', this.getCustomValueFromString);
return processIfStatements(orderDetailsBodyText, 'custom', this.getCustomValueFromString);
},
forwardButtonText() {
return this.getCmsContent(this.widget.footer, widgetFields.FOOTER_WIDGET.FORWARD_BUTTON_TEXT);
@ -193,7 +193,7 @@ export default {
return useMainStore().order.currentDeductible;
},
deductibleBoxValue() {
return this.isVerified ? this.formatAmountInDollars(this.currentDeductible) : VERIFYING_COVERAGE;
return this.isVerified ? formatAmountInDollars(this.currentDeductible) : VERIFYING_COVERAGE;
},
getVehicleLines() {
const { year, make, model } = useMainStore().order.vehicle;
@ -206,17 +206,16 @@ export default {
return this.getAnswersNullSafe(this.widget.damageLocations);
},
driverSideDamageAnswers() {
const answerContent = this.getLocationAnswer(damageLocationsSelected.DRIVER, this.locationAnswers);
const answerContent = getLocationAnswer(damageLocationsSelected.DRIVER, this.locationAnswers);
return this.getAnswersNullSafe(answerContent?.SubWidgetName);
},
passengerSideDamageAnswers() {
const answerContent = this.getLocationAnswer(damageLocationsSelected.PASSENGER, this.locationAnswers);
const answerContent = getLocationAnswer(damageLocationsSelected.PASSENGER, this.locationAnswers);
return this.getAnswersNullSafe(answerContent?.SubWidgetName);
},
// TODO finish
getDamageLines() {
const { glassToReplace, isRepair } = useMainStore().order.damage;
return this.getDamageDisplayContent(
return getDamageDisplayContent(
this.locationAnswers,
this.driverSideDamageAnswers,
this.passengerSideDamageAnswers,
@ -227,16 +226,16 @@ export default {
getPreferredShopLines() {
const { phoneNumber, address } = useMainStore().order.serviceLocation.provider;
const { streetAddress, city, state, zipCode } = address;
const displayAddress = this.formatAddress(streetAddress, null, city, state, zipCode);
const displayPhoneNumber = this.toDisplayPhoneNumber(phoneNumber);
return [this.toTitleCase(this.companyName ?? ''), displayAddress, displayPhoneNumber];
const displayAddress = formatAddress(streetAddress, null, city, state, zipCode);
const displayPhoneNumber = toDisplayPhoneNumber(phoneNumber);
return [toTitleCase(this.companyName ?? ''), displayAddress, displayPhoneNumber];
},
getContactInfoLines() {
const { firstName, lastName, emailAddress, phoneNumber } = useMainStore().contactInfo;
return [
`${firstName} ${lastName}`,
emailAddress ?? '',
this.toDisplayPhoneNumber(phoneNumber)
toDisplayPhoneNumber(phoneNumber)
];
}
},
@ -279,15 +278,7 @@ export default {
getAnswersNullSafe(widgetName) {
const rawAnswers = this.getCmsContent(widgetName, 'Answers');
return rawAnswers || [];
},
processIfStatements,
getStringWithCustomValues,
toDisplayPhoneNumber,
toTitleCase,
formatAddress,
formatAmountInDollars,
getDamageDisplayContent,
getLocationAnswer
}
}
};
</script>