diff --git a/src/layouts/tpa-search/tpa-search.spec.js b/src/layouts/tpa-search/tpa-search.spec.js index de95fdb8..f1f5c412 100644 --- a/src/layouts/tpa-search/tpa-search.spec.js +++ b/src/layouts/tpa-search/tpa-search.spec.js @@ -745,7 +745,7 @@ describe('TPA search page', () => { }); describe('watch', () => { // TODO update/add to filter watch tests - test.only('on filter calls getTpaProviders and sets providers', async () => { + test('on filter calls getTpaProviders and sets providers', async () => { // Arrange const zipCode = '78220'; const initialMapZipCode = '88800'; @@ -1197,18 +1197,41 @@ describe('TPA search page', () => { [undefined, ''], [null, ''], ['', ''], - ['hello world', 'Hello World'], - ['hello world', 'Hello World'], - ['HEllO worLD', 'Hello World'], - ['a991,,:A froG FAMILY', 'A991,,:a Frog Family'] + ['119', ''], + ['1111999900', '111-199-9900'], + ['111199-9900', '111-199-9900'], + ['111-199-9900', '111-199-9900'], + ['01111999900', '0-111-199-9900'], + ['0-111-199-9900', '0-111-199-9900'] ])( - 'toTitleCase given "%p" returns "%p"', + 'getDisplayPhoneNumber', (input, expected) => { // Arrange const { wrapper } = getMountedComponent(); // Act - const result = wrapper.vm.toTitleCase(input); + const result = wrapper.vm.getDisplayPhoneNumber(input); + + // Assert + expect(result).toEqual(expected); + } + ); + test.each([ + [undefined, ''], + [null, ''], + ['', ''], + ['hello world', 'Hello World'], + ['hello world', 'Hello World'], + ['HEllO worLD', 'Hello World'], + ['a991,,:A froG FAMILY', 'A991,,:a Frog Family'] + ])( + 'getTitleCase given "%p" returns "%p"', + (input, expected) => { + // Arrange + const { wrapper } = getMountedComponent(); + + // Act + const result = wrapper.vm.getTitleCase(input); // Assert expect(result).toEqual(expected); diff --git a/src/layouts/tpa-search/tpa-search.vue b/src/layouts/tpa-search/tpa-search.vue index f35ee59f..8eb12c90 100644 --- a/src/layouts/tpa-search/tpa-search.vue +++ b/src/layouts/tpa-search/tpa-search.vue @@ -296,7 +296,7 @@ export default { this.providers = providers; }, getProviderAddress(provider) { - const city = this.toTitleCase(provider?.address?.city); + const city = this.getTitleCase(provider?.address?.city); const state = provider?.address?.state ?? ''; const zipCode = provider?.address?.zipCode ?? ''; let addressLine2 = ''; @@ -314,7 +314,7 @@ export default { addressLine2 += zipCode; } - const addressLine1 = this.toTitleCase(provider?.address?.streetAddress); + const addressLine1 = this.getTitleCase(provider?.address?.streetAddress); const joinString = addressLine1.length > 0 && addressLine2.length > 0 ? ', ' : ''; return [addressLine1, addressLine2].join(joinString); }, @@ -369,17 +369,18 @@ export default { getDisplayPhoneNumber(phoneNumber) { let result = ''; if (!phoneNumber) { return result; } - let remainingDigits = phoneNumber; - if (phoneNumber.length === 11) { + let remainingDigits = phoneNumber.match(/\d+/g).join(''); + console.log(remainingDigits); + if (remainingDigits.length === 11) { result += `${remainingDigits[0]}-`; remainingDigits = remainingDigits.substring(1); } - if (phoneNumber.length > 9) { + if (remainingDigits.length === 10) { result += remainingDigits.replace(/^(\d{3})(\d{3})(\d{4})/, '$1-$2-$3'); } return result; }, - toTitleCase(text) { + getTitleCase(text) { if ((text?.length ?? 0) === 0) { return ''; }