Skip to content

Commit

Permalink
Mock firebase in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vyPal committed Feb 9, 2024
1 parent 75a4a28 commit c685127
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion integration_test/app_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

Expand All @@ -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())
Expand Down Expand Up @@ -66,7 +72,20 @@ Future<void> 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"));
Expand All @@ -76,5 +95,35 @@ Future<void> 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(),
);
}
}

0 comments on commit c685127

Please sign in to comment.