diff --git a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js index 525f1bbd238e9ef97728efb13e531aecd9a7c43b..7b062a66fd96666e0db6132906434c06381a72e1 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js @@ -104,8 +104,11 @@ export const UnitConverter = { return seconds; }, getSecsToHrsWithFractionDigits: function (seconds, fractionDigits = 2) { + if (seconds===null ){ + return 0; + } if (typeof seconds !== "number" || isNaN(seconds)) { - throw TypeError("Cannot convert a wrong value. Must be a number") + return "0?"; } return (seconds / 3600).toFixed(fractionDigits) }, diff --git a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.test.js b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.test.js index c48d61acda20b9d220dc3b331708c6bd833eb3a0..daaffdeb8e262e8deb2fd4216e4fba683f2f2212 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.test.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.test.js @@ -60,9 +60,7 @@ describe('getSecsToHrsWithFractionDigits', () => { it('should handle zero seconds', () => { const seconds = 0; - const result = UnitConverter.getSecsToHrsWithFractionDigits(seconds); - expect(result).toBe('0.00'); }); @@ -74,10 +72,15 @@ describe('getSecsToHrsWithFractionDigits', () => { expect(result).toBe('-0.37'); }); - test.each(["12", null, undefined, []])('Should log an error and return "Invalid" for wrong input: %s', (wrongSeconds) => { + test.each(["12", undefined, "aa"])('Should handle invalid data with 0? for wrong input: %s', (wrongSeconds) => { + const result = UnitConverter.getSecsToHrsWithFractionDigits(wrongSeconds); + expect(result).toBe('0?'); + }); - expect(() => { - UnitConverter.getSecsToHrsWithFractionDigits(wrongSeconds); - }).toThrow(TypeError) - }) + + it('should handle null with 0', () => { + const wrongSeconds = null; + const result = UnitConverter.getSecsToHrsWithFractionDigits(wrongSeconds); + expect(result).toBe(0); + }); }); \ No newline at end of file