Added first real test

This commit is contained in:
Arnaud Vergnet 2020-03-20 22:50:28 +01:00
parent 96c9b57d92
commit a4c38168ad
3 changed files with 20 additions and 11 deletions

View file

@ -11,7 +11,8 @@
"testc": "jest --coverage" "testc": "jest --coverage"
}, },
"jest": { "jest": {
"preset": "react-native" "preset": "react-native",
"setupFilesAfterEnv": ["jest-extended"]
}, },
"dependencies": { "dependencies": {
"@expo/vector-icons": "~10.0.0", "@expo/vector-icons": "~10.0.0",
@ -46,6 +47,7 @@
"devDependencies": { "devDependencies": {
"babel-preset-expo": "^8.0.0", "babel-preset-expo": "^8.0.0",
"jest": "^25.1.0", "jest": "^25.1.0",
"jest-extended": "^0.11.5",
"react-test-renderer": "^16.13.1" "react-test-renderer": "^16.13.1"
}, },
"private": true "private": true

View file

@ -74,10 +74,12 @@ export default class PlanningEventManager {
} }
static isDescriptionEmpty (description: string) { static isDescriptionEmpty (description: string) {
return description if (description !== undefined && description !== null) {
.replace('<p>', '') return description
.replace('</p>', '') .replace('<p>', '')
.replace('<br>', '').trim() === ''; .replace('</p>', '')
.replace('<br>', '').trim() === '';
} else
return true;
} }
} }

View file

@ -1,10 +1,15 @@
import React from 'react'; import React from 'react';
import PlanningEventManager from "../PlanningEventManager"; import PlanningEventManager from "../PlanningEventManager";
test('time test', () => { test('isDescriptionEmpty', () => {
expect(PlanningEventManager.formatTime("1:2")).toBe("1:2"); expect(PlanningEventManager.isDescriptionEmpty("")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p></p>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p><br></p>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("<p><br>")).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty(null)).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty(undefined)).toBeTrue();
expect(PlanningEventManager.isDescriptionEmpty("coucou")).toBeFalse();
expect(PlanningEventManager.isDescriptionEmpty("<p>coucou</p>")).toBeFalse();
}); });
test('time test 2', () => {
expect(PlanningEventManager.formatTime("1:2")).toBe("2:2");
});