Merge pull request #850 from Safelite/feature/richardson/SSR-1466

Fix for empty p tag
This commit is contained in:
brich1212safe 2024-09-20 15:53:27 -04:00 committed by GitHub
commit 270d5b95cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 7 deletions

View file

@ -18,7 +18,7 @@ export function stripRteStyle(stringWithStyleTag) {
* @returns {string} converted string wrapped in an <ol>
*/
export function createOrderedListFromStringOfParagraphs(stringOfParagraphs) {
return `<ol>${stringOfParagraphs.replaceAll('<p>', '<li>').replaceAll('</p>', '</li>')}</ol>`;
return `<ol>${stringOfParagraphs.replaceAll('<p></p>', '').replaceAll('<p>', '<li>').replaceAll('</p>', '</li>')}</ol>`;
}
/**

View file

@ -74,12 +74,23 @@ describe('text-helper', () => {
])('formatAmountInDollars(%s) should return %s', (amount, expected) => {
expect(formatAmountInDollars(amount)).toBe(expected);
});
test('returns orderedlist from paragraph string', () => {
// Arrange
const testData = '<p>String one</p><p>String two</p>';
const expected = '<ol><li>String one</li><li>String two</li></ol>';
describe('createOrderedListFromStringOfParagraphs', () => {
test('returns orderedlist from paragraph string', () => {
// Arrange
const testData = '<p>String one</p><p>String two</p>';
const expected = '<ol><li>String one</li><li>String two</li></ol>';
// Assert
expect(createOrderedListFromStringOfParagraphs(testData)).toBe(expected);
// Assert
expect(createOrderedListFromStringOfParagraphs(testData)).toBe(expected);
});
test('returns orderedlist from paragraph string with empty <p> tag', () => {
// Arrange
const testData = '<p>String one</p><p>String two</p><p></p>';
const expected = '<ol><li>String one</li><li>String two</li></ol>';
// Assert
expect(createOrderedListFromStringOfParagraphs(testData)).toBe(expected);
});
});
});