@@ -93,7 +93,7 @@ void main() {
93
93
expect (ngModel.valid).toBe (false );
94
94
}));
95
95
96
- it ('should write to input only if value is different' ,
96
+ it ('should write to input only if the value is different' ,
97
97
inject ((Injector i, AstParser parser, NgAnimate animate) {
98
98
99
99
var scope = _.rootScope;
@@ -111,20 +111,40 @@ void main() {
111
111
..selectionStart = 1
112
112
..selectionEnd = 2 ;
113
113
114
- model.render ('abc' );
114
+ scope.apply (() {
115
+ scope.context['model' ] = 'abc' ;
116
+ });
115
117
116
118
expect (element.value).toEqual ('abc' );
117
119
// No update. selectionStart/End is unchanged.
118
120
expect (element.selectionStart).toEqual (1 );
119
121
expect (element.selectionEnd).toEqual (2 );
120
122
121
- model.render ('xyz' );
123
+ scope.apply (() {
124
+ scope.context['model' ] = 'xyz' ;
125
+ });
122
126
123
127
// Value updated. selectionStart/End changed.
124
128
expect (element.value).toEqual ('xyz' );
125
129
expect (element.selectionStart).toEqual (3 );
126
130
expect (element.selectionEnd).toEqual (3 );
127
131
}));
132
+
133
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
134
+ _.compile ('<input type="text" ng-model="model" probe="p">' );
135
+ Probe probe = _.rootScope.context['p' ];
136
+ var ngModel = probe.directive (NgModel );
137
+ InputElement inputElement = probe.element;
138
+
139
+ ngModel.render ('xyz' );
140
+ scope.context['model' ] = 'xyz' ;
141
+
142
+ expect (inputElement.value).not.toEqual ('xyz' );
143
+
144
+ scope.apply ();
145
+
146
+ expect (inputElement.value).toEqual ('xyz' );
147
+ }));
128
148
});
129
149
130
150
/* This function simulates typing the given text into the input
@@ -254,6 +274,22 @@ void main() {
254
274
_.rootScope.apply ('model = null' );
255
275
expect ((_.rootElement as dom.InputElement ).value).toEqual ('' );
256
276
}));
277
+
278
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
279
+ _.compile ('<input type="number" ng-model="model" probe="p">' );
280
+ Probe probe = _.rootScope.context['p' ];
281
+ var ngModel = probe.directive (NgModel );
282
+ InputElement inputElement = probe.element;
283
+
284
+ ngModel.render (123 );
285
+ scope.context['model' ] = 123 ;
286
+
287
+ expect (inputElement.value).not.toEqual ('123' );
288
+
289
+ scope.apply ();
290
+
291
+ expect (inputElement.value).toEqual ('123' );
292
+ }));
257
293
258
294
});
259
295
@@ -313,18 +349,38 @@ void main() {
313
349
..selectionStart = 1
314
350
..selectionEnd = 2 ;
315
351
316
- model.render ('abc' );
352
+ scope.apply (() {
353
+ scope.context['model' ] = 'abc' ;
354
+ });
317
355
318
356
expect (element.value).toEqual ('abc' );
319
357
expect (element.selectionStart).toEqual (1 );
320
358
expect (element.selectionEnd).toEqual (2 );
321
359
322
- model.render ('xyz' );
360
+ scope.apply (() {
361
+ scope.context['model' ] = 'xyz' ;
362
+ });
323
363
324
364
expect (element.value).toEqual ('xyz' );
325
365
expect (element.selectionStart).toEqual (3 );
326
366
expect (element.selectionEnd).toEqual (3 );
327
367
}));
368
+
369
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
370
+ _.compile ('<input type="password" ng-model="model" probe="p">' );
371
+ Probe probe = _.rootScope.context['p' ];
372
+ var ngModel = probe.directive (NgModel );
373
+ InputElement inputElement = probe.element;
374
+
375
+ ngModel.render ('xyz' );
376
+ scope.context['model' ] = 'xyz' ;
377
+
378
+ expect (inputElement.value).not.toEqual ('xyz' );
379
+
380
+ scope.apply ();
381
+
382
+ expect (inputElement.value).toEqual ('xyz' );
383
+ }));
328
384
});
329
385
330
386
describe ('type="search"' , () {
@@ -382,20 +438,40 @@ void main() {
382
438
..selectionStart = 1
383
439
..selectionEnd = 2 ;
384
440
385
- model.render ('abc' );
441
+ scope.apply (() {
442
+ scope.context['model' ] = 'abc' ;
443
+ });
386
444
387
445
expect (element.value).toEqual ('abc' );
388
446
// No update. selectionStart/End is unchanged.
389
447
expect (element.selectionStart).toEqual (1 );
390
448
expect (element.selectionEnd).toEqual (2 );
391
449
392
- model.render ('xyz' );
450
+ scope.apply (() {
451
+ scope.context['model' ] = 'xyz' ;
452
+ });
393
453
394
454
// Value updated. selectionStart/End changed.
395
455
expect (element.value).toEqual ('xyz' );
396
456
expect (element.selectionStart).toEqual (3 );
397
457
expect (element.selectionEnd).toEqual (3 );
398
458
}));
459
+
460
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
461
+ _.compile ('<input type="search" ng-model="model" probe="p">' );
462
+ Probe probe = _.rootScope.context['p' ];
463
+ var ngModel = probe.directive (NgModel );
464
+ InputElement inputElement = probe.element;
465
+
466
+ ngModel.render ('xyz' );
467
+ scope.context['model' ] = 'xyz' ;
468
+
469
+ expect (inputElement.value).not.toEqual ('xyz' );
470
+
471
+ scope.apply ();
472
+
473
+ expect (inputElement.value).toEqual ('xyz' );
474
+ }));
399
475
});
400
476
401
477
describe ('no type attribute' , () {
@@ -459,18 +535,38 @@ void main() {
459
535
..selectionStart = 1
460
536
..selectionEnd = 2 ;
461
537
462
- model.render ('abc' );
538
+ scope.apply (() {
539
+ scope.context['model' ] = 'abc' ;
540
+ });
463
541
464
542
expect (element.value).toEqual ('abc' );
465
543
expect (element.selectionStart).toEqual (1 );
466
544
expect (element.selectionEnd).toEqual (2 );
467
545
468
- model.render ('xyz' );
546
+ scope.apply (() {
547
+ scope.context['model' ] = 'xyz' ;
548
+ });
469
549
470
550
expect (element.value).toEqual ('xyz' );
471
551
expect (element.selectionStart).toEqual (3 );
472
552
expect (element.selectionEnd).toEqual (3 );
473
553
}));
554
+
555
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
556
+ _.compile ('<input ng-model="model" probe="p">' );
557
+ Probe probe = _.rootScope.context['p' ];
558
+ var ngModel = probe.directive (NgModel );
559
+ InputElement inputElement = probe.element;
560
+
561
+ ngModel.render ('xyz' );
562
+ scope.context['model' ] = 'xyz' ;
563
+
564
+ expect (inputElement.value).not.toEqual ('xyz' );
565
+
566
+ scope.apply ();
567
+
568
+ expect (inputElement.value).toEqual ('xyz' );
569
+ }));
474
570
});
475
571
476
572
describe ('type="checkbox"' , () {
@@ -557,6 +653,22 @@ void main() {
557
653
_.triggerEvent (element, 'change' );
558
654
expect (scope.context['model' ]).toBe (false );
559
655
}));
656
+
657
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
658
+ _.compile ('<input type="checkbox" ng-model="model" probe="p">' );
659
+ Probe probe = _.rootScope.context['p' ];
660
+ var ngModel = probe.directive (NgModel );
661
+ InputElement inputElement = probe.element;
662
+
663
+ ngModel.render ('xyz' );
664
+ scope.context['model' ] = true ;
665
+
666
+ expect (inputElement.checked).toBe (false );
667
+
668
+ scope.apply ();
669
+
670
+ expect (inputElement.checked).toBe (true );
671
+ }));
560
672
});
561
673
562
674
describe ('textarea' , () {
@@ -631,6 +743,22 @@ void main() {
631
743
expect (element.selectionStart).toEqual (0 );
632
744
expect (element.selectionEnd).toEqual (0 );
633
745
}));
746
+
747
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
748
+ _.compile ('<textarea ng-model="model" probe="p"></textarea>' );
749
+ Probe probe = _.rootScope.context['p' ];
750
+ var ngModel = probe.directive (NgModel );
751
+ TextAreaElement inputElement = probe.element;
752
+
753
+ ngModel.render ('xyz' );
754
+ scope.context['model' ] = 'xyz' ;
755
+
756
+ expect (inputElement.value).not.toEqual ('xyz' );
757
+
758
+ scope.apply ();
759
+
760
+ expect (inputElement.value).toEqual ('xyz' );
761
+ }));
634
762
});
635
763
636
764
describe ('type="radio"' , () {
@@ -772,6 +900,34 @@ void main() {
772
900
expect (input1.classes.contains ("ng-pristine" )).toBe (false );
773
901
expect (input1.classes.contains ("ng-pristine" )).toBe (false );
774
902
}));
903
+
904
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
905
+ var element = _.compile (
906
+ '<div>' +
907
+ ' <input type="radio" id="on" ng-model="model" probe="i" value="on" />' +
908
+ ' <input type="radio" id="off" ng-model="model" probe="j" value="off" />' +
909
+ '</div>'
910
+ );
911
+
912
+ Probe probe1 = _.rootScope.context['i' ];
913
+ var ngModel1 = probe1.directive (NgModel );
914
+ InputElement inputElement1 = probe1.element;
915
+
916
+ Probe probe2 = _.rootScope.context['j' ];
917
+ var ngModel2 = probe2.directive (NgModel );
918
+ InputElement inputElement2 = probe2.element;
919
+
920
+ ngModel1.render ('on' );
921
+ scope.context['model' ] = 'on' ;
922
+
923
+ expect (inputElement1.checked).toBe (false );
924
+ expect (inputElement2.checked).toBe (false );
925
+
926
+ scope.apply ();
927
+
928
+ expect (inputElement1.checked).toBe (true );
929
+ expect (inputElement2.checked).toBe (false );
930
+ }));
775
931
});
776
932
777
933
describe ('type="search"' , () {
@@ -810,6 +966,22 @@ void main() {
810
966
input.processValue ();
811
967
expect (_.rootScope.context['model' ]).toEqual ('123' );
812
968
}));
969
+
970
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
971
+ _.compile ('<input type="search" ng-model="model" probe="p">' );
972
+ Probe probe = _.rootScope.context['p' ];
973
+ var ngModel = probe.directive (NgModel );
974
+ InputElement inputElement = probe.element;
975
+
976
+ ngModel.render ('xyz' );
977
+ scope.context['model' ] = 'xyz' ;
978
+
979
+ expect (inputElement.value).not.toEqual ('xyz' );
980
+
981
+ scope.apply ();
982
+
983
+ expect (inputElement.value).toEqual ('xyz' );
984
+ }));
813
985
});
814
986
815
987
describe ('contenteditable' , () {
@@ -836,6 +1008,22 @@ void main() {
836
1008
input.processValue ();
837
1009
expect (_.rootScope.context['model' ]).toEqual ('def' );
838
1010
}));
1011
+
1012
+ it ('should only render the input value upon the next digest' , inject ((Scope scope) {
1013
+ _.compile ('<div contenteditable ng-model="model" probe="p"></div>' );
1014
+ Probe probe = _.rootScope.context['p' ];
1015
+ var ngModel = probe.directive (NgModel );
1016
+ Element element = probe.element;
1017
+
1018
+ ngModel.render ('xyz' );
1019
+ scope.context['model' ] = 'xyz' ;
1020
+
1021
+ expect (element.innerHtml).not.toEqual ('xyz' );
1022
+
1023
+ scope.apply ();
1024
+
1025
+ expect (element.innerHtml).toEqual ('xyz' );
1026
+ }));
839
1027
});
840
1028
841
1029
describe ('pristine / dirty' , () {
0 commit comments