Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/668 update state #679

Merged
merged 8 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ Please also see the [contribution guide in the root folder](../CONTRIBUTING.md).
- Run `dart pub get` to fetch all dart dependencies
- Run `flutter pub get` to fetch all flutter dependencies and setup all
generated code
- Run `flutter pub run build_runner build --delete-conflicting-outputs`
- Run `flutter pub run build_runner build --delete-conflicting-outputs` or
`flutter pub run build_runner watch --delete-conflicting-outputs` to
re-generate code upon file changes while developing

You should now be able to run the app by opening the debug panel on the left and
pressing the green triangle at the top (or using the shortcut <kbd>F5</kbd>).

## Useful Shortcuts

For (cleaning) generated code, you might want to add the following aliases to
your shell configuration:

```bash
alias flutter-generate='flutter pub run build_runner build --delete-conflicting-outputs'
alias flutter-clean='find . -maxdepth 20 -type f \( -name "*.inject.summary" -o -name "*.inject.dart" -o -name "*.g.dart" \) -delete'
```

## Architecture

The app consists of multiple so-called modules. Our main modules correspond to
Expand Down
86 changes: 48 additions & 38 deletions app/integration_test/drugs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 MockDrugsCubit extends MockCubit<DrugState> implements DrugCubit {}

Expand Down Expand Up @@ -83,21 +84,24 @@ void main() {
late BuildContext context;

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) {
return DrugPage(testDrug, cubit: mockDrugsCubit);
},
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) {
return DrugPage(testDrug, cubit: mockDrugsCubit);
},
),
),
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 Expand Up @@ -151,24 +155,27 @@ void main() {
DrugState.loaded());

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) {
return DrugPage(
testDrugWithoutGuidelines,
cubit: mockDrugsCubit,
);
},
ChangeNotifierProvider(
create: (context) => ActiveDrugs(),
child: MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) {
return DrugPage(
testDrugWithoutGuidelines,
cubit: mockDrugsCubit,
);
},
),
),
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 All @@ -180,15 +187,18 @@ void main() {
when(() => mockDrugsCubit.state).thenReturn(DrugState.loading());

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

Expand Down
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
Loading
Loading