Closed oddball-lindsay closed 1 month ago
@cosu419
Hey Colin - I just added a bunch of unit tests to that PR - https://github.com/department-of-veterans-affairs/vets-website/pull/32029
I moved a bunch of functions from the component pages into the helpers.js file so they can easily be tested (and to dry some things up).
This spec file is failing locally - src/applications/representative-appoint/tests/components/ContactCard.unit.spec.jsx
I think it’s because of that strange issue with this import (we talked about it):
import { parsePhoneNumber } from '../utilities/helpers';
Would you mind handling this for me? I have one more silent failures thing to do, but I want to checkout for my vacation.
Yes, when I create this file - src/applications/representative-appoint/utilities/parsePhoneNumber.js
const parsePhoneNumber = phone => {
if (!phone) {
return { contact: null, extension: null };
}
let sanitizedNumber = phone
.replace(/[()\s]/g, '') // remove parentheses
.replace(/(?<=.)([+.*])/g, '-'); // replace .*+ symbols being used as dashes
// return null for non-US country codes
if (sanitizedNumber.match(/\+(\d+)[^\d1]/g)) {
return { contact: null, extension: null };
}
// remove US country codes +1 or 1
sanitizedNumber = sanitizedNumber.replace(/^(\+1|1)\s*/, '');
// capture first 10 digits + ext if applicable
const parserRegex = /^(\d{10})(\D*?(\d+))?/;
const contact = sanitizedNumber.replace(/-/g, '').replace(parserRegex, '$1');
const extension =
sanitizedNumber
.replace(/-/g, '')
.replace(parserRegex, '$3')
.replace(/\D/g, '') || null;
const isValidContactNumberRegex = /^(?:[2-9]\d{2})[2-9]\d{2}\d{4}$/;
if (isValidContactNumberRegex.test(contact)) {
return { contact, extension };
}
return { contact: null, extension: null };
};
export default parsePhoneNumber;
And change the import in src/applications/representative-appoint/components/ContactCard.jsx
to import parsePhoneNumber from '../utilities/parsePhoneNumber';
the tests pass. So weird.
Thanks!
Background
When a user clicks "Continue" on the download page, we ned to make a request to VA Notify to send a confirmation email.
Related work:
Tasks
Acceptance Criteria