import { toTitleCase, toDisplayPhoneNumber, formatAddress, formatAmountInDollars, createOrderedListFromStringOfParagraphs } from '@/helpers/text-helper.js'; describe('text-helper', () => { test.each([ [undefined, ''], [null, ''], ['', ''], ['hello world', 'Hello World'], ['hello world', 'Hello World'], ['HEllO worLD', 'Hello World'], ['a991,,:A froG FAMILY', 'A991,,:a Frog Family'] ])( 'toTitleCase given "%p" returns "%p"', (input, expected) => { // Act const result = toTitleCase(input); // Assert expect(result).toEqual(expected); } ); test.each([ [undefined, ''], [null, ''], ['', ''], ['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'] ])( 'getDisplayPhoneNumber', (input, expected) => { // Act const result = toDisplayPhoneNumber(input); // Assert expect(result).toEqual(expected); } ); test.each([ [null, null, null, null, null, ''], ['123 Main St', null, null, null, null, '123 Main St'], ['123 main st', 'Apt 4B', null, null, null, '123 Main St, Apt 4b'], ['123 Main St', 'apt 4B', 'Anytown', null, null, '123 Main St, Apt 4b, Anytown'], ['123 Main St', 'Apt 4B', 'Anytown', 'ny', null, '123 Main St, Apt 4b, Anytown, ny'], ['123 Main St', 'Apt 4B', 'AnYtoWn', 'NY', '12345', '123 Main St, Apt 4b, Anytown, NY 12345'] ])('formatAddress(%s, %s, %s, %s, %s) should return %s', (addressLine1, addressLine2, city, state, zipCode, expected) => { expect(formatAddress(addressLine1, addressLine2, city, state, zipCode)).toBe(expected); }); test.each([ [1234.5678, '$1,234.57'], ['1234.5678', '$1,234.57'], [1234.56, '$1,234.56'], ['1234.56', '$1,234.56'], [1234.5, '$1,234.50'], ['1234.5', '$1,234.50'], [1234, '$1,234.00'], ['1234', '$1,234.00'], [0, '$0.00'], ['0', '$0.00'], [NaN, ''], ['NaN', ''], [null, ''], ['', ''], ['abc', ''] ])('formatAmountInDollars(%s) should return %s', (amount, expected) => { expect(formatAmountInDollars(amount)).toBe(expected); }); describe('createOrderedListFromStringOfParagraphs', () => { test('returns orderedlist from paragraph string', () => { // Arrange const testData = '

String one

String two

'; const expected = '
  1. String one
  2. String two
'; // Assert expect(createOrderedListFromStringOfParagraphs(testData)).toBe(expected); }); test('returns orderedlist from paragraph string with empty

tag', () => { // Arrange const testData = '

String one

String two

'; const expected = '
  1. String one
  2. String two
'; // Assert expect(createOrderedListFromStringOfParagraphs(testData)).toBe(expected); }); }); });