From ef3a47632e835eec7133791dedd2b18e342a8a1d Mon Sep 17 00:00:00 2001 From: Cynthia Wang Date: Thu, 21 Sep 2023 13:41:45 -0400 Subject: [PATCH] fix: update versions --- firestore/.vscode/settings.json | 3 ++ firestore/android/app/build.gradle | 3 ++ firestore/android/build.gradle | 3 ++ firestore/firebase.json | 18 ++++++++ .../integration_test/friendly_eats_test.dart | 42 +++++++++++++++++++ firestore/lib/main.dart | 11 +++++ .../lib/src/data/restaurant_provider.dart | 6 +-- firestore/pubspec.yaml | 17 ++++++-- firestore/test_driver/integration_test.dart | 3 ++ .../flutter/generated_plugin_registrant.cc | 6 +++ 10 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 firestore/.vscode/settings.json create mode 100644 firestore/firebase.json create mode 100644 firestore/integration_test/friendly_eats_test.dart create mode 100644 firestore/test_driver/integration_test.dart diff --git a/firestore/.vscode/settings.json b/firestore/.vscode/settings.json new file mode 100644 index 00000000..c5f3f6b9 --- /dev/null +++ b/firestore/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/firestore/android/app/build.gradle b/firestore/android/app/build.gradle index 7715865e..ded18ffb 100644 --- a/firestore/android/app/build.gradle +++ b/firestore/android/app/build.gradle @@ -22,6 +22,9 @@ if (flutterVersionName == null) { } apply plugin: 'com.android.application' +// START: FlutterFire Configuration +apply plugin: 'com.google.gms.google-services' +// END: FlutterFire Configuration apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" diff --git a/firestore/android/build.gradle b/firestore/android/build.gradle index 4256f917..111a0724 100644 --- a/firestore/android/build.gradle +++ b/firestore/android/build.gradle @@ -7,6 +7,9 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.1.0' + // START: FlutterFire Configuration + classpath 'com.google.gms:google-services:4.3.10' + // END: FlutterFire Configuration classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/firestore/firebase.json b/firestore/firebase.json new file mode 100644 index 00000000..494cec0a --- /dev/null +++ b/firestore/firebase.json @@ -0,0 +1,18 @@ +{ + "firestore": { + "rules": "firestore.rules", + "indexes": "firestore.indexes.json" + }, + "emulators": { + "auth": { + "port": 9099 + }, + "firestore": { + "port": 8080 + }, + "ui": { + "enabled": true + }, + "singleProjectMode": true + } +} diff --git a/firestore/integration_test/friendly_eats_test.dart b/firestore/integration_test/friendly_eats_test.dart new file mode 100644 index 00000000..fa13ab76 --- /dev/null +++ b/firestore/integration_test/friendly_eats_test.dart @@ -0,0 +1,42 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:firestore/firebase_options.dart'; +import 'package:firestore/src/app.dart'; +import 'package:firestore/src/widgets/restaurant_card.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +bool USE_FIRESTORE_EMULATOR = true; + +Future main() async { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,); + final hostUrl = defaultTargetPlatform == TargetPlatform.android ? "10.0.2.2" : "localhost"; + if (USE_FIRESTORE_EMULATOR) { + FirebaseFirestore.instance.useFirestoreEmulator(hostUrl, 8080); + await FirebaseAuth.instance.useAuthEmulator(hostUrl, 9099); + await FirebaseAuth.instance.signInAnonymously(); + } + group('Integration Tests', () { + testWidgets('Test empty home page', (tester) async { + await tester.pumpWidget(FriendlyEatsApp()); + expect(find.text('FriendlyEats has no restaurants yet!'), findsOneWidget); + expect(find.text('ADD SOME'), findsOneWidget); + await tester.tap(find.text('ADD SOME').first); + await tester.pumpAndSettle(const Duration(seconds: 1)); + expect(find.byIcon(Icons.star), findsWidgets); + }); + testWidgets('view restaurant page', (tester) async { + await tester.pumpWidget(FriendlyEatsApp()); + await tester.tap(find.byType(RestaurantCard)); + await tester.pumpAndSettle(const Duration(seconds: 1)); + expect(find.text('Add Random Reviews'), findsOneWidget); + await tester.tap(find.text('Add Random Reviews')); + await tester.pumpAndSettle(const Duration(seconds: 1)); + expect(find.text('Anonymous User'), findsWidgets); + }); + }); +} \ No newline at end of file diff --git a/firestore/lib/main.dart b/firestore/lib/main.dart index 340557fd..1fe8fa73 100644 --- a/firestore/lib/main.dart +++ b/firestore/lib/main.dart @@ -1,7 +1,9 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; import 'firebase_options.dart'; import 'src/app.dart'; @@ -11,6 +13,15 @@ void main() async { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); + if (kDebugMode) { + try { + FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080); + await FirebaseAuth.instance.useAuthEmulator('localhost', 9099); + } catch (e) { + // ignore: avoid_print + print(e); + } + } // required to interact with Firestore due to security Rules await FirebaseAuth.instance.signInAnonymously(); diff --git a/firestore/lib/src/data/restaurant_provider.dart b/firestore/lib/src/data/restaurant_provider.dart index 9fc0f8d0..de7c9165 100644 --- a/firestore/lib/src/data/restaurant_provider.dart +++ b/firestore/lib/src/data/restaurant_provider.dart @@ -18,7 +18,7 @@ import 'dart:async'; import 'package:cloud_firestore/cloud_firestore.dart'; -import '../model/filter.dart'; +import '../model/filter.dart' as SearchFilter; import '../model/restaurant.dart'; import '../model/review.dart'; @@ -29,7 +29,7 @@ abstract class RestaurantProvider { {required String restaurantId, required Review review}); void addRestaurantsBatch(List restaurants); void loadAllRestaurants(); - void loadFilteredRestaurants(Filter filter); + void loadFilteredRestaurants(SearchFilter.Filter filter); Future getRestaurantById(String restaurantId); void dispose(); } @@ -116,7 +116,7 @@ class FirestoreRestaurantProvider implements RestaurantProvider { } @override - void loadFilteredRestaurants(Filter filter) { + void loadFilteredRestaurants(SearchFilter.Filter filter) { Query collection = FirebaseFirestore.instance.collection('restaurants'); if (filter.category != null) { collection = collection.where('category', isEqualTo: filter.category); diff --git a/firestore/pubspec.yaml b/firestore/pubspec.yaml index 89f32d45..b60890f4 100644 --- a/firestore/pubspec.yaml +++ b/firestore/pubspec.yaml @@ -11,14 +11,25 @@ dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.2 - firebase_core: ^1.15.0 - firebase_auth: ^3.3.15 - cloud_firestore: ^3.1.13 + firebase_core: ^2.16.0 + firebase_auth: ^4.10.0 + cloud_firestore: ^4.9.2 + provider: ^6.0.5 + go_router: ^10.2.0 + http: ^1.1.0 + fake_cloud_firestore: ^2.4.1+1 dev_dependencies: pedantic: ^1.9.0 flutter_test: sdk: flutter + integration_test: + sdk: flutter + flutter_driver: + sdk: flutter + test: ^1.24.3 + mockito: ^5.4.2 + build_runner: ^2.4.6 # The following section is specific to Flutter. flutter: diff --git a/firestore/test_driver/integration_test.dart b/firestore/test_driver/integration_test.dart new file mode 100644 index 00000000..b38629cc --- /dev/null +++ b/firestore/test_driver/integration_test.dart @@ -0,0 +1,3 @@ +import 'package:integration_test/integration_test_driver.dart'; + +Future main() => integrationDriver(); diff --git a/firestore/windows/flutter/generated_plugin_registrant.cc b/firestore/windows/flutter/generated_plugin_registrant.cc index 8b6d4680..d141b74f 100644 --- a/firestore/windows/flutter/generated_plugin_registrant.cc +++ b/firestore/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,12 @@ #include "generated_plugin_registrant.h" +#include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + FirebaseAuthPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FirebaseAuthPluginCApi")); + FirebaseCorePluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FirebaseCorePluginCApi")); }