Merge pull request #3255 from Safelite/feature/CASH-2934
Feature/CASH 2934
This commit is contained in:
commit
30b2e3b3d2
3 changed files with 27 additions and 3 deletions
|
|
@ -210,7 +210,7 @@ describe("save-progress-popup-question ", () => {
|
||||||
|
|
||||||
expect(dispatchStoreAction).toHaveBeenCalledWith(
|
expect(dispatchStoreAction).toHaveBeenCalledWith(
|
||||||
storeActions.SAVE_PHONE_NUMBER,
|
storeActions.SAVE_PHONE_NUMBER,
|
||||||
"555-123-4567",
|
"5551234567",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
expect(dispatchStoreAction).not.toHaveBeenCalledWith(
|
expect(dispatchStoreAction).not.toHaveBeenCalledWith(
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,24 @@ export function isPhoneContactMethod(contactMethod) {
|
||||||
return contactMethod === saveProgressPopupContactMethods.PHONE;
|
return contactMethod === saveProgressPopupContactMethods.PHONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function normalizePhoneNumberForStore(phoneNumber) {
|
||||||
|
if (!phoneNumber) {
|
||||||
|
return phoneNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(phoneNumber).replace(/\D/g, "");
|
||||||
|
}
|
||||||
|
|
||||||
export async function saveProgressPopupContactToStore(
|
export async function saveProgressPopupContactToStore(
|
||||||
dispatchStoreAction,
|
dispatchStoreAction,
|
||||||
{ contactMethod, userInput, smsConsent, pageName }
|
{ contactMethod, userInput, smsConsent, pageName }
|
||||||
) {
|
) {
|
||||||
if (isPhoneContactMethod(contactMethod)) {
|
if (isPhoneContactMethod(contactMethod)) {
|
||||||
await dispatchStoreAction(storeActions.SAVE_PHONE_NUMBER, userInput, false);
|
await dispatchStoreAction(
|
||||||
|
storeActions.SAVE_PHONE_NUMBER,
|
||||||
|
normalizePhoneNumberForStore(userInput),
|
||||||
|
false
|
||||||
|
);
|
||||||
await dispatchStoreAction(storeActions.SAVE_IS_SMS_OPT_IN, smsConsent.transactional, false);
|
await dispatchStoreAction(storeActions.SAVE_IS_SMS_OPT_IN, smsConsent.transactional, false);
|
||||||
|
|
||||||
const existingPageData = store.getters.pageData(pageName) ?? {};
|
const existingPageData = store.getters.pageData(pageName) ?? {};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { storeActions } from "@/constants/store-actions";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import {
|
import {
|
||||||
isPhoneContactMethod,
|
isPhoneContactMethod,
|
||||||
|
normalizePhoneNumberForStore,
|
||||||
saveProgressPopupContactMethods,
|
saveProgressPopupContactMethods,
|
||||||
saveProgressPopupContactToStore,
|
saveProgressPopupContactToStore,
|
||||||
} from "./save-progress-popup-contact-helper";
|
} from "./save-progress-popup-contact-helper";
|
||||||
|
|
@ -28,6 +29,17 @@ describe("save-progress-popup-contact-helper", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("normalizePhoneNumberForStore", () => {
|
||||||
|
it("should strip non-digit characters from a formatted phone number", () => {
|
||||||
|
expect(normalizePhoneNumberForStore("555-123-4567")).toBe("5551234567");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return empty values unchanged", () => {
|
||||||
|
expect(normalizePhoneNumberForStore("")).toBe("");
|
||||||
|
expect(normalizePhoneNumberForStore(null)).toBe(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("saveProgressPopupContactToStore", () => {
|
describe("saveProgressPopupContactToStore", () => {
|
||||||
it("should save phone number and persist sms consent on phone tab", async () => {
|
it("should save phone number and persist sms consent on phone tab", async () => {
|
||||||
const dispatchStoreAction = jest.fn().mockResolvedValue(undefined);
|
const dispatchStoreAction = jest.fn().mockResolvedValue(undefined);
|
||||||
|
|
@ -42,7 +54,7 @@ describe("save-progress-popup-contact-helper", () => {
|
||||||
|
|
||||||
expect(dispatchStoreAction).toHaveBeenCalledWith(
|
expect(dispatchStoreAction).toHaveBeenCalledWith(
|
||||||
storeActions.SAVE_PHONE_NUMBER,
|
storeActions.SAVE_PHONE_NUMBER,
|
||||||
"555-123-4567",
|
"5551234567",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
expect(dispatchStoreAction).not.toHaveBeenCalledWith(
|
expect(dispatchStoreAction).not.toHaveBeenCalledWith(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue