@@ -4,6 +4,7 @@ import '../_specs.dart';
4
4
import 'package:angular/change_detection/change_detection.dart' ;
5
5
import 'package:angular/change_detection/dirty_checking_change_detector.dart' ;
6
6
import 'package:angular/change_detection/dirty_checking_change_detector_static.dart' ;
7
+ import 'package:angular/change_detection/dirty_checking_change_detector_dynamic.dart' ;
7
8
import 'dart:collection' ;
8
9
import 'dart:math' ;
9
10
@@ -14,19 +15,80 @@ void main() {
14
15
"first" : (o) => o.first,
15
16
"age" : (o) => o.age,
16
17
"last" : (o) => o.last,
17
- "toString" : (o) => o.toString
18
+ "toString" : (o) => o.toString,
19
+ "isUnderAge" : (o) => o.isUnderAge,
20
+ "isUnderAgeAsVariable" : (o) => o.isUnderAgeAsVariable
18
21
});
19
22
20
23
beforeEach (() {
21
24
detector = new DirtyCheckingChangeDetector <String >(getterFactory);
22
25
});
23
26
24
27
describe ('StaticFieldGetterFactory' , () {
28
+ DirtyCheckingChangeDetector <String > detector;
29
+ var user = new _User ('Marko' , 'Vuksanovic' , 30 );
30
+ FieldGetterFactory getterFactory = new StaticFieldGetterFactory ({
31
+ "first" : (o) => o.first,
32
+ "age" : (o) => o.age,
33
+ "last" : (o) => o.last,
34
+ "toString" : (o) => o.toString,
35
+ "isUnderAge" : (o) => o.isUnderAge,
36
+ "isUnderAgeAsVariable" : (o) => o.isUnderAgeAsVariable,
37
+ "list" : (o) => o.list,
38
+ "map" : (o) => o.map
39
+ });
40
+
41
+ beforeEach (() {
42
+ detector = new DirtyCheckingChangeDetector <String >(getterFactory);
43
+ });
44
+
25
45
it ('should detect methods' , () {
26
46
var obj = new _User ();
27
47
expect (getterFactory.isMethod (obj, 'toString' )).toEqual (true );
28
48
expect (getterFactory.isMethod (obj, 'age' )).toEqual (false );
29
49
});
50
+
51
+ it ('should return true is method is real method' , () {
52
+ expect (getterFactory.isMethod (user, 'isUnderAge' )).toEqual (true );
53
+ });
54
+
55
+ it ('should return false is field is a function' , () {
56
+ expect (getterFactory.isMethod (user, 'isUnderAgeAsVariable' )).toEqual (false );
57
+ });
58
+
59
+ it ('should return false is field is a list' , () {
60
+ expect (getterFactory.isMethod (user, 'list' )).toEqual (false );
61
+ });
62
+
63
+ it ('should return false is field is a map' , () {
64
+ expect (getterFactory.isMethod (user, 'map' )).toEqual (false );
65
+ });
66
+ });
67
+
68
+ describe ('Dynamic GetterFactory' , () {
69
+ DirtyCheckingChangeDetector <String > detector;
70
+ var user = new _User ('Marko' , 'Vuksanovic' , 30 );
71
+ FieldGetterFactory getterFactory = new DynamicFieldGetterFactory ();
72
+
73
+ beforeEach (() {
74
+ detector = new DirtyCheckingChangeDetector <String >(getterFactory);
75
+ });
76
+
77
+ it ('should return true is method is real method' , () {
78
+ expect (getterFactory.isMethod (user, 'isUnderAge' )).toEqual (true );
79
+ });
80
+
81
+ it ('should return false is field is a function' , () {
82
+ expect (getterFactory.isMethod (user, 'isUnderAgeAsVariable' )).toEqual (false );
83
+ });
84
+
85
+ it ('should return false is field is a list' , () {
86
+ expect (getterFactory.isMethod (user, 'list' )).toEqual (false );
87
+ });
88
+
89
+ it ('should return false is field is a map' , () {
90
+ expect (getterFactory.isMethod (user, 'map' )).toEqual (false );
91
+ });
30
92
});
31
93
32
94
describe ('object field' , () {
@@ -657,6 +719,39 @@ void main() {
657
719
});
658
720
});
659
721
722
+ describe ('function watching' , () {
723
+ it ('should detect no changes when watching a function' , () {
724
+ var user = new _User ('marko' , 'vuksanovic' , 15 );
725
+ Iterator changeIterator;
726
+
727
+ detector..watch (user, 'isUnderAge' , null );
728
+ changeIterator = detector.collectChanges ();
729
+ expect (changeIterator.moveNext ()).toEqual (true );
730
+ expect (changeIterator.moveNext ()).toEqual (false );
731
+
732
+ user.age = 17 ;
733
+ changeIterator = detector.collectChanges ();
734
+ expect (changeIterator.moveNext ()).toEqual (false );
735
+
736
+ user.age = 30 ;
737
+ changeIterator = detector.collectChanges ();
738
+ expect (changeIterator.moveNext ()).toEqual (false );
739
+ });
740
+
741
+ it ('should detect change when watching a property function' , () {
742
+ var user = new _User ('marko' , 'vuksanovic' , 30 );
743
+ Iterator changeIterator;
744
+
745
+ detector..watch (user, 'isUnderAgeAsVariable' , null );
746
+ changeIterator = detector.collectChanges ();
747
+ expect (changeIterator.moveNext ()).toEqual (false );
748
+
749
+ user.isUnderAgeAsVariable = () => false ;
750
+ changeIterator = detector.collectChanges ();
751
+ expect (changeIterator.moveNext ()).toEqual (true );
752
+ });
753
+ });
754
+
660
755
describe ('DuplicateMap' , () {
661
756
DuplicateMap map;
662
757
beforeEach (() => map = new DuplicateMap ());
@@ -693,8 +788,17 @@ class _User {
693
788
String first;
694
789
String last;
695
790
num age;
791
+ var isUnderAgeAsVariable;
792
+ List <String > list = ['foo' , 'bar' , 'baz' ];
793
+ Map map = {'foo' : 'bar' , 'baz' : 'cux' };
696
794
697
- _User ([this .first, this .last, this .age]);
795
+ _User ([this .first, this .last, this .age]) {
796
+ isUnderAgeAsVariable = isUnderAge;
797
+ }
798
+
799
+ bool isUnderAge () {
800
+ return age != null ? age < 18 : false ;
801
+ }
698
802
}
699
803
700
804
Matcher toEqualCollectionRecord ({collection, previous, additions, moves, removals}) =>
0 commit comments