1
1
describe ( 'timepicker directive' , function ( ) {
2
- var $rootScope , $compile , $templateCache , element ;
2
+ var $rootScope , $compile , $templateCache , element , modelCtrl ;
3
3
4
4
beforeEach ( module ( 'ui.bootstrap.timepicker' ) ) ;
5
5
beforeEach ( module ( 'template/timepicker/timepicker.html' ) ) ;
@@ -11,6 +11,8 @@ describe('timepicker directive', function() {
11
11
12
12
element = $compile ( '<uib-timepicker ng-model="time"></uib-timepicker>' ) ( $rootScope ) ;
13
13
$rootScope . $digest ( ) ;
14
+
15
+ modelCtrl = element . controller ( 'ngModel' ) ;
14
16
} ) ) ;
15
17
16
18
function newTime ( hours , minutes , seconds ) {
@@ -117,7 +119,11 @@ describe('timepicker directive', function() {
117
119
} ) ;
118
120
119
121
it ( 'should be pristine' , function ( ) {
120
- expect ( element . controller ( 'ngModel' ) . $pristine ) . toBe ( true ) ;
122
+ expect ( modelCtrl . $pristine ) . toBe ( true ) ;
123
+ } ) ;
124
+
125
+ it ( 'should be untouched' , function ( ) {
126
+ expect ( modelCtrl . $untouched ) . toBe ( true ) ;
121
127
} ) ;
122
128
123
129
it ( 'has `selected` current time when model is initially cleared' , function ( ) {
@@ -192,6 +198,51 @@ describe('timepicker directive', function() {
192
198
expect ( getModelState ( ) ) . toEqual ( [ 14 , 40 , 24 ] ) ;
193
199
} ) ;
194
200
201
+ it ( 'should be dirty when input changes' , function ( ) {
202
+ var upHours = getHoursButton ( true ) ;
203
+ var upMinutes = getMinutesButton ( true ) ;
204
+ var upSeconds = getSecondsButton ( true ) ;
205
+
206
+ doClick ( upHours ) ;
207
+ expect ( modelCtrl . $dirty ) . toBe ( true ) ;
208
+
209
+ modelCtrl . $setPristine ( ) ;
210
+
211
+ doClick ( upMinutes ) ;
212
+ expect ( modelCtrl . $dirty ) . toBe ( true ) ;
213
+
214
+ modelCtrl . $setPristine ( ) ;
215
+
216
+ doClick ( upSeconds ) ;
217
+ expect ( modelCtrl . $dirty ) . toBe ( true ) ;
218
+ } ) ;
219
+
220
+ it ( 'should be touched when input blurs' , function ( ) {
221
+ var inputs = element . find ( 'input' ) ;
222
+ var hoursInput = inputs . eq ( 0 ) ,
223
+ minutesInput = inputs . eq ( 1 ) ,
224
+ secondsInput = inputs . eq ( 2 ) ;
225
+
226
+ hoursInput . val ( 12 ) ;
227
+ $rootScope . $digest ( ) ;
228
+ hoursInput . blur ( ) ;
229
+ expect ( modelCtrl . $touched ) . toBe ( true ) ;
230
+
231
+ modelCtrl . $setUntouched ( ) ;
232
+
233
+ minutesInput . val ( 20 ) ;
234
+ $rootScope . $digest ( ) ;
235
+ hoursInput . blur ( ) ;
236
+ expect ( modelCtrl . $touched ) . toBe ( true ) ;
237
+
238
+ modelCtrl . $setUntouched ( ) ;
239
+
240
+ secondsInput . val ( 9 ) ;
241
+ $rootScope . $digest ( ) ;
242
+ hoursInput . blur ( ) ;
243
+ expect ( modelCtrl . $touched ) . toBe ( true ) ;
244
+ } ) ;
245
+
195
246
it ( 'meridian button has correct type' , function ( ) {
196
247
var button = getMeridianButton ( ) ;
197
248
expect ( button . attr ( 'type' ) ) . toBe ( 'button' ) ;
0 commit comments