@@ -46,6 +46,8 @@ let init = function () {
4646 }
4747 } ;
4848 $parentScope . timefilter = timefilter ;
49+ $parentScope . updateInterval = sinon . spy ( ) ;
50+ $parentScope . updateFilter = sinon . spy ( ) ;
4951
5052 // Create the element
5153 $elem = angular . element (
@@ -54,7 +56,9 @@ let init = function () {
5456 ' to="timefilter.time.to"' +
5557 ' mode="timefilter.time.mode"' +
5658 ' active-tab="timefilter.timepickerActiveTab"' +
57- ' interval="timefilter.refreshInterval">' +
59+ ' interval="timefilter.refreshInterval"' +
60+ ' on-interval-select="updateInterval(interval)"' +
61+ ' on-filter-select="updateFilter(from, to)">' +
5862 '</kbn-timepicker>'
5963 ) ;
6064
@@ -99,64 +103,34 @@ describe('timepicker directive', function () {
99103 done ( ) ;
100104 } ) ;
101105
102- it ( 'should have a $scope.setRefreshInterval() that sets interval variable ' , function ( done ) {
106+ it ( 'should have a $scope.setRefreshInterval() that calls handler ' , function ( done ) {
103107 $scope . setRefreshInterval ( { value : 10000 } ) ;
104- expect ( $scope . interval ) . to . have . property ( 'value' , 10000 ) ;
105- done ( ) ;
106- } ) ;
107-
108- it ( 'should set the interval on the courier' , function ( done ) {
109- // Change refresh interval and digest
110- $scope . setRefreshInterval ( { value : 1000 } ) ;
111- $elem . scope ( ) . $digest ( ) ;
112- expect ( $courier . searchLooper . loopInterval ( ) ) . to . be ( 1000 ) ;
113- done ( ) ;
114- } ) ;
115-
116- it ( 'should disable the looper when paused' , function ( done ) {
117- $scope . setRefreshInterval ( { value : 1000 , pause : true } ) ;
118- $elem . scope ( ) . $digest ( ) ;
119- expect ( $courier . searchLooper . loopInterval ( ) ) . to . be ( 0 ) ;
120- expect ( $scope . interval . value ) . to . be ( 1000 ) ;
121- done ( ) ;
122- } ) ;
123-
124- it ( 'but keep interval.value set' , function ( done ) {
125- $scope . setRefreshInterval ( { value : 1000 , pause : true } ) ;
126- $elem . scope ( ) . $digest ( ) ;
127- expect ( $scope . interval . value ) . to . be ( 1000 ) ;
108+ sinon . assert . calledOnce ( $parentScope . updateInterval ) ;
109+ expect ( $parentScope . updateInterval . firstCall . args [ 0 ] ) . to . have . property ( 'value' , 10000 ) ;
128110 done ( ) ;
129111 } ) ;
130112
131113 it ( 'should unpause when setRefreshInterval is called without pause:true' , function ( done ) {
132- $scope . setRefreshInterval ( { value : 1000 , pause : true } ) ;
133- expect ( $scope . interval . pause ) . to . be ( true ) ;
114+ $scope . setRefreshInterval ( { value : 1000 , pause : true } ) ;
115+ expect ( $parentScope . updateInterval . getCall ( 0 ) . args [ 0 ] ) . to . have . property ( 'pause' , true ) ;
134116
135- $scope . setRefreshInterval ( { value : 1000 , pause : false } ) ;
136- expect ( $scope . interval . pause ) . to . be ( false ) ;
117+ $scope . setRefreshInterval ( { value : 1000 , pause : false } ) ;
118+ expect ( $parentScope . updateInterval . getCall ( 1 ) . args [ 0 ] ) . to . have . property ( 'pause' , false ) ;
137119
138- $scope . setRefreshInterval ( { value : 1000 } ) ;
139- expect ( $scope . interval . pause ) . to . be ( false ) ;
120+ $scope . setRefreshInterval ( { value : 1000 } ) ;
121+ expect ( $parentScope . updateInterval . getCall ( 2 ) . args [ 0 ] ) . to . have . property ( 'pause' , false ) ;
140122
141123 done ( ) ;
142124 } ) ;
143125
144126
145127 it ( 'should highlight the current active interval' , function ( done ) {
146- $scope . setRefreshInterval ( { value : 300000 } ) ;
128+ $scope . interval = { value : 300000 } ;
147129 $elem . scope ( ) . $digest ( ) ;
148130 expect ( $elem . find ( '.refresh-interval-active' ) . length ) . to . be ( 1 ) ;
149131 expect ( $elem . find ( '.refresh-interval-active' ) . text ( ) . trim ( ) ) . to . be ( '5 minutes' ) ;
150132 done ( ) ;
151133 } ) ;
152-
153- it ( 'should default the interval on the courier with incorrect values' , function ( done ) {
154- // Change refresh interval and digest
155- $scope . setRefreshInterval ( ) ;
156- $elem . scope ( ) . $digest ( ) ;
157- expect ( $courier . searchLooper . loopInterval ( ) ) . to . be ( 0 ) ;
158- done ( ) ;
159- } ) ;
160134 } ) ;
161135
162136 describe ( 'mode setting' , function ( ) {
@@ -198,10 +172,11 @@ describe('timepicker directive', function () {
198172 done ( ) ;
199173 } ) ;
200174
201- it ( 'should have a $scope.setQuick() that sets the to and from variables to strings ' , function ( done ) {
175+ it ( 'should have a $scope.setQuick() that calls handler ' , function ( done ) {
202176 $scope . setQuick ( 'now' , 'now' ) ;
203- expect ( $scope . from ) . to . be ( 'now' ) ;
204- expect ( $scope . to ) . to . be ( 'now' ) ;
177+ sinon . assert . calledOnce ( $parentScope . updateFilter ) ;
178+ expect ( $parentScope . updateFilter . firstCall . args [ 0 ] ) . to . be ( 'now' ) ;
179+ expect ( $parentScope . updateFilter . firstCall . args [ 1 ] ) . to . be ( 'now' ) ;
205180 done ( ) ;
206181 } ) ;
207182 } ) ;
@@ -312,24 +287,25 @@ describe('timepicker directive', function () {
312287 $scope . relative . count = 1 ;
313288 $scope . relative . unit = 's' ;
314289 $scope . applyRelative ( ) ;
315- expect ( $scope . from ) . to . be ( 'now-1s' ) ;
290+ sinon . assert . calledOnce ( $parentScope . updateFilter ) ;
291+ expect ( $parentScope . updateFilter . getCall ( 0 ) . args [ 0 ] ) . to . be ( 'now-1s' ) ;
316292
317293 $scope . relative . count = 2 ;
318294 $scope . relative . unit = 'm' ;
319295 $scope . applyRelative ( ) ;
320- expect ( $scope . from ) . to . be ( 'now-2m' ) ;
296+ expect ( $parentScope . updateFilter . getCall ( 1 ) . args [ 0 ] ) . to . be ( 'now-2m' ) ;
321297
322298 $scope . relative . count = 3 ;
323299 $scope . relative . unit = 'h' ;
324300 $scope . applyRelative ( ) ;
325- expect ( $scope . from ) . to . be ( 'now-3h' ) ;
301+ expect ( $parentScope . updateFilter . getCall ( 2 ) . args [ 0 ] ) . to . be ( 'now-3h' ) ;
326302
327303 // Enable rounding
328304 $scope . relative . round = true ;
329305 $scope . relative . count = 7 ;
330306 $scope . relative . unit = 'd' ;
331307 $scope . applyRelative ( ) ;
332- expect ( $scope . from ) . to . be ( 'now-7d/d' ) ;
308+ expect ( $parentScope . updateFilter . getCall ( 3 ) . args [ 0 ] ) . to . be ( 'now-7d/d' ) ;
333309
334310 done ( ) ;
335311 } ) ;
@@ -398,16 +374,6 @@ describe('timepicker directive', function () {
398374 done ( ) ;
399375 } ) ;
400376
401- it ( 'should parse the time of scope.from and scope.to to set its own variables' , function ( done ) {
402- $scope . setQuick ( 'now-30m' , 'now' ) ;
403- $scope . setMode ( 'absolute' ) ;
404- $scope . $digest ( ) ;
405-
406- expect ( $scope . absolute . from . valueOf ( ) ) . to . be ( moment ( ) . subtract ( 30 , 'minutes' ) . valueOf ( ) ) ;
407- expect ( $scope . absolute . to . valueOf ( ) ) . to . be ( moment ( ) . valueOf ( ) ) ;
408- done ( ) ;
409- } ) ;
410-
411377 it ( 'should update its own variables if timefilter time is updated' , function ( done ) {
412378 $scope . setMode ( 'absolute' ) ;
413379 $scope . $digest ( ) ;
@@ -438,18 +404,17 @@ describe('timepicker directive', function () {
438404 } ) ;
439405
440406 it ( 'should only copy its input to scope.from and scope.to when scope.applyAbsolute() is called' , function ( done ) {
441- $scope . setQuick ( 'now-30m' , 'now' ) ;
442- expect ( $scope . from ) . to . be ( 'now-30m' ) ;
443- expect ( $scope . to ) . to . be ( 'now' ) ;
407+ $scope . from = 'now-30m' ;
408+ $scope . to = 'now' ;
444409
445410 $scope . absolute . from = moment ( '2012-02-01' ) ;
446411 $scope . absolute . to = moment ( '2012-02-11' ) ;
447412 expect ( $scope . from ) . to . be ( 'now-30m' ) ;
448413 expect ( $scope . to ) . to . be ( 'now' ) ;
449414
450415 $scope . applyAbsolute ( ) ;
451- expect ( $scope . from . valueOf ( ) ) . to . be ( moment ( '2012-02-01' ) . valueOf ( ) ) ;
452- expect ( $scope . to . valueOf ( ) ) . to . be ( moment ( '2012-02-11' ) . valueOf ( ) ) ;
416+ expect ( $parentScope . updateFilter . firstCall . args [ 0 ] ) . to . eql ( moment ( '2012-02-01' ) ) ;
417+ expect ( $parentScope . updateFilter . firstCall . args [ 1 ] ) . to . eql ( moment ( '2012-02-11' ) ) ;
453418
454419 $scope . $digest ( ) ;
455420
0 commit comments