mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Added spec tests for millisecond resolution
This commit is contained in:
@@ -170,8 +170,8 @@ export default class TimeSeries {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isMsResolutionNeeded() {
|
isMsResolutionNeeded() {
|
||||||
for (var j = 0; j<this.datapoints.length; j++) {
|
for (var i = 0; i<this.datapoints.length; i++) {
|
||||||
var timestamp = this.datapoints[j][1].toString();
|
var timestamp = this.datapoints[i][0].toString();
|
||||||
if (timestamp.length === 13 && parseInt(timestamp.substring(10,13)) !== 0) {
|
if (timestamp.length === 13 && parseInt(timestamp.substring(10,13)) !== 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,59 @@ describe('GraphCtrl', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('msResolution with second resolution timestamps', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
|
||||||
|
data: [
|
||||||
|
{ target: 'test.cpu1', datapoints: [[1234567890, 45], [1234567899, 60]]},
|
||||||
|
{ target: 'test.cpu2', datapoints: [[1236547890, 55], [1234456709, 90]]}
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
ctx.ctrl.panel.tooltip.msResolution = false;
|
||||||
|
ctx.ctrl.refreshData(ctx.datasource);
|
||||||
|
ctx.scope.$digest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show millisecond resolution tooltip', function() {
|
||||||
|
expect(ctx.ctrl.panel.tooltip.msResolution).to.be(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('msResolution with millisecond resolution timestamps', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
|
||||||
|
data: [
|
||||||
|
{ target: 'test.cpu1', datapoints: [[1234567890000, 45], [1234567899000, 60]]},
|
||||||
|
{ target: 'test.cpu2', datapoints: [[1236547890001, 55], [1234456709000, 90]]}
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
ctx.ctrl.panel.tooltip.msResolution = false;
|
||||||
|
ctx.ctrl.refreshData(ctx.datasource);
|
||||||
|
ctx.scope.$digest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show millisecond resolution tooltip', function() {
|
||||||
|
expect(ctx.ctrl.panel.tooltip.msResolution).to.be(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('msResolution with millisecond resolution timestamps but with trailing zeroes', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
|
||||||
|
data: [
|
||||||
|
{ target: 'test.cpu1', datapoints: [[1234567890000, 45], [1234567899000, 60]]},
|
||||||
|
{ target: 'test.cpu2', datapoints: [[1236547890000, 55], [1234456709000, 90]]}
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
ctx.ctrl.panel.tooltip.msResolution = false;
|
||||||
|
ctx.ctrl.refreshData(ctx.datasource);
|
||||||
|
ctx.scope.$digest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show millisecond resolution tooltip', function() {
|
||||||
|
expect(ctx.ctrl.panel.tooltip.msResolution).to.be(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -323,5 +323,27 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Formatting epoch timestamp when timezone is set as utc', function() {
|
||||||
|
var dashboard;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
dashboard = _dashboardSrv.create({
|
||||||
|
timezone: 'utc',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should format timestamp with second resolution by default', function() {
|
||||||
|
expect(dashboard.formatDate(1234567890000)).to.be('2009-02-13 23:31:30');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should format timestamp with second resolution even if second format is passed as parameter', function() {
|
||||||
|
expect(dashboard.formatDate(1234567890007,'YYYY-MM-DD HH:mm:ss')).to.be('2009-02-13 23:31:30');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should format timestamp with millisecond resolution if format is passed as parameter', function() {
|
||||||
|
expect(dashboard.formatDate(1234567890007,'YYYY-MM-DD HH:mm:ss.SSS')).to.be('2009-02-13 23:31:30.007');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user