|
| 1 | +// Copyright 2013 The Flutter Authors |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter/widgets.dart'; |
| 6 | +import 'package:flutter_test/flutter_test.dart'; |
| 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 | + |
| 10 | +import 'fake_google_maps_flutter_platform.dart'; |
| 11 | + |
| 12 | +void main() { |
| 13 | + TestWidgetsFlutterBinding.ensureInitialized(); |
| 14 | + late FakeGoogleMapsFlutterPlatform platform; |
| 15 | + |
| 16 | + setUp(() { |
| 17 | + platform = FakeGoogleMapsFlutterPlatform(); |
| 18 | + GoogleMapsFlutterPlatform.instance = platform; |
| 19 | + }); |
| 20 | + |
| 21 | + testWidgets('onPointOfInterestTap callback receives place ID from platform event', ( |
| 22 | + WidgetTester tester, |
| 23 | + ) async { |
| 24 | + PointOfInterestId? tappedPointOfInterestId; |
| 25 | + |
| 26 | + await tester.pumpWidget( |
| 27 | + Directionality( |
| 28 | + textDirection: TextDirection.ltr, |
| 29 | + child: GoogleMap( |
| 30 | + initialCameraPosition: const CameraPosition(target: LatLng(0.0, 0.0)), |
| 31 | + onPointOfInterestTap: (PointOfInterestId pointOfInterestId) { |
| 32 | + tappedPointOfInterestId = pointOfInterestId; |
| 33 | + }, |
| 34 | + ), |
| 35 | + ), |
| 36 | + ); |
| 37 | + |
| 38 | + await tester.pump(); |
| 39 | + |
| 40 | + expect(platform.createdIds, isNotEmpty); |
| 41 | + final int mapId = platform.createdIds.first; |
| 42 | + |
| 43 | + platform.mapEventStreamController.add( |
| 44 | + PointOfInterestTapEvent(mapId, const PointOfInterestId('place-123')), |
| 45 | + ); |
| 46 | + |
| 47 | + await tester.pump(); |
| 48 | + |
| 49 | + expect(tappedPointOfInterestId, const PointOfInterestId('place-123')); |
| 50 | + }); |
| 51 | +} |
0 commit comments