-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
forceNow
query parameter when parsing timefilter (#16236)
* Using "forceNow" parameter to adjust "now" and exposing timeRange * Moving forceNow parameter to the hash, adding tests * Renaming test
- Loading branch information
Showing
4 changed files
with
132 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import sinon from 'sinon'; | ||
import expect from 'expect.js'; | ||
import ngMock from 'ng_mock'; | ||
|
||
describe('Timefilter service', function () { | ||
|
||
describe('calculateBounds', function () { | ||
beforeEach(ngMock.module('kibana')); | ||
|
||
const fifteenMinutesInMilliseconds = 15 * 60 * 1000; | ||
const clockNowTicks = new Date(2000, 1, 1, 0, 0, 0, 0).valueOf(); | ||
|
||
let timefilter; | ||
let $location; | ||
let clock; | ||
|
||
beforeEach(ngMock.inject(function (_timefilter_, _$location_) { | ||
timefilter = _timefilter_; | ||
$location = _$location_; | ||
|
||
clock = sinon.useFakeTimers(clockNowTicks); | ||
})); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('uses clock time by default', function () { | ||
const timeRange = { | ||
from: 'now-15m', | ||
to: 'now' | ||
}; | ||
|
||
const result = timefilter.calculateBounds(timeRange); | ||
expect(result.min.valueOf()).to.eql(clockNowTicks - fifteenMinutesInMilliseconds); | ||
expect(result.max.valueOf()).to.eql(clockNowTicks); | ||
}); | ||
|
||
it('uses forceNow string', function () { | ||
const timeRange = { | ||
from: 'now-15m', | ||
to: 'now' | ||
}; | ||
|
||
const forceNowString = '1999-01-01T00:00:00.000Z'; | ||
$location.search('forceNow', forceNowString); | ||
const result = timefilter.calculateBounds(timeRange); | ||
|
||
const forceNowTicks = Date.parse(forceNowString); | ||
expect(result.min.valueOf()).to.eql(forceNowTicks - fifteenMinutesInMilliseconds); | ||
expect(result.max.valueOf()).to.eql(forceNowTicks); | ||
}); | ||
|
||
it(`throws Error if forceNow can't be parsed`, function () { | ||
const timeRange = { | ||
from: 'now-15m', | ||
to: 'now' | ||
}; | ||
|
||
$location.search('forceNow', 'malformed%20string'); | ||
expect(() => timefilter.calculateBounds(timeRange)).to.throwError(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters