Skip to content

Instantly share code, notes, and snippets.

@Benson194
Created August 27, 2021 03:53
Show Gist options
  • Save Benson194/5382b4aaff5f5c2369ba0c4ad0faf97c to your computer and use it in GitHub Desktop.
Save Benson194/5382b4aaff5f5c2369ba0c4ad0faf97c to your computer and use it in GitHub Desktop.
Flutter Integration Test
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
setUp(() async {
await Repository().openDB();
});
tearDown(() async {
await Repository().closeDB();
});
testWidgets('Test insert data', (WidgetTester tester) async {
await tester.pumpWidget(MultiBlocProvider(
providers: [
BlocProvider(
create: (BuildContext context) {
return CreateBloc(Repository());
},
),
BlocProvider(
create: (BuildContext context) {
return HomeBloc(Repository());
},
),
],
child: MaterialApp(
title: appName,
theme: ThemeData(primaryColor: kPrimaryColor),
debugShowCheckedModeBanner: false,
home: const HomeScreen(),
routes: routes,
initialRoute: '/'),
));
// ensure the loading dialog will be dismissed
// by waiting until code in GetNoteSuccess state is executed
await tester.pumpAndSettle();
// here we delay for 1 second so that we can
// see the home screen doesn't have any note
await Future.delayed(const Duration(seconds: 1), () {});
expect(find.byKey(const Key("Empty note list")), findsOneWidget);
// tap create button to go to create screen
await tester.tap(find.byType(FloatingActionButton));
await tester.pumpAndSettle();
// tap on note title field
await tester.enterText(find.byKey(const Key("Note Title")), 'Hello!');
// tap on Start date time DateTimePicker
await tester.dragUntilVisible(
find.byKey(const Key("Start Date time picker")),
find.byKey(const Key("Create note scrollview")),
const Offset(0, -200),
);
await tester.tap(find.byKey(const Key("Start Date time picker")));
await tester.pumpAndSettle();
await tester.tap(find.text('10'));
await tester.pumpAndSettle();
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();
// tap on End date time DateTimePicker
await tester.dragUntilVisible(
find.byKey(const Key("End Date time picker")),
find.byKey(const Key("Create note scrollview")),
const Offset(0, -200),
);
await tester.tap(find.byKey(const Key("End Date time picker")));
await tester.pumpAndSettle();
await tester.tap(find.text('13'));
await tester.pumpAndSettle();
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();
// tap on submit button
await tester.tap(find.byKey(const Key("Submit button")));
await tester.pumpAndSettle();
// here we delay for 1 second so that we can
// see the new note appears in home screen
await Future.delayed(const Duration(seconds: 1), () {});
expect(find.byKey(const Key("Empty note list")), findsNothing);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment