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
88e91b3f
Commit
88e91b3f
authored
Jul 26, 2018
by
Tobias Skarhed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Begin conversion
parent
48d9b375
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
384 additions
and
0 deletions
+384
-0
public/app/plugins/panel/singlestat/specs/singlestat.jest.ts
+384
-0
No files found.
public/app/plugins/panel/singlestat/specs/singlestat.jest.ts
0 → 100644
View file @
88e91b3f
// import { describe, beforeEach, afterEach, it, sinon, expect, angularMocks } from 'test/lib/common';
// import helpers from 'test/specs/helpers';
import
{
SingleStatCtrl
}
from
'../module'
;
import
moment
from
'moment'
;
describe
(
'SingleStatCtrl'
,
function
()
{
let
ctx
=
<
any
>
{};
let
epoch
=
1505826363746
;
let
clock
;
let
$scope
=
{
$on
:
()
=>
{},
};
let
$injector
=
{
get
:
()
=>
{},
};
SingleStatCtrl
.
prototype
.
panel
=
{
events
:
{
on
:
()
=>
{},
emit
:
()
=>
{},
},
};
SingleStatCtrl
.
prototype
.
dashboard
=
{
isTimezoneUtc
:
()
=>
{},
};
function
singleStatScenario
(
desc
,
func
)
{
describe
(
desc
,
function
()
{
ctx
.
setup
=
function
(
setupFunc
)
{
// beforeEach(angularMocks.module('grafana.services'));
// beforeEach(angularMocks.module('grafana.controllers'));
// beforeEach(
// angularMocks.module(function($compileProvider) {
// $compileProvider.preAssignBindingsEnabled(true);
// })
// );
// beforeEach(ctx.providePhase());
// beforeEach(ctx.createPanelController(SingleStatCtrl));
beforeEach
(
function
()
{
ctx
.
ctrl
=
new
SingleStatCtrl
(
$scope
,
$injector
,
{});
setupFunc
();
ctx
.
ctrl
.
onDataReceived
(
ctx
.
data
);
ctx
.
data
=
ctx
.
ctrl
.
data
;
});
};
func
(
ctx
);
});
}
singleStatScenario
(
'with defaults'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
10
,
1
],
[
20
,
2
]]
}];
});
it
(
'Should use series avg as default main value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
15
);
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
15
);
});
it
(
'should set formatted falue'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'15'
);
});
});
singleStatScenario
(
'showing serie name instead of value'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
10
,
1
],
[
20
,
2
]]
}];
ctx
.
ctrl
.
panel
.
valueName
=
'name'
;
});
it
(
'Should use series avg as default main value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
0
);
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
0
);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'test.cpu1'
);
});
});
singleStatScenario
(
'showing last iso time instead of value'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
10
,
12
],
[
20
,
1505634997920
]]
}];
ctx
.
ctrl
.
panel
.
valueName
=
'last_time'
;
ctx
.
ctrl
.
panel
.
format
=
'dateTimeAsIso'
;
});
it
(
'Should use time instead of value'
,
function
()
{
console
.
log
(
ctx
.
data
.
value
);
expect
(
ctx
.
data
.
value
).
toBe
(
1505634997920
);
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
1505634997920
);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
moment
(
1505634997920
).
format
(
'YYYY-MM-DD HH:mm:ss'
));
});
});
singleStatScenario
(
'showing last iso time instead of value (in UTC)'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
10
,
12
],
[
20
,
1505634997920
]]
}];
ctx
.
ctrl
.
panel
.
valueName
=
'last_time'
;
ctx
.
ctrl
.
panel
.
format
=
'dateTimeAsIso'
;
// ctx.setIsUtc(true);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
moment
.
utc
(
1505634997920
).
format
(
'YYYY-MM-DD HH:mm:ss'
));
});
});
singleStatScenario
(
'showing last us time instead of value'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
10
,
12
],
[
20
,
1505634997920
]]
}];
ctx
.
ctrl
.
panel
.
valueName
=
'last_time'
;
ctx
.
ctrl
.
panel
.
format
=
'dateTimeAsUS'
;
});
it
(
'Should use time instead of value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
1505634997920
);
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
1505634997920
);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
moment
(
1505634997920
).
format
(
'MM/DD/YYYY h:mm:ss a'
));
});
});
singleStatScenario
(
'showing last us time instead of value (in UTC)'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
10
,
12
],
[
20
,
1505634997920
]]
}];
ctx
.
ctrl
.
panel
.
valueName
=
'last_time'
;
ctx
.
ctrl
.
panel
.
format
=
'dateTimeAsUS'
;
// ctx.setIsUtc(true);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
moment
.
utc
(
1505634997920
).
format
(
'MM/DD/YYYY h:mm:ss a'
));
});
});
singleStatScenario
(
'showing last time from now instead of value'
,
function
(
ctx
)
{
beforeEach
(()
=>
{
// clock = sinon.useFakeTimers(epoch);
jest
.
useFakeTimers
();
});
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
10
,
12
],
[
20
,
1505634997920
]]
}];
ctx
.
ctrl
.
panel
.
valueName
=
'last_time'
;
ctx
.
ctrl
.
panel
.
format
=
'dateTimeFromNow'
;
});
it
(
'Should use time instead of value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
1505634997920
);
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
1505634997920
);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'2 days ago'
);
});
afterEach
(()
=>
{
jest
.
clearAllTimers
();
});
});
singleStatScenario
(
'showing last time from now instead of value (in UTC)'
,
function
(
ctx
)
{
beforeEach
(()
=>
{
// clock = sinon.useFakeTimers(epoch);
jest
.
useFakeTimers
();
});
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
10
,
12
],
[
20
,
1505634997920
]]
}];
ctx
.
ctrl
.
panel
.
valueName
=
'last_time'
;
ctx
.
ctrl
.
panel
.
format
=
'dateTimeFromNow'
;
// ctx.setIsUtc(true);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'2 days ago'
);
});
afterEach
(()
=>
{
jest
.
clearAllTimers
();
});
});
singleStatScenario
(
'MainValue should use same number for decimals as displayed when checking thresholds'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
99.999
,
1
],
[
99.99999
,
2
]]
}];
});
it
(
'Should be rounded'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
99.999495
);
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
100
);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'100'
);
});
});
singleStatScenario
(
'When value to text mapping is specified'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
9.9
,
1
]]
}];
ctx
.
ctrl
.
panel
.
valueMaps
=
[{
value
:
'10'
,
text
:
'OK'
}];
});
it
(
'value should remain'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
9.9
);
});
it
(
'round should be rounded up'
,
function
()
{
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
10
);
});
it
(
'Should replace value with text'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'OK'
);
});
});
singleStatScenario
(
'When range to text mapping is specified for first range'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
41
,
50
]]
}];
ctx
.
ctrl
.
panel
.
mappingType
=
2
;
ctx
.
ctrl
.
panel
.
rangeMaps
=
[{
from
:
'10'
,
to
:
'50'
,
text
:
'OK'
},
{
from
:
'51'
,
to
:
'100'
,
text
:
'NOT OK'
}];
});
it
(
'Should replace value with text OK'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'OK'
);
});
});
singleStatScenario
(
'When range to text mapping is specified for other ranges'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
[{
target
:
'test.cpu1'
,
datapoints
:
[[
65
,
75
]]
}];
ctx
.
ctrl
.
panel
.
mappingType
=
2
;
ctx
.
ctrl
.
panel
.
rangeMaps
=
[{
from
:
'10'
,
to
:
'50'
,
text
:
'OK'
},
{
from
:
'51'
,
to
:
'100'
,
text
:
'NOT OK'
}];
});
it
(
'Should replace value with text NOT OK'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'NOT OK'
);
});
});
describe
(
'When table data'
,
function
()
{
const
tableData
=
[
{
columns
:
[{
text
:
'Time'
,
type
:
'time'
},
{
text
:
'test1'
},
{
text
:
'mean'
},
{
text
:
'test2'
}],
rows
:
[[
1492759673649
,
'ignore1'
,
15
,
'ignore2'
]],
type
:
'table'
,
},
];
singleStatScenario
(
'with default values'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
});
it
(
'Should use first rows value as default main value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
15
);
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
15
);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'15'
);
});
});
singleStatScenario
(
'When table data has multiple columns'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
ctrl
.
panel
.
tableColumn
=
''
;
});
it
(
'Should set column to first column that is not time'
,
function
()
{
expect
(
ctx
.
ctrl
.
panel
.
tableColumn
).
toBe
(
'test1'
);
});
});
singleStatScenario
(
'MainValue should use same number for decimals as displayed when checking thresholds'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
99.99999
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
});
it
(
'Should be rounded'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
99.99999
);
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
100
);
});
it
(
'should set formatted falue'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'100'
);
});
});
singleStatScenario
(
'When value to text mapping is specified'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
9.9
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
ctx
.
ctrl
.
panel
.
valueMaps
=
[{
value
:
'10'
,
text
:
'OK'
}];
});
it
(
'value should remain'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
9.9
);
});
it
(
'round should be rounded up'
,
function
()
{
expect
(
ctx
.
data
.
valueRounded
).
toBe
(
10
);
});
it
(
'Should replace value with text'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'OK'
);
});
});
singleStatScenario
(
'When range to text mapping is specified for first range'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
41
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
ctx
.
ctrl
.
panel
.
mappingType
=
2
;
ctx
.
ctrl
.
panel
.
rangeMaps
=
[{
from
:
'10'
,
to
:
'50'
,
text
:
'OK'
},
{
from
:
'51'
,
to
:
'100'
,
text
:
'NOT OK'
}];
});
it
(
'Should replace value with text OK'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'OK'
);
});
});
singleStatScenario
(
'When range to text mapping is specified for other ranges'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
65
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
ctx
.
ctrl
.
panel
.
mappingType
=
2
;
ctx
.
ctrl
.
panel
.
rangeMaps
=
[{
from
:
'10'
,
to
:
'50'
,
text
:
'OK'
},
{
from
:
'51'
,
to
:
'100'
,
text
:
'NOT OK'
}];
});
it
(
'Should replace value with text NOT OK'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'NOT OK'
);
});
});
singleStatScenario
(
'When value is string'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
65
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'test1'
;
});
it
(
'Should replace value with text NOT OK'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
toBe
(
'ignore1'
);
});
});
singleStatScenario
(
'When value is zero'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
0
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
});
it
(
'Should return zero'
,
function
()
{
expect
(
ctx
.
data
.
value
).
toBe
(
0
);
});
});
});
});
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