From df79d78165ccaa207f140c5e8415744c04d35e4f Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sat, 21 Mar 2020 11:24:30 +0100 Subject: [PATCH] Improved test and replace method --- utils/PlanningEventManager.js | 8 ++++---- utils/__test__/PlanningEventManager.test.js | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/PlanningEventManager.js b/utils/PlanningEventManager.js index db67157..52d53e2 100644 --- a/utils/PlanningEventManager.js +++ b/utils/PlanningEventManager.js @@ -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('

', '') - .replace('

', '') - .replace('
', '').trim() === ''; + .split('

').join('') // Equivalent to a replace all + .split('

').join('') + .split('
').join('').trim() === ''; } else return true; } diff --git a/utils/__test__/PlanningEventManager.test.js b/utils/__test__/PlanningEventManager.test.js index 8451850..6c30d50 100644 --- a/utils/__test__/PlanningEventManager.test.js +++ b/utils/__test__/PlanningEventManager.test.js @@ -3,8 +3,12 @@ import PlanningEventManager from "../PlanningEventManager"; test('isDescriptionEmpty', () => { expect(PlanningEventManager.isDescriptionEmpty("")).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty(" ")).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty("

")).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty("

")).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty("


")).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty("



")).toBeTrue(); + expect(PlanningEventManager.isDescriptionEmpty("




")).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty("


")).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty(null)).toBeTrue(); expect(PlanningEventManager.isDescriptionEmpty(undefined)).toBeTrue();