Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
d1ab3eb7
Commit
d1ab3eb7
authored
1 year ago
by
Reinder Kraaij
Browse files
Options
Downloads
Patches
Plain Diff
When something is null , it's nothing and thus 0
parent
3bc51444
No related branches found
No related tags found
1 merge request
!1207
When something is null , it's nothing and thus 0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js
+4
-1
4 additions, 1 deletion
SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js
SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.test.js
+10
-7
10 additions, 7 deletions
...MSS/frontend/tmss_webapp/src/utils/unit.converter.test.js
with
14 additions
and
8 deletions
SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js
+
4
−
1
View file @
d1ab3eb7
...
@@ -104,8 +104,11 @@ export const UnitConverter = {
...
@@ -104,8 +104,11 @@ export const UnitConverter = {
return
seconds
;
return
seconds
;
},
},
getSecsToHrsWithFractionDigits
:
function
(
seconds
,
fractionDigits
=
2
)
{
getSecsToHrsWithFractionDigits
:
function
(
seconds
,
fractionDigits
=
2
)
{
if
(
seconds
===
null
){
return
0
;
}
if
(
typeof
seconds
!==
"
number
"
||
isNaN
(
seconds
))
{
if
(
typeof
seconds
!==
"
number
"
||
isNaN
(
seconds
))
{
throw
TypeError
(
"
Cannot convert a wrong value. Must be a number
"
)
return
"
0?
"
;
}
}
return
(
seconds
/
3600
).
toFixed
(
fractionDigits
)
return
(
seconds
/
3600
).
toFixed
(
fractionDigits
)
},
},
...
...
This diff is collapsed.
Click to expand it.
SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.test.js
+
10
−
7
View file @
d1ab3eb7
...
@@ -60,9 +60,7 @@ describe('getSecsToHrsWithFractionDigits', () => {
...
@@ -60,9 +60,7 @@ describe('getSecsToHrsWithFractionDigits', () => {
it
(
'
should handle zero seconds
'
,
()
=>
{
it
(
'
should handle zero seconds
'
,
()
=>
{
const
seconds
=
0
;
const
seconds
=
0
;
const
result
=
UnitConverter
.
getSecsToHrsWithFractionDigits
(
seconds
);
const
result
=
UnitConverter
.
getSecsToHrsWithFractionDigits
(
seconds
);
expect
(
result
).
toBe
(
'
0.00
'
);
expect
(
result
).
toBe
(
'
0.00
'
);
});
});
...
@@ -74,10 +72,15 @@ describe('getSecsToHrsWithFractionDigits', () => {
...
@@ -74,10 +72,15 @@ describe('getSecsToHrsWithFractionDigits', () => {
expect
(
result
).
toBe
(
'
-0.37
'
);
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
);
it
(
'
should handle null with 0
'
,
()
=>
{
}).
toThrow
(
TypeError
)
const
wrongSeconds
=
null
;
})
const
result
=
UnitConverter
.
getSecsToHrsWithFractionDigits
(
wrongSeconds
);
expect
(
result
).
toBe
(
0
);
});
});
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment