2015-09-17 02:44:51 -05:00
|
|
|
import {describe, beforeEach, it, sinon, expect} from 'test/lib/common'
|
|
|
|
|
|
|
|
import rangeUtil = require('app/core/utils/rangeutil')
|
|
|
|
import _ = require('lodash')
|
|
|
|
import moment = require('moment')
|
|
|
|
|
2015-09-18 08:06:08 -05:00
|
|
|
describe("rangeUtil", () => {
|
2015-09-17 02:44:51 -05:00
|
|
|
|
2015-09-19 05:20:24 -05:00
|
|
|
describe("Can get range grouped list of ranges", () => {
|
|
|
|
it('when custom settings should return default range list', () => {
|
|
|
|
var groups = rangeUtil.getRelativeTimesList({time_options: []}, 'Last 5 minutes');
|
|
|
|
expect(_.keys(groups).length).to.be(4)
|
|
|
|
expect(groups[3][0].active).to.be(true)
|
|
|
|
});
|
|
|
|
|
|
|
|
// it('should add custom options to right section', () => {
|
|
|
|
// var groups = rangeUtil.getRelativeTimesList({
|
|
|
|
// time_options: ['12m', '15d']
|
|
|
|
// }, '');
|
|
|
|
// var value = _.findWhere(groups["3"], {display: 'Last 12 minutes'});
|
|
|
|
// expect(value).to.not.be(undefined)
|
|
|
|
// });
|
|
|
|
});
|
|
|
|
|
2015-09-17 05:40:04 -05:00
|
|
|
describe("Can get range text described", () => {
|
2015-09-17 02:44:51 -05:00
|
|
|
it('should handle simple old expression with only amount and unit', () => {
|
|
|
|
var info = rangeUtil.describeTextRange('5m');
|
|
|
|
expect(info.display).to.be('Last 5 minutes')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have singular when amount is 1', () => {
|
|
|
|
var info = rangeUtil.describeTextRange('1h');
|
|
|
|
expect(info.display).to.be('Last 1 hour')
|
|
|
|
});
|
|
|
|
|
2015-09-17 05:40:04 -05:00
|
|
|
it('should handle non default amount', () => {
|
|
|
|
var info = rangeUtil.describeTextRange('13h');
|
|
|
|
expect(info.display).to.be('Last 13 hours')
|
|
|
|
expect(info.from).to.be('now-13h')
|
|
|
|
});
|
|
|
|
|
2015-09-17 02:44:51 -05:00
|
|
|
it('should handle now/d', () => {
|
|
|
|
var info = rangeUtil.describeTextRange('now/d');
|
|
|
|
expect(info.display).to.be('The day so far');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle now/w', () => {
|
|
|
|
var info = rangeUtil.describeTextRange('now/w');
|
|
|
|
expect(info.display).to.be('Week to date');
|
|
|
|
});
|
2015-09-17 05:40:04 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("Can get date range described", () => {
|
|
|
|
it('Date range with simple ranges', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: 'now-1h', to: 'now'});
|
|
|
|
expect(text).to.be('Last 1 hour')
|
|
|
|
});
|
2015-09-17 02:44:51 -05:00
|
|
|
|
2015-10-01 09:36:16 -05:00
|
|
|
it('Date range with rounding ranges', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: 'now/d+6h', to: 'now'});
|
|
|
|
expect(text).to.be('now/d+6h to now')
|
|
|
|
});
|
|
|
|
|
2015-09-18 06:54:31 -05:00
|
|
|
it('Date range with absolute to now', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: moment([2014,10,10,2,3,4]), to: 'now'});
|
|
|
|
expect(text).to.be('Nov 10, 2014 02:03:04 to a few seconds ago')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Date range with absolute to relative', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: moment([2014,10,10,2,3,4]), to: 'now-1d'});
|
|
|
|
expect(text).to.be('Nov 10, 2014 02:03:04 to a day ago')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Date range with relative to absolute', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: 'now-7d', to: moment([2014,10,10,2,3,4])});
|
|
|
|
expect(text).to.be('7 days ago to Nov 10, 2014 02:03:04')
|
|
|
|
});
|
|
|
|
|
2015-09-17 05:40:04 -05:00
|
|
|
it('Date range with non matching default ranges', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: 'now-13h', to: 'now'});
|
|
|
|
expect(text).to.be('Last 13 hours')
|
|
|
|
});
|
2015-11-11 03:34:53 -06:00
|
|
|
|
|
|
|
it('Date range with from and to both are in now-* format', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: 'now-6h', to: 'now-3h'});
|
|
|
|
expect(text).to.be('now-6h to now-3h')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Date range with from and to both are either in now-* or now/* format', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: 'now/d+6h', to: 'now-3h'});
|
|
|
|
expect(text).to.be('now/d+6h to now-3h')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Date range with from and to both are either in now-* or now+* format', () => {
|
|
|
|
var text = rangeUtil.describeTimeRange({from: 'now-6h', to: 'now+1h'});
|
|
|
|
expect(text).to.be('now-6h to now+1h')
|
|
|
|
});
|
|
|
|
|
2015-09-17 02:44:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|