-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #410 from hpi-dhc/393/add-tests
393/add tests
- Loading branch information
Showing
23 changed files
with
845 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,6 @@ app.*.map.json | |
|
||
# environment file | ||
.env | ||
|
||
# coverage files | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:app/common/module.dart'; | ||
import 'package:app/faq/constants.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
void main() { | ||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.onlyPumps; | ||
|
||
group('integration test for the faq page', () { | ||
final appRouter = AppRouter(); | ||
final faqWidget = MaterialApp.router( | ||
routeInformationParser: appRouter.defaultRouteParser(), | ||
routerDelegate: appRouter.delegate( | ||
initialDeepLink: 'main/faq', | ||
), | ||
localizationsDelegates: [ | ||
AppLocalizations.delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
], | ||
supportedLocales: [Locale('en', '')], | ||
); | ||
|
||
testWidgets('All questions are loaded and expansion tiles can be open', | ||
(tester) async { | ||
await tester.pumpWidget(faqWidget); | ||
await tester.pumpAndSettle(); | ||
|
||
expect( | ||
find | ||
.descendant( | ||
of: find.byKey(ValueKey('questions_column')), | ||
matching: find.byType(ExpansionTile), | ||
) | ||
.evaluate() | ||
.length, | ||
faqList.length, | ||
); | ||
|
||
expect(find.text(faqList[0].question), findsOneWidget); | ||
expect(find.text(faqList[0].answer), findsNothing); | ||
|
||
await tester.tap(find.byType(ExpansionTile).first); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text(faqList[0].answer), findsOneWidget); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import 'package:app/common/module.dart'; | ||
import 'package:app/login/models/lab.dart'; | ||
import 'package:app/login/module.dart'; | ||
import 'package:bloc_test/bloc_test.dart'; | ||
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'; | ||
|
||
class MockLoginCubit extends MockCubit<LoginPageState> | ||
implements LoginPageCubit {} | ||
|
||
void main() { | ||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
final mockLoginCubit = MockLoginCubit(); | ||
|
||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.onlyPumps; | ||
|
||
group('integration tests for the login page', () { | ||
testWidgets('test loading state', (tester) async { | ||
when(() => mockLoginCubit.state).thenReturn( | ||
LoginPageState.loadingUserData(), | ||
); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: LoginPage(cubit: mockLoginCubit), | ||
localizationsDelegates: [ | ||
AppLocalizations.delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
], | ||
supportedLocales: [Locale('en', '')], | ||
), | ||
); | ||
|
||
expect(find.byType(CircularProgressIndicator), findsOneWidget); | ||
}); | ||
|
||
testWidgets('test error state', (tester) async { | ||
when(() => mockLoginCubit.state).thenReturn( | ||
LoginPageState.error('Some error'), | ||
); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: LoginPage(cubit: mockLoginCubit), | ||
localizationsDelegates: [ | ||
AppLocalizations.delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
], | ||
supportedLocales: [Locale('en', '')], | ||
), | ||
); | ||
|
||
expect(find.byIcon(Icons.error_outline_rounded), findsOneWidget); | ||
|
||
expect(find.text('Some error'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('test loaded state', (tester) async { | ||
when(() => mockLoginCubit.state).thenReturn( | ||
LoginPageState.loadedUserData(), | ||
); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Scaffold(body: LoginPage(cubit: mockLoginCubit)), | ||
localizationsDelegates: [ | ||
AppLocalizations.delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
], | ||
supportedLocales: [Locale('en', '')], | ||
), | ||
); | ||
|
||
final BuildContext context = tester.element(find.byType(Scaffold).first); | ||
|
||
expect(find.byIcon(Icons.check_circle_outline), findsOneWidget); | ||
expect(find.text(context.l10n.auth_success), findsOneWidget); | ||
}); | ||
|
||
testWidgets('test initial state', (tester) async { | ||
when(() => mockLoginCubit.state).thenReturn( | ||
LoginPageState.initial(), | ||
); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Scaffold(body: LoginPage(cubit: mockLoginCubit)), | ||
localizationsDelegates: [ | ||
AppLocalizations.delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
], | ||
supportedLocales: [Locale('en', '')], | ||
), | ||
); | ||
|
||
expect(find.byType(DropdownButtonHideUnderline), findsOneWidget); | ||
|
||
expect(find.byType(DropdownMenuItem<String>), findsNWidgets(labs.length)); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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'; | ||
|
||
void main() { | ||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.onlyPumps; | ||
|
||
group('test the main page', () { | ||
testWidgets('test that tabs change pages', (tester) async { | ||
final appRouter = AppRouter(); | ||
await tester.pumpWidget( | ||
MaterialApp.router( | ||
routeInformationParser: appRouter.defaultRouteParser(), | ||
routerDelegate: appRouter.delegate( | ||
initialDeepLink: 'main', | ||
), | ||
localizationsDelegates: [ | ||
AppLocalizations.delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
], | ||
supportedLocales: [Locale('en', '')], | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
final BuildContext context = tester.element(find.byType(Scaffold).first); | ||
|
||
expect(find.text(context.l10n.general_appName), findsOneWidget); | ||
|
||
expect(find.byIcon(Icons.search), findsOneWidget); | ||
expect(find.byIcon(Icons.assessment), findsOneWidget); | ||
expect(find.byIcon(Icons.lightbulb), findsOneWidget); | ||
expect(find.byIcon(Icons.more_horiz), findsOneWidget); | ||
|
||
// ignore: omit_local_variable_types | ||
BottomNavigationBar bar = tester.widget(find.byType(BottomNavigationBar)); | ||
|
||
expect(bar.currentIndex, 0); | ||
|
||
await tester.tap(find.byIcon(Icons.lightbulb)); | ||
await tester.pumpAndSettle(); | ||
|
||
bar = tester.widget(find.byType(BottomNavigationBar)); | ||
expect(bar.currentIndex, 2); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.