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 [], "sections": Array [],
"widget": Object { "widget": Object {
"damageLocations": "DamageLocationsWidget",
"footer": "SiteFooterWidget", "footer": "SiteFooterWidget",
"orderDetails": "OrderDetailsContent", "orderDetails": "OrderDetailsContent",
"serviceSummary": "ServiceSummaryContent", "serviceSummary": "ServiceSummaryContent",

View file

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

View file

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