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
}
static isDescriptionEmpty (description: string) {
static isDescriptionEmpty (description: ?string) {
if (description !== undefined && description !== null) {
return description
.replace('<p>', '')
.replace('</p>', '')
.replace('<br>', '').trim() === '';
.split('<p>').join('') // Equivalent to a replace all
.split('</p>').join('')
.split('<br>').join('').trim() === '';
} else
return true;
}

View file

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