forked from vergnet/application-amicale
Improved test and replace method
This commit is contained in:
parent
a4c38168ad
commit
df79d78165
2 changed files with 8 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue