Dashboard: time range can now be read from URL parameters, will override dashboard saved time range, Closes #787, Closes #761

This commit is contained in:
Torkel Ödegaard
2014-09-10 10:46:04 +02:00
parent 6022784e42
commit 682d2a1675
3 changed files with 74 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ define([
var _dashboard;
beforeEach(module('grafana.services'));
beforeEach(ctx.providePhase());
beforeEach(ctx.providePhase(['$routeParams']));
beforeEach(ctx.createService('timeSrv'));
beforeEach(function() {
@@ -35,6 +35,45 @@ define([
});
});
describe('init time from url', function() {
it('should handle relative times', function() {
ctx.$routeParams.from = 'now-2d';
ctx.$routeParams.to = 'now';
ctx.service.init(_dashboard);
var time = ctx.service.timeRange(false);
expect(time.from).to.be('now-2d');
expect(time.to).to.be('now');
});
it('should handle formated dates', function() {
ctx.$routeParams.from = '20140410T052010';
ctx.$routeParams.to = '20140520T031022';
ctx.service.init(_dashboard);
var time = ctx.service.timeRange(true);
expect(time.from.getTime()).to.equal(new Date("2014-04-10T05:20:10Z").getTime());
expect(time.to.getTime()).to.equal(new Date("2014-05-20T03:10:22Z").getTime());
});
it('should handle formated dates without time', function() {
ctx.$routeParams.from = '20140410';
ctx.$routeParams.to = '20140520';
ctx.service.init(_dashboard);
var time = ctx.service.timeRange(true);
expect(time.from.getTime()).to.equal(new Date("2014-04-10T00:00:00Z").getTime());
expect(time.to.getTime()).to.equal(new Date("2014-05-20T00:00:00Z").getTime());
});
it('should handle epochs', function() {
ctx.$routeParams.from = '1410337646373';
ctx.$routeParams.to = '1410337665699';
ctx.service.init(_dashboard);
var time = ctx.service.timeRange(true);
expect(time.from.getTime()).to.equal(1410337646373);
expect(time.to.getTime()).to.equal(1410337665699);
});
});
describe('setTime', function() {
it('should return disable refresh for absolute times', function() {
_dashboard.refresh = false;