From c6851272f53ddddf22d294995a09b4facd7b9b98 Mon Sep 17 00:00:00 2001 From: vyPal <66716025+vyPal@users.noreply.github.com> Date: Fri, 9 Feb 2024 09:32:30 +0100 Subject: [PATCH] Mock firebase in tests --- integration_test/app_test.dart | 51 +++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 003e93f..ef5032b 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -1,3 +1,6 @@ +import 'package:eduapge2/firebase_options.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_remote_config/firebase_remote_config.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -6,6 +9,7 @@ import 'package:integration_test/integration_test.dart'; import 'package:eduapge2/main.dart' as app; import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'utils.dart'; @@ -25,6 +29,8 @@ void main() { testWidgets('Test TimeTable page', (tester) async { await prep(tester, username, password, name); + await tester.pump(const Duration(seconds: 1)); + await tester.tap(find.byType(NavigationDestination).at(1)); await tester.pump(const Duration(seconds: 1)); String day = DateFormat('d', const Locale('en', 'US').toString()) @@ -66,7 +72,20 @@ Future prep( WidgetTester tester, String username, String password, String name) async { SharedPreferences.setMockInitialValues({}); final FlutterExceptionHandler? originalOnError = FlutterError.onError; - app.main(); + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); + final remoteConfig = FirebaseRemoteConfig.instance; + await remoteConfig.setConfigSettings(RemoteConfigSettings( + fetchTimeout: const Duration(minutes: 1), + minimumFetchInterval: const Duration(hours: 1), + )); + await remoteConfig.setDefaults(const { + "baseUrl": "https://lobster-app-z6jfk.ondigitalocean.app/api", + "testUrl": "https://ep2.vypal.me" + }); + await remoteConfig.activate(); + runApp(const MyTestApp()); await tester.pumpAndSettle(); FlutterError.onError = originalOnError; await pumpUntilFound(tester, find.text("Username")); @@ -76,5 +95,35 @@ Future prep( await tester.tap(find.byType(ElevatedButton)); await pumpUntilFound(tester, find.text(name)); + await tester.pumpAndSettle(); await tester.pump(const Duration(seconds: 1)); } + +class MyTestApp extends StatelessWidget { + const MyTestApp({super.key}); + static final _defaultLightColorScheme = + ColorScheme.fromSwatch(primarySwatch: Colors.blue); + + static final _defaultDarkColorScheme = ColorScheme.fromSwatch( + primarySwatch: Colors.blue, brightness: Brightness.dark); + + // This widget is the root of your application. + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'EduPage2', + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + theme: ThemeData( + colorScheme: _defaultLightColorScheme, + useMaterial3: true, + ), + darkTheme: ThemeData( + colorScheme: _defaultDarkColorScheme, + useMaterial3: true, + ), + themeMode: ThemeMode.dark, + home: const app.PageBase(), + ); + } +}