Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
b4bca473
Commit
b4bca473
authored
Oct 13, 2018
by
Francisco Guimarães
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding tests
parent
3db5d142
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
2 deletions
+75
-2
public/app/core/specs/kbn.test.ts
+71
-0
public/app/core/utils/kbn.ts
+4
-2
No files found.
public/app/core/specs/kbn.test.ts
View file @
b4bca473
...
...
@@ -399,6 +399,77 @@ describe('duration', () => {
});
});
describe
(
'clock'
,
()
=>
{
it
(
'null'
,
()
=>
{
const
str
=
kbn
.
toClock
(
null
,
0
);
expect
(
str
).
toBe
(
''
);
});
it
(
'size less than 1 second'
,
()
=>
{
const
str
=
kbn
.
toClock
(
999
,
0
);
expect
(
str
).
toBe
(
'999ms'
);
});
describe
(
'size less than 1 minute'
,
()
=>
{
it
(
'default'
,
()
=>
{
const
str
=
kbn
.
toClock
(
59999
);
expect
(
str
).
toBe
(
'59s:999ms'
);
});
it
(
'decimals equals 0'
,
()
=>
{
const
str
=
kbn
.
toClock
(
59999
,
0
);
expect
(
str
).
toBe
(
'59s'
);
});
});
describe
(
'size less than 1 hour'
,
()
=>
{
it
(
'default'
,
()
=>
{
const
str
=
kbn
.
toClock
(
3599999
);
expect
(
str
).
toBe
(
'59m:59s:999ms'
);
});
it
(
'decimals equals 0'
,
()
=>
{
const
str
=
kbn
.
toClock
(
3599999
,
0
);
expect
(
str
).
toBe
(
'59m'
);
});
it
(
'decimals equals 1'
,
()
=>
{
const
str
=
kbn
.
toClock
(
3599999
,
1
);
expect
(
str
).
toBe
(
'59m:59s'
);
});
});
describe
(
'size greater than or equal 1 hour'
,
()
=>
{
it
(
'default'
,
()
=>
{
const
str
=
kbn
.
toClock
(
7199999
);
expect
(
str
).
toBe
(
'01h:59m:59s:999ms'
);
});
it
(
'decimals equals 0'
,
()
=>
{
const
str
=
kbn
.
toClock
(
7199999
,
0
);
expect
(
str
).
toBe
(
'01h'
);
});
it
(
'decimals equals 1'
,
()
=>
{
const
str
=
kbn
.
toClock
(
7199999
,
1
);
expect
(
str
).
toBe
(
'01h:59m'
);
});
it
(
'decimals equals 2'
,
()
=>
{
const
str
=
kbn
.
toClock
(
7199999
,
2
);
expect
(
str
).
toBe
(
'01h:59m:59s'
);
});
});
describe
(
'size greater than or equal 1 day'
,
()
=>
{
it
(
'default'
,
()
=>
{
const
str
=
kbn
.
toClock
(
89999999
);
expect
(
str
).
toBe
(
'24h:59m:59s:999ms'
);
});
it
(
'decimals equals 0'
,
()
=>
{
const
str
=
kbn
.
toClock
(
89999999
,
0
);
expect
(
str
).
toBe
(
'24h'
);
});
it
(
'decimals equals 1'
,
()
=>
{
const
str
=
kbn
.
toClock
(
89999999
,
1
);
expect
(
str
).
toBe
(
'24h:59m'
);
});
it
(
'decimals equals 2'
,
()
=>
{
const
str
=
kbn
.
toClock
(
89999999
,
2
);
expect
(
str
).
toBe
(
'24h:59m:59s'
);
});
});
});
describe
(
'volume'
,
()
=>
{
it
(
'1000m3'
,
()
=>
{
const
str
=
kbn
.
valueFormats
[
'm3'
](
1000
,
1
,
null
);
...
...
public/app/core/utils/kbn.ts
View file @
b4bca473
...
...
@@ -809,7 +809,9 @@ kbn.toDuration = (size, decimals, timeScale) => {
};
kbn.toClock = (size, decimals) => {
console.log(`size ${JSON.stringify(size, null, 2)}`);
if (size === null) {
return '';
}
// < 1 second
if (size < 1000) {
...
...
@@ -838,7 +840,7 @@ kbn.toClock = (size, decimals) => {
let format = '
mm
\\
m
:
ss
\\
s
:
SSS
\\
m
\\
s
';
const hours =
('
0
' + Math.floor(moment.duration(size, '
milliseconds
').asHours())).slice(-2)
;
const hours =
`${('
0
' + Math.floor(moment.duration(size, '
milliseconds
').asHours())).slice(-2)}h`
;
if (decimals === 0) {
format = '';
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment