2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- import 'package:flutter/services.dart' ;
6
5
import 'package:flutter/widgets.dart' ;
7
6
import 'package:flutter_test/flutter_test.dart' ;
8
7
import 'package:google_maps_flutter/google_maps_flutter.dart' ;
8
+ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart' ;
9
9
10
- import 'fake_maps_controllers .dart' ;
10
+ import 'fake_google_maps_flutter_platform .dart' ;
11
11
12
12
Widget _mapWithCircles (Set <Circle > circles) {
13
13
return Directionality (
@@ -20,36 +20,24 @@ Widget _mapWithCircles(Set<Circle> circles) {
20
20
}
21
21
22
22
void main () {
23
- TestWidgetsFlutterBinding .ensureInitialized ();
24
-
25
- final FakePlatformViewsController fakePlatformViewsController =
26
- FakePlatformViewsController ();
27
-
28
- setUpAll (() {
29
- _ambiguate (TestDefaultBinaryMessengerBinding .instance)!
30
- .defaultBinaryMessenger
31
- .setMockMethodCallHandler (
32
- SystemChannels .platform_views,
33
- fakePlatformViewsController.fakePlatformViewsMethodHandler,
34
- );
35
- });
23
+ late FakeGoogleMapsFlutterPlatform platform;
36
24
37
25
setUp (() {
38
- fakePlatformViewsController.reset ();
26
+ platform = FakeGoogleMapsFlutterPlatform ();
27
+ GoogleMapsFlutterPlatform .instance = platform;
39
28
});
40
29
41
30
testWidgets ('Initializing a circle' , (WidgetTester tester) async {
42
31
const Circle c1 = Circle (circleId: CircleId ('circle_1' ));
43
32
await tester.pumpWidget (_mapWithCircles (< Circle > {c1}));
44
33
45
- final FakePlatformGoogleMap platformGoogleMap =
46
- fakePlatformViewsController.lastCreatedView! ;
47
- expect (platformGoogleMap.circlesToAdd.length, 1 );
34
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
35
+ expect (map.circleUpdates.last.circlesToAdd.length, 1 );
48
36
49
- final Circle initializedCircle = platformGoogleMap .circlesToAdd.first;
37
+ final Circle initializedCircle = map.circleUpdates.last .circlesToAdd.first;
50
38
expect (initializedCircle, equals (c1));
51
- expect (platformGoogleMap .circleIdsToRemove.isEmpty, true );
52
- expect (platformGoogleMap .circlesToChange.isEmpty, true );
39
+ expect (map.circleUpdates.last .circleIdsToRemove.isEmpty, true );
40
+ expect (map.circleUpdates.last .circlesToChange.isEmpty, true );
53
41
});
54
42
55
43
testWidgets ('Adding a circle' , (WidgetTester tester) async {
@@ -59,16 +47,15 @@ void main() {
59
47
await tester.pumpWidget (_mapWithCircles (< Circle > {c1}));
60
48
await tester.pumpWidget (_mapWithCircles (< Circle > {c1, c2}));
61
49
62
- final FakePlatformGoogleMap platformGoogleMap =
63
- fakePlatformViewsController.lastCreatedView! ;
64
- expect (platformGoogleMap.circlesToAdd.length, 1 );
50
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
51
+ expect (map.circleUpdates.last.circlesToAdd.length, 1 );
65
52
66
- final Circle addedCircle = platformGoogleMap .circlesToAdd.first;
53
+ final Circle addedCircle = map.circleUpdates.last .circlesToAdd.first;
67
54
expect (addedCircle, equals (c2));
68
55
69
- expect (platformGoogleMap .circleIdsToRemove.isEmpty, true );
56
+ expect (map.circleUpdates.last .circleIdsToRemove.isEmpty, true );
70
57
71
- expect (platformGoogleMap .circlesToChange.isEmpty, true );
58
+ expect (map.circleUpdates.last .circlesToChange.isEmpty, true );
72
59
});
73
60
74
61
testWidgets ('Removing a circle' , (WidgetTester tester) async {
@@ -77,13 +64,12 @@ void main() {
77
64
await tester.pumpWidget (_mapWithCircles (< Circle > {c1}));
78
65
await tester.pumpWidget (_mapWithCircles (< Circle > {}));
79
66
80
- final FakePlatformGoogleMap platformGoogleMap =
81
- fakePlatformViewsController.lastCreatedView! ;
82
- expect (platformGoogleMap.circleIdsToRemove.length, 1 );
83
- expect (platformGoogleMap.circleIdsToRemove.first, equals (c1.circleId));
67
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
68
+ expect (map.circleUpdates.last.circleIdsToRemove.length, 1 );
69
+ expect (map.circleUpdates.last.circleIdsToRemove.first, equals (c1.circleId));
84
70
85
- expect (platformGoogleMap .circlesToChange.isEmpty, true );
86
- expect (platformGoogleMap .circlesToAdd.isEmpty, true );
71
+ expect (map.circleUpdates.last .circlesToChange.isEmpty, true );
72
+ expect (map.circleUpdates.last .circlesToAdd.isEmpty, true );
87
73
});
88
74
89
75
testWidgets ('Updating a circle' , (WidgetTester tester) async {
@@ -93,13 +79,12 @@ void main() {
93
79
await tester.pumpWidget (_mapWithCircles (< Circle > {c1}));
94
80
await tester.pumpWidget (_mapWithCircles (< Circle > {c2}));
95
81
96
- final FakePlatformGoogleMap platformGoogleMap =
97
- fakePlatformViewsController.lastCreatedView! ;
98
- expect (platformGoogleMap.circlesToChange.length, 1 );
99
- expect (platformGoogleMap.circlesToChange.first, equals (c2));
82
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
83
+ expect (map.circleUpdates.last.circlesToChange.length, 1 );
84
+ expect (map.circleUpdates.last.circlesToChange.first, equals (c2));
100
85
101
- expect (platformGoogleMap .circleIdsToRemove.isEmpty, true );
102
- expect (platformGoogleMap .circlesToAdd.isEmpty, true );
86
+ expect (map.circleUpdates.last .circleIdsToRemove.isEmpty, true );
87
+ expect (map.circleUpdates.last .circlesToAdd.isEmpty, true );
103
88
});
104
89
105
90
testWidgets ('Updating a circle' , (WidgetTester tester) async {
@@ -109,11 +94,10 @@ void main() {
109
94
await tester.pumpWidget (_mapWithCircles (< Circle > {c1}));
110
95
await tester.pumpWidget (_mapWithCircles (< Circle > {c2}));
111
96
112
- final FakePlatformGoogleMap platformGoogleMap =
113
- fakePlatformViewsController.lastCreatedView! ;
114
- expect (platformGoogleMap.circlesToChange.length, 1 );
97
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
98
+ expect (map.circleUpdates.last.circlesToChange.length, 1 );
115
99
116
- final Circle update = platformGoogleMap .circlesToChange.first;
100
+ final Circle update = map.circleUpdates.last .circlesToChange.first;
117
101
expect (update, equals (c2));
118
102
expect (update.radius, 10 );
119
103
});
@@ -129,12 +113,11 @@ void main() {
129
113
await tester.pumpWidget (_mapWithCircles (prev));
130
114
await tester.pumpWidget (_mapWithCircles (cur));
131
115
132
- final FakePlatformGoogleMap platformGoogleMap =
133
- fakePlatformViewsController.lastCreatedView! ;
116
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
134
117
135
- expect (platformGoogleMap .circlesToChange, cur);
136
- expect (platformGoogleMap .circleIdsToRemove.isEmpty, true );
137
- expect (platformGoogleMap .circlesToAdd.isEmpty, true );
118
+ expect (map.circleUpdates.last .circlesToChange, cur);
119
+ expect (map.circleUpdates.last .circleIdsToRemove.isEmpty, true );
120
+ expect (map.circleUpdates.last .circlesToAdd.isEmpty, true );
138
121
});
139
122
140
123
testWidgets ('Multi Update' , (WidgetTester tester) async {
@@ -150,16 +133,15 @@ void main() {
150
133
await tester.pumpWidget (_mapWithCircles (prev));
151
134
await tester.pumpWidget (_mapWithCircles (cur));
152
135
153
- final FakePlatformGoogleMap platformGoogleMap =
154
- fakePlatformViewsController.lastCreatedView! ;
136
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
155
137
156
- expect (platformGoogleMap .circlesToChange.length, 1 );
157
- expect (platformGoogleMap .circlesToAdd.length, 1 );
158
- expect (platformGoogleMap .circleIdsToRemove.length, 1 );
138
+ expect (map.circleUpdates.last .circlesToChange.length, 1 );
139
+ expect (map.circleUpdates.last .circlesToAdd.length, 1 );
140
+ expect (map.circleUpdates.last .circleIdsToRemove.length, 1 );
159
141
160
- expect (platformGoogleMap .circlesToChange.first, equals (c2));
161
- expect (platformGoogleMap .circlesToAdd.first, equals (c1));
162
- expect (platformGoogleMap .circleIdsToRemove.first, equals (c3.circleId));
142
+ expect (map.circleUpdates.last .circlesToChange.first, equals (c2));
143
+ expect (map.circleUpdates.last .circlesToAdd.first, equals (c1));
144
+ expect (map.circleUpdates.last .circleIdsToRemove.first, equals (c3.circleId));
163
145
});
164
146
165
147
testWidgets ('Partial Update' , (WidgetTester tester) async {
@@ -173,12 +155,11 @@ void main() {
173
155
await tester.pumpWidget (_mapWithCircles (prev));
174
156
await tester.pumpWidget (_mapWithCircles (cur));
175
157
176
- final FakePlatformGoogleMap platformGoogleMap =
177
- fakePlatformViewsController.lastCreatedView! ;
158
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
178
159
179
- expect (platformGoogleMap .circlesToChange, < Circle > {c3});
180
- expect (platformGoogleMap .circleIdsToRemove.isEmpty, true );
181
- expect (platformGoogleMap .circlesToAdd.isEmpty, true );
160
+ expect (map.circleUpdates.last .circlesToChange, < Circle > {c3});
161
+ expect (map.circleUpdates.last .circleIdsToRemove.isEmpty, true );
162
+ expect (map.circleUpdates.last .circlesToAdd.isEmpty, true );
182
163
});
183
164
184
165
testWidgets ('Update non platform related attr' , (WidgetTester tester) async {
@@ -190,17 +171,42 @@ void main() {
190
171
await tester.pumpWidget (_mapWithCircles (prev));
191
172
await tester.pumpWidget (_mapWithCircles (cur));
192
173
193
- final FakePlatformGoogleMap platformGoogleMap =
194
- fakePlatformViewsController.lastCreatedView! ;
174
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
195
175
196
- expect (platformGoogleMap .circlesToChange.isEmpty, true );
197
- expect (platformGoogleMap .circleIdsToRemove.isEmpty, true );
198
- expect (platformGoogleMap .circlesToAdd.isEmpty, true );
176
+ expect (map.circleUpdates.last .circlesToChange.isEmpty, true );
177
+ expect (map.circleUpdates.last .circleIdsToRemove.isEmpty, true );
178
+ expect (map.circleUpdates.last .circlesToAdd.isEmpty, true );
199
179
});
200
- }
201
180
202
- /// This allows a value of type T or T? to be treated as a value of type T?.
203
- ///
204
- /// We use this so that APIs that have become non-nullable can still be used
205
- /// with `!` and `?` on the stable branch.
206
- T ? _ambiguate <T >(T ? value) => value;
181
+ testWidgets ('multi-update with delays' , (WidgetTester tester) async {
182
+ platform.simulatePlatformDelay = true ;
183
+
184
+ const Circle c1 = Circle (circleId: CircleId ('circle_1' ));
185
+ const Circle c2 = Circle (circleId: CircleId ('circle_2' ));
186
+ const Circle c3 = Circle (circleId: CircleId ('circle_3' ), radius: 1 );
187
+ const Circle c3updated = Circle (circleId: CircleId ('circle_3' ), radius: 10 );
188
+
189
+ // First remove one and add another, then update the new one.
190
+ await tester.pumpWidget (_mapWithCircles (< Circle > {c1, c2}));
191
+ await tester.pumpWidget (_mapWithCircles (< Circle > {c1, c3}));
192
+ await tester.pumpWidget (_mapWithCircles (< Circle > {c1, c3updated}));
193
+
194
+ final PlatformMapStateRecorder map = platform.lastCreatedMap;
195
+
196
+ expect (map.circleUpdates.length, 3 );
197
+
198
+ expect (map.circleUpdates[0 ].circlesToChange.isEmpty, true );
199
+ expect (map.circleUpdates[0 ].circlesToAdd, < Circle > {c1, c2});
200
+ expect (map.circleUpdates[0 ].circleIdsToRemove.isEmpty, true );
201
+
202
+ expect (map.circleUpdates[1 ].circlesToChange.isEmpty, true );
203
+ expect (map.circleUpdates[1 ].circlesToAdd, < Circle > {c3});
204
+ expect (map.circleUpdates[1 ].circleIdsToRemove, < CircleId > {c2.circleId});
205
+
206
+ expect (map.circleUpdates[2 ].circlesToChange, < Circle > {c3updated});
207
+ expect (map.circleUpdates[2 ].circlesToAdd.isEmpty, true );
208
+ expect (map.circleUpdates[2 ].circleIdsToRemove.isEmpty, true );
209
+
210
+ await tester.pumpAndSettle ();
211
+ });
212
+ }
0 commit comments