Skip to content

Commit

Permalink
feat(#668): add provider to further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 22, 2023
1 parent fc29ce2 commit e08c9a4
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 73 deletions.
85 changes: 49 additions & 36 deletions app/integration_test/login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:provider/provider.dart';

class MockLoginCubit extends MockCubit<LoginPageState>
implements LoginPageCubit {}
Expand All @@ -23,15 +24,18 @@ void main() {
);

await tester.pumpWidget(
MaterialApp(
home: LoginPage(cubit: mockLoginCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp(
home: LoginPage(cubit: mockLoginCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
),
);

Expand All @@ -44,15 +48,18 @@ void main() {
);

await tester.pumpWidget(
MaterialApp(
home: LoginPage(cubit: mockLoginCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp(
home: LoginPage(cubit: mockLoginCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
),
);

Expand All @@ -67,15 +74,18 @@ void main() {
);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: LoginPage(cubit: mockLoginCubit)),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp(
home: Scaffold(body: LoginPage(cubit: mockLoginCubit)),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
),
);

Expand All @@ -91,15 +101,18 @@ void main() {
);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: LoginPage(cubit: mockLoginCubit)),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp(
home: Scaffold(body: LoginPage(cubit: mockLoginCubit)),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
),
);

Expand Down
26 changes: 15 additions & 11 deletions app/integration_test/main_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:app/common/module.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:provider/provider.dart';

void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Expand All @@ -19,18 +20,21 @@ void main() {
await initServices();
final appRouter = AppRouter();
await tester.pumpWidget(
MaterialApp.router(
routeInformationParser: appRouter.defaultRouteParser(),
routerDelegate: appRouter.delegate(
initialDeepLink: 'main',
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp.router(
routeInformationParser: appRouter.defaultRouteParser(),
routerDelegate: appRouter.delegate(
initialDeepLink: 'main',
),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
);

Expand Down
63 changes: 37 additions & 26 deletions app/integration_test/search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:provider/provider.dart';

class MockDrugListCubit extends MockCubit<DrugListState> implements DrugListCubit {
@override
Expand Down Expand Up @@ -52,20 +53,25 @@ void main() {
group('integration test for the search page', () {
testWidgets('test search page in loading state', (tester) async {
when(() => mockDrugListCubit.state).thenReturn(DrugListState.loading());
await tester.pumpWidget(BlocProvider.value(
value: mockDrugListCubit,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: SearchPage(cubit: mockDrugListCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: BlocProvider.value(
value: mockDrugListCubit,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: SearchPage(cubit: mockDrugListCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
),
),
));
);

expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
Expand All @@ -74,20 +80,25 @@ void main() {
when(() => mockDrugListCubit.state)
.thenReturn(DrugListState.loaded(loadedDrugs, FilterState.initial()));

await tester.pumpWidget(BlocProvider.value(
value: mockDrugListCubit,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: SearchPage(cubit: mockDrugListCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
await tester.pumpWidget(
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: BlocProvider.value(
value: mockDrugListCubit,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: SearchPage(cubit: mockDrugListCubit),
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en', '')],
),
),
),
));
);
await tester.pumpAndSettle();

expect(
Expand Down

0 comments on commit e08c9a4

Please sign in to comment.