mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 17:15:40 -06:00
feat(timepicker2): fixed timesrv specs
This commit is contained in:
parent
4c79591403
commit
5ad38ee9f8
@ -30,10 +30,10 @@ define([
|
||||
this._parseTime = function() {
|
||||
// when absolute time is saved in json it is turned to a string
|
||||
if (_.isString(this.time.from) && this.time.from.indexOf('Z') >= 0) {
|
||||
this.time.from = new Date(this.time.from);
|
||||
this.time.from = moment(this.time.from);
|
||||
}
|
||||
if (_.isString(this.time.to) && this.time.to.indexOf('Z') >= 0) {
|
||||
this.time.to = new Date(this.time.to);
|
||||
this.time.to = moment(this.time.to);
|
||||
}
|
||||
};
|
||||
|
||||
@ -113,8 +113,8 @@ define([
|
||||
range = this.timeRange();
|
||||
}
|
||||
|
||||
if (_.isDate(range.from)) { range.from = range.from.getTime(); }
|
||||
if (_.isDate(range.to)) { range.to = range.to.getTime(); }
|
||||
if (moment.isMoment(range.from)) { range.from = range.from.valueOf(); }
|
||||
if (moment.isMoment(range.to)) { range.to = range.to.valueOf(); }
|
||||
|
||||
return range;
|
||||
};
|
||||
|
@ -2,9 +2,10 @@ define([
|
||||
'../mocks/dashboard-mock',
|
||||
'./helpers',
|
||||
'lodash',
|
||||
'moment',
|
||||
'app/services/timer',
|
||||
'app/features/dashboard/timeSrv'
|
||||
], function(dashboardMock, helpers, _) {
|
||||
], function(dashboardMock, helpers, _, moment) {
|
||||
'use strict';
|
||||
|
||||
describe('timeSrv', function() {
|
||||
@ -31,8 +32,8 @@ define([
|
||||
it('should return parsed when parse is true', function() {
|
||||
ctx.service.setTime({from: 'now', to: 'now-1h' });
|
||||
var time = ctx.service.timeRange(true);
|
||||
expect(_.isDate(time.from)).to.be(true);
|
||||
expect(_.isDate(time.to)).to.be(true);
|
||||
expect(moment.isMoment(time.from)).to.be(true);
|
||||
expect(moment.isMoment(time.to)).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
@ -51,8 +52,8 @@ define([
|
||||
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());
|
||||
expect(time.from.valueOf()).to.equal(new Date("2014-04-10T05:20:10Z").getTime());
|
||||
expect(time.to.valueOf()).to.equal(new Date("2014-05-20T03:10:22Z").getTime());
|
||||
});
|
||||
|
||||
it('should handle formated dates without time', function() {
|
||||
@ -60,8 +61,8 @@ define([
|
||||
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());
|
||||
expect(time.from.valueOf()).to.equal(new Date("2014-04-10T00:00:00Z").getTime());
|
||||
expect(time.to.valueOf()).to.equal(new Date("2014-05-20T00:00:00Z").getTime());
|
||||
});
|
||||
|
||||
it('should handle epochs', function() {
|
||||
@ -69,8 +70,8 @@ define([
|
||||
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);
|
||||
expect(time.from.valueOf()).to.equal(1410337646373);
|
||||
expect(time.to.valueOf()).to.equal(1410337665699);
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user