|
9 | 9 | import ngMock from 'ng_mock'; |
10 | 10 | import expect from 'expect.js'; |
11 | 11 | import moment from 'moment'; |
12 | | -import { IntervalHelperProvider, getBoundsRoundedToInterval } from '../ml_time_buckets'; |
| 12 | +import { |
| 13 | + IntervalHelperProvider, |
| 14 | + getBoundsRoundedToInterval, |
| 15 | + calcEsInterval } from '../ml_time_buckets'; |
13 | 16 |
|
14 | 17 | describe('ML - time buckets', () => { |
15 | 18 |
|
@@ -125,7 +128,7 @@ describe('ML - time buckets', () => { |
125 | 128 |
|
126 | 129 | }); |
127 | 130 |
|
128 | | - describe('getBoundsRoundedToInterval ', () => { |
| 131 | + describe('getBoundsRoundedToInterval', () => { |
129 | 132 | // Must include timezone when creating moments for this test to ensure |
130 | 133 | // checks are correct when running tests in different timezones. |
131 | 134 | const testBounds = { min: moment('2017-01-05T10:11:12.000+00:00'), max: moment('2017-10-26T09:08:07.000+00:00') }; |
@@ -156,4 +159,24 @@ describe('ML - time buckets', () => { |
156 | 159 |
|
157 | 160 | }); |
158 | 161 |
|
| 162 | + describe('calcEsInterval', () => { |
| 163 | + it('returns correct interval for various durations', () => { |
| 164 | + expect(calcEsInterval(moment.duration(500, 'ms'))).to.eql({ value: 500, unit: 'ms', expression: '500ms' }); |
| 165 | + expect(calcEsInterval(moment.duration(1000, 'ms'))).to.eql({ value: 1, unit: 's', expression: '1s' }); |
| 166 | + expect(calcEsInterval(moment.duration(15, 's'))).to.eql({ value: 15, unit: 's', expression: '15s' }); |
| 167 | + expect(calcEsInterval(moment.duration(60, 's'))).to.eql({ value: 1, unit: 'm', expression: '1m' }); |
| 168 | + expect(calcEsInterval(moment.duration(1, 'm'))).to.eql({ value: 1, unit: 'm', expression: '1m' }); |
| 169 | + expect(calcEsInterval(moment.duration(60, 'm'))).to.eql({ value: 1, unit: 'h', expression: '1h' }); |
| 170 | + expect(calcEsInterval(moment.duration(3, 'h'))).to.eql({ value: 3, unit: 'h', expression: '3h' }); |
| 171 | + expect(calcEsInterval(moment.duration(24, 'h'))).to.eql({ value: 1, unit: 'd', expression: '1d' }); |
| 172 | + expect(calcEsInterval(moment.duration(3, 'd'))).to.eql({ value: 3, unit: 'd', expression: '3d' }); |
| 173 | + expect(calcEsInterval(moment.duration(7, 'd'))).to.eql({ value: 1, unit: 'w', expression: '1w' }); |
| 174 | + expect(calcEsInterval(moment.duration(1, 'w'))).to.eql({ value: 1, unit: 'w', expression: '1w' }); |
| 175 | + expect(calcEsInterval(moment.duration(4, 'w'))).to.eql({ value: 28, unit: 'd', expression: '28d' }); |
| 176 | + expect(calcEsInterval(moment.duration(1, 'M'))).to.eql({ value: 1, unit: 'M', expression: '1M' }); |
| 177 | + expect(calcEsInterval(moment.duration(12, 'M'))).to.eql({ value: 1, unit: 'y', expression: '1y' }); |
| 178 | + expect(calcEsInterval(moment.duration(1, 'y'))).to.eql({ value: 1, unit: 'y', expression: '1y' }); |
| 179 | + }); |
| 180 | + }); |
| 181 | + |
159 | 182 | }); |
0 commit comments