Improved test and replace method

This commit is contained in:
Arnaud Vergnet 2020-03-21 11:24:30 +01:00
parent a4c38168ad
commit df79d78165
2 changed files with 8 additions and 4 deletions

View file

@ -73,12 +73,12 @@ export default class PlanningEventManager {
return formattedStr return formattedStr
} }
static isDescriptionEmpty (description: string) { static isDescriptionEmpty (description: ?string) {
if (description !== undefined && description !== null) { if (description !== undefined && description !== null) {
return description return description
.replace('<p>', '') .split('<p>').join('') // Equivalent to a replace all
.replace('</p>', '') .split('</p>').join('')
.replace('<br>', '').trim() === ''; .split('<br>').join('').trim() === '';
} else } else
return true; return true;
} }

View file

@ -3,8 +3,12 @@ import PlanningEventManager from "../PlanningEventManager";
test('isDescriptionEmpty', () => { test('isDescriptionEmpty', () => {
expect(PlanningEventManager.isDescriptionEmpty("")).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty("")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty(" ")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p></p>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p> </p>")).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty("<p> </p>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p><br></p>")).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty("<p><br></p>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p><br></p><p><br></p>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p><br><br><br></p>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p><br>")).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty("<p><br>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty(null)).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty(null)).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty(undefined)).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty(undefined)).toBeTrue();