-
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.
Refactor out state logic from dashboard directive (and a bugfix) (#10152
) * New state and tests and time fixes * Code review comments * Remove saving filters if "enter" hasn't been pressed
- Loading branch information
1 parent
4662635
commit 20ea24f
Showing
17 changed files
with
806 additions
and
394 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
95 changes: 95 additions & 0 deletions
95
src/core_plugins/kibana/public/dashboard/__tests__/dashboard_state.js
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,95 @@ | ||
import ngMock from 'ng_mock'; | ||
import expect from 'expect.js'; | ||
|
||
import { DashboardState } from '../dashboard_state'; | ||
|
||
describe('DashboardState', function () { | ||
let AppState; | ||
let dashboardState; | ||
let savedDashboard; | ||
let SavedDashboard; | ||
let timefilter; | ||
let quickTimeRanges; | ||
|
||
function initDashboardState() { | ||
dashboardState = new DashboardState(savedDashboard, timefilter, true, quickTimeRanges, AppState); | ||
} | ||
|
||
beforeEach(ngMock.module('kibana')); | ||
beforeEach(ngMock.inject(function ($injector) { | ||
timefilter = $injector.get('timefilter'); | ||
quickTimeRanges = $injector.get('quickRanges'); | ||
AppState = $injector.get('AppState'); | ||
SavedDashboard = $injector.get('SavedDashboard'); | ||
savedDashboard = new SavedDashboard(); | ||
})); | ||
|
||
describe('timefilter', function () { | ||
|
||
describe('when timeRestore is true', function () { | ||
it('syncs quick time', function () { | ||
savedDashboard.timeRestore = true; | ||
savedDashboard.timeFrom = 'now/w'; | ||
savedDashboard.timeTo = 'now/w'; | ||
|
||
timefilter.time.from = '2015-09-19 06:31:44.000'; | ||
timefilter.time.to = '2015-09-29 06:31:44.000'; | ||
timefilter.time.mode = 'absolute'; | ||
|
||
initDashboardState(); | ||
|
||
expect(timefilter.time.mode).to.equal('quick'); | ||
expect(timefilter.time.to).to.equal('now/w'); | ||
expect(timefilter.time.from).to.equal('now/w'); | ||
}); | ||
|
||
it('syncs relative time', function () { | ||
savedDashboard.timeRestore = true; | ||
savedDashboard.timeFrom = 'now-13d'; | ||
savedDashboard.timeTo = 'now'; | ||
|
||
timefilter.time.from = '2015-09-19 06:31:44.000'; | ||
timefilter.time.to = '2015-09-29 06:31:44.000'; | ||
timefilter.time.mode = 'absolute'; | ||
|
||
initDashboardState(); | ||
|
||
expect(timefilter.time.mode).to.equal('relative'); | ||
expect(timefilter.time.to).to.equal('now'); | ||
expect(timefilter.time.from).to.equal('now-13d'); | ||
}); | ||
|
||
it('syncs absolute time', function () { | ||
savedDashboard.timeRestore = true; | ||
savedDashboard.timeFrom = '2015-09-19 06:31:44.000'; | ||
savedDashboard.timeTo = '2015-09-29 06:31:44.000'; | ||
|
||
timefilter.time.from = 'now/w'; | ||
timefilter.time.to = 'now/w'; | ||
timefilter.time.mode = 'quick'; | ||
|
||
initDashboardState(); | ||
|
||
expect(timefilter.time.mode).to.equal('absolute'); | ||
expect(timefilter.time.to).to.equal(savedDashboard.timeTo); | ||
expect(timefilter.time.from).to.equal(savedDashboard.timeFrom); | ||
}); | ||
}); | ||
|
||
it('is not synced when timeRestore is false', function () { | ||
savedDashboard.timeRestore = false; | ||
savedDashboard.timeFrom = 'now/w'; | ||
savedDashboard.timeTo = 'now/w'; | ||
|
||
timefilter.time.timeFrom = '2015-09-19 06:31:44.000'; | ||
timefilter.time.timeTo = '2015-09-29 06:31:44.000'; | ||
timefilter.time.mode = 'absolute'; | ||
|
||
initDashboardState(); | ||
|
||
expect(timefilter.time.mode).to.equal('absolute'); | ||
expect(timefilter.time.timeFrom).to.equal('2015-09-19 06:31:44.000'); | ||
expect(timefilter.time.timeTo).to.equal('2015-09-29 06:31:44.000'); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.