|
6 | 6 | @import google_maps_flutter.Test;
|
7 | 7 | @import XCTest;
|
8 | 8 | @import MapKit;
|
| 9 | +@import GoogleMaps; |
9 | 10 |
|
10 | 11 | #import <OCMock/OCMock.h>
|
11 | 12 | #import "PartiallyMockedMapView.h"
|
@@ -75,29 +76,216 @@ - (void)testHolesFromPointsArray {
|
75 | 76 | XCTAssertEqual(holes[1][1].coordinate.longitude, 8);
|
76 | 77 | }
|
77 | 78 |
|
78 |
| -- (void)testDictionaryFromPosition{ |
| 79 | +- (void)testDictionaryFromPosition { |
79 | 80 | id mockPosition = OCMClassMock([GMSCameraPosition class]);
|
80 | 81 | NSValue *locationValue = [NSValue valueWithMKCoordinate:CLLocationCoordinate2DMake(1, 2)];
|
81 | 82 | [(GMSCameraPosition *)[[mockPosition stub] andReturnValue:locationValue] target];
|
82 | 83 | [[[mockPosition stub] andReturnValue:@(2.0)] zoom];
|
83 | 84 | [[[mockPosition stub] andReturnValue:@(3.0)] bearing];
|
84 | 85 | [[[mockPosition stub] andReturnValue:@(75.0)] viewingAngle];
|
85 | 86 | NSDictionary *dictionary = [FLTGoogleMapJSONConversions dictionaryFromPosition:mockPosition];
|
86 |
| - NSArray *targetArray = @[@1, @2]; |
| 87 | + NSArray *targetArray = @[ @1, @2 ]; |
87 | 88 | XCTAssertEqualObjects(dictionary[@"target"], targetArray);
|
88 | 89 | XCTAssertEqualObjects(dictionary[@"zoom"], @2.0);
|
89 | 90 | XCTAssertEqualObjects(dictionary[@"bearing"], @3.0);
|
90 | 91 | XCTAssertEqualObjects(dictionary[@"tilt"], @75.0);
|
91 | 92 | }
|
92 | 93 |
|
93 |
| -@end |
| 94 | +- (void)testDictionaryFromPoint { |
| 95 | + CGPoint point = CGPointMake(10, 20); |
| 96 | + NSDictionary *dictionary = [FLTGoogleMapJSONConversions dictionaryFromPoint:point]; |
| 97 | + const CGFloat accuracy = 0.0001; |
| 98 | + XCTAssertEqualWithAccuracy([dictionary[@"x"] floatValue], point.x, accuracy); |
| 99 | + XCTAssertEqualWithAccuracy([dictionary[@"y"] floatValue], point.y, accuracy); |
| 100 | +} |
| 101 | + |
| 102 | +- (void)testDictionaryFromCoordinateBounds { |
| 103 | + XCTAssertNil([FLTGoogleMapJSONConversions dictionaryFromCoordinateBounds:nil]); |
| 104 | + |
| 105 | + GMSCoordinateBounds *bounds = |
| 106 | + [[GMSCoordinateBounds alloc] initWithCoordinate:CLLocationCoordinate2DMake(10, 20) |
| 107 | + coordinate:CLLocationCoordinate2DMake(30, 40)]; |
| 108 | + NSDictionary *dictionary = [FLTGoogleMapJSONConversions dictionaryFromCoordinateBounds:bounds]; |
| 109 | + NSArray *southwest = @[ @10, @20 ]; |
| 110 | + NSArray *northeast = @[ @30, @40 ]; |
| 111 | + XCTAssertEqualObjects(dictionary[@"southwest"], southwest); |
| 112 | + XCTAssertEqualObjects(dictionary[@"northeast"], northeast); |
| 113 | +} |
| 114 | + |
| 115 | +- (void)testCameraPostionFromDictionary { |
| 116 | + XCTAssertNil([FLTGoogleMapJSONConversions cameraPostionFromDictionary:nil]); |
| 117 | + |
| 118 | + NSDictionary *channelValue = |
| 119 | + @{@"target" : @[ @(1), @(2) ], @"zoom" : @3, @"bearing" : @4, @"tilt" : @5}; |
| 120 | + |
| 121 | + GMSCameraPosition *cameraPosition = |
| 122 | + [FLTGoogleMapJSONConversions cameraPostionFromDictionary:channelValue]; |
| 123 | + |
| 124 | + const CGFloat accuracy = 0.001; |
| 125 | + XCTAssertEqualWithAccuracy(cameraPosition.target.latitude, 1, accuracy); |
| 126 | + XCTAssertEqualWithAccuracy(cameraPosition.target.longitude, 2, accuracy); |
| 127 | + XCTAssertEqualWithAccuracy(cameraPosition.zoom, 3, accuracy); |
| 128 | + XCTAssertEqualWithAccuracy(cameraPosition.bearing, 4, accuracy); |
| 129 | + XCTAssertEqualWithAccuracy(cameraPosition.viewingAngle, 5, accuracy); |
| 130 | +} |
| 131 | + |
| 132 | +- (void)testPointFromDictionary { |
| 133 | + XCTAssertNil([FLTGoogleMapJSONConversions cameraPostionFromDictionary:nil]); |
| 134 | + |
| 135 | + NSDictionary *dictionary = @{ |
| 136 | + @"x" : @1, |
| 137 | + @"y" : @2, |
| 138 | + }; |
| 139 | + |
| 140 | + CGPoint point = [FLTGoogleMapJSONConversions pointFromDictionary:dictionary]; |
| 141 | + |
| 142 | + const CGFloat accuracy = 0.001; |
| 143 | + XCTAssertEqualWithAccuracy(point.x, 1, accuracy); |
| 144 | + XCTAssertEqualWithAccuracy(point.y, 2, accuracy); |
| 145 | +} |
| 146 | + |
| 147 | +- (void)testCoordinateBoundsFromLatlongs { |
| 148 | + NSArray<NSNumber *> *latlong1 = @[ @(1), @(2) ]; |
| 149 | + NSArray<NSNumber *> *latlong2 = @[ @(3), @(4) ]; |
| 150 | + |
| 151 | + GMSCoordinateBounds *bounds = |
| 152 | + [FLTGoogleMapJSONConversions coordinateBoundsFromLatlongs:@[ latlong1, latlong2 ]]; |
| 153 | + |
| 154 | + const CGFloat accuracy = 0.001; |
| 155 | + XCTAssertEqualWithAccuracy(bounds.southWest.latitude, 1, accuracy); |
| 156 | + XCTAssertEqualWithAccuracy(bounds.southWest.longitude, 2, accuracy); |
| 157 | + XCTAssertEqualWithAccuracy(bounds.northEast.latitude, 3, accuracy); |
| 158 | + XCTAssertEqualWithAccuracy(bounds.northEast.longitude, 4, accuracy); |
| 159 | +} |
| 160 | + |
| 161 | +- (void)testMapViewTypeFromTypeValue { |
| 162 | + XCTAssertEqual(kGMSTypeNormal, [FLTGoogleMapJSONConversions mapViewTypeFromTypeValue:@1]); |
| 163 | + XCTAssertEqual(kGMSTypeSatellite, [FLTGoogleMapJSONConversions mapViewTypeFromTypeValue:@2]); |
| 164 | + XCTAssertEqual(kGMSTypeTerrain, [FLTGoogleMapJSONConversions mapViewTypeFromTypeValue:@3]); |
| 165 | + XCTAssertEqual(kGMSTypeHybrid, [FLTGoogleMapJSONConversions mapViewTypeFromTypeValue:@4]); |
| 166 | + XCTAssertEqual(kGMSTypeNone, [FLTGoogleMapJSONConversions mapViewTypeFromTypeValue:@5]); |
| 167 | +} |
| 168 | + |
| 169 | +- (void)testCameraUpdateFromChannelValueNewCameraPosition { |
| 170 | + NSArray *channelValue = @[ |
| 171 | + @"newCameraPosition", |
| 172 | + @{@"target" : @[ @(1), @(2) ], @"zoom" : @3, @"bearing" : @4, @"tilt" : @5} |
| 173 | + ]; |
| 174 | + id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]); |
| 175 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValue]; |
| 176 | + [[classMockCameraUpdate expect] |
| 177 | + setCamera:[FLTGoogleMapJSONConversions cameraPostionFromDictionary:channelValue[1]]]; |
| 178 | + [classMockCameraUpdate stopMocking]; |
| 179 | +} |
| 180 | + |
| 181 | +// TODO(cyanglaz): Fix the test for CameraUpdateFromChannelValue with the "NewLatlng" key. |
| 182 | +// 2 approaches have been tried and neither worked for the tests. |
| 183 | +// |
| 184 | +// 1. Use OCMock to vefiry that [GMSCameraUpdate setTarget:] is triggered with the correct value. |
| 185 | +// This class method conflicts with certain category method in OCMock, causing OCMock not able to |
| 186 | +// disambigious them. |
| 187 | +// |
| 188 | +// 2. Directly verify the GMSCameraUpdate object returned by the method. |
| 189 | +// The GMSCameraUpdate object returned from the method doesn't have any accessors to the "target" |
| 190 | +// property. It can be used to update the "camera" property in GMSMapView. However, [GMSMapView |
| 191 | +// moveCamera:] doesn't update the camera immediately. Thus the GMSCameraUpdate object cannot be |
| 192 | +// verified. |
| 193 | +// |
| 194 | +// The code in below test uses the 2nd approach. |
| 195 | +- (void)skip_testCameraUpdateFromChannelValueNewLatlong { |
| 196 | + NSArray *channelValue = @[ @"newLatLng", @[ @1, @2 ] ]; |
| 197 | + |
| 198 | + GMSCameraUpdate *update = [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValue]; |
| 199 | + |
| 200 | + GMSMapView *mapView = [[GMSMapView alloc] |
| 201 | + initWithFrame:CGRectZero |
| 202 | + camera:[GMSCameraPosition cameraWithTarget:CLLocationCoordinate2DMake(5, 6) zoom:1]]; |
| 203 | + [mapView moveCamera:update]; |
| 204 | + const CGFloat accuracy = 0.001; |
| 205 | + XCTAssertEqualWithAccuracy(mapView.camera.target.latitude, 1, |
| 206 | + accuracy); // mapView.camera.target.latitude is still 5. |
| 207 | + XCTAssertEqualWithAccuracy(mapView.camera.target.longitude, 2, |
| 208 | + accuracy); // mapView.camera.target.longitude is still 6. |
| 209 | +} |
| 210 | + |
| 211 | +- (void)testCameraUpdateFromChannelValueNewLatLngBounds { |
| 212 | + NSArray<NSNumber *> *latlong1 = @[ @(1), @(2) ]; |
| 213 | + NSArray<NSNumber *> *latlong2 = @[ @(3), @(4) ]; |
| 214 | + GMSCoordinateBounds *bounds = |
| 215 | + [FLTGoogleMapJSONConversions coordinateBoundsFromLatlongs:@[ latlong1, latlong2 ]]; |
| 216 | + |
| 217 | + NSArray *channelValue = @[ @"newLatLngBounds", @[ latlong1, latlong2 ], @20 ]; |
| 218 | + id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]); |
| 219 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValue]; |
94 | 220 |
|
95 |
| -//+ (nullable NSDictionary<NSString *, id> *)dictionaryFromPosition: |
96 |
| -// (nullable GMSCameraPosition *)position; |
97 |
| -//+ (NSDictionary<NSString *, NSNumber *> *)dictionaryFromPoint:(CGPoint)point; |
98 |
| -//+ (nullable NSDictionary *)dictionaryFromCoordinateBounds:(nullable GMSCoordinateBounds *)bounds; |
99 |
| -//+ (nullable GMSCameraPosition *)cameraPostionFromDictionary:(nullable NSDictionary *)channelValue; |
100 |
| -//+ (CGPoint)pointFromDictionary:(NSDictionary *)dictionary; |
101 |
| -//+ (GMSCoordinateBounds *)coordinateBoundsFromLatlong:(NSArray *)latlong; |
102 |
| -//+ (GMSMapViewType)mapViewTypeFromTypeValue:(NSNumber *)value; |
103 |
| -//+ (nullable GMSCameraUpdate *)cameraUpdateFromChannelValue:(NSArray *)channelValue; |
| 221 | + [[classMockCameraUpdate expect] fitBounds:bounds withPadding:20]; |
| 222 | + [classMockCameraUpdate stopMocking]; |
| 223 | +} |
| 224 | + |
| 225 | +- (void)testCameraUpdateFromChannelValueNewLatLngZoom { |
| 226 | + NSArray *channelValue = @[ @"newLatLngZoom", @[ @1, @2 ], @3 ]; |
| 227 | + |
| 228 | + id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]); |
| 229 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValue]; |
| 230 | + |
| 231 | + [[classMockCameraUpdate expect] setTarget:CLLocationCoordinate2DMake(1, 2) zoom:3]; |
| 232 | + [classMockCameraUpdate stopMocking]; |
| 233 | +} |
| 234 | + |
| 235 | +- (void)testCameraUpdateFromChannelValueScrollBy { |
| 236 | + NSArray *channelValue = @[ @"scrollBy", @1, @2 ]; |
| 237 | + |
| 238 | + id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]); |
| 239 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValue]; |
| 240 | + |
| 241 | + [[classMockCameraUpdate expect] scrollByX:1 Y:2]; |
| 242 | + [classMockCameraUpdate stopMocking]; |
| 243 | +} |
| 244 | + |
| 245 | +- (void)testCameraUpdateFromChannelValueZoomBy { |
| 246 | + NSArray *channelValueNoPoint = @[ @"zoomBy", @1 ]; |
| 247 | + |
| 248 | + id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]); |
| 249 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValueNoPoint]; |
| 250 | + |
| 251 | + [[classMockCameraUpdate expect] zoomBy:1]; |
| 252 | + |
| 253 | + NSArray *channelValueWithPoint = @[ @"zoomBy", @1, @[ @2, @3 ] ]; |
| 254 | + |
| 255 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValueWithPoint]; |
| 256 | + |
| 257 | + [[classMockCameraUpdate expect] zoomBy:1 atPoint:CGPointMake(2, 3)]; |
| 258 | + [classMockCameraUpdate stopMocking]; |
| 259 | +} |
| 260 | + |
| 261 | +- (void)testCameraUpdateFromChannelValueZoomIn { |
| 262 | + NSArray *channelValueNoPoint = @[ @"zoomIn" ]; |
| 263 | + |
| 264 | + id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]); |
| 265 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValueNoPoint]; |
| 266 | + |
| 267 | + [[classMockCameraUpdate expect] zoomIn]; |
| 268 | + [classMockCameraUpdate stopMocking]; |
| 269 | +} |
| 270 | + |
| 271 | +- (void)testCameraUpdateFromChannelValueZoomOut { |
| 272 | + NSArray *channelValueNoPoint = @[ @"zoomOut" ]; |
| 273 | + |
| 274 | + id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]); |
| 275 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValueNoPoint]; |
| 276 | + |
| 277 | + [[classMockCameraUpdate expect] zoomOut]; |
| 278 | + [classMockCameraUpdate stopMocking]; |
| 279 | +} |
| 280 | + |
| 281 | +- (void)testCameraUpdateFromChannelValueZoomTo { |
| 282 | + NSArray *channelValueNoPoint = @[ @"zoomTo", @1 ]; |
| 283 | + |
| 284 | + id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]); |
| 285 | + [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValueNoPoint]; |
| 286 | + |
| 287 | + [[classMockCameraUpdate expect] zoomTo:1]; |
| 288 | + [classMockCameraUpdate stopMocking]; |
| 289 | +} |
| 290 | + |
| 291 | +@end |
0 commit comments