diff --git a/lib/main.dart b/lib/main.dart index 1137dcd6..8e9a1f62 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,9 @@ import 'package:flutter/material.dart'; import 'menu.dart'; const appBarKey = Key('appbar'); +const textfieldKey = Key('textfield'); +const saveButtonKey = Key('save_button'); +const iconKey = Key('menu_icon_button'); // coverage:ignore-start void main() { @@ -32,7 +35,7 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - bool showMenu = false; + bool showMenu = true; final GlobalKey _scaffoldKey = GlobalKey(); @override @@ -58,6 +61,7 @@ class _HomePageState extends State { maintainState: true, visible: showMenu, child: IconButton( + key: iconKey, onPressed: () { _scaffoldKey.currentState!.openEndDrawer(); }, @@ -95,6 +99,7 @@ class _MyTextFieldState extends State { focus ? extendsFieldText() : minimizeFieldText(); }, child: TextField( + key: textfieldKey, decoration: const InputDecoration(hintText: 'Capture what is on your mind..!.', border: OutlineInputBorder()), expands: _expands, maxLines: _maxLines, @@ -107,6 +112,7 @@ class _MyTextFieldState extends State { Align( alignment: Alignment.bottomRight, child: ElevatedButton( + key: saveButtonKey, onPressed: () { minimizeFieldText(); }, diff --git a/lib/menu.dart b/lib/menu.dart index 4f7b2ff6..bcf8810a 100644 --- a/lib/menu.dart +++ b/lib/menu.dart @@ -55,39 +55,35 @@ class DrawerMenu extends StatelessWidget { margin: const EdgeInsets.only(top: 100), padding: const EdgeInsets.only(top: 15, bottom: 15), decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: Colors.white))), - child: ListTile( + child: const ListTile( key: tourTileKey, - leading: const Icon( + leading: Icon( Icons.flag_outlined, color: Colors.white, size: 40, ), - title: const Text('Feature Tour', + title: Text('Feature Tour', style: TextStyle( fontSize: 25, color: Colors.white, )), - onTap: () { - }, ), ), Container( padding: const EdgeInsets.only(top: 15, bottom: 15), decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: Colors.white))), - child: ListTile( + child: const ListTile( key: settingsTileKey, - leading: const Icon( + leading: Icon( Icons.settings, color: Colors.white, size: 40, ), - title: const Text('Settings', + title: Text('Settings', style: TextStyle( fontSize: 25, color: Colors.white, )), - onTap: () { - }, ), ), ])), diff --git a/test/menu_test.dart b/test/menu_test.dart new file mode 100644 index 00000000..8d5d2eae --- /dev/null +++ b/test/menu_test.dart @@ -0,0 +1,27 @@ +import 'package:app/menu.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:app/main.dart'; + +void main() { + testWidgets('Open drawer and close it', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Appbar is rendered + expect(find.byKey(appBarKey).hitTestable(), findsOneWidget); + expect(find.byKey(drawerMenuKey).hitTestable(), findsNothing); + + await tester.tap(find.byKey(iconKey)); + await tester.pumpAndSettle(); + + // Expect drawer menu to be shown + expect(find.byKey(drawerMenuKey).hitTestable(), findsOneWidget); + + await tester.tap(find.byKey(closeMenuKey)); + await tester.pumpAndSettle(); + + // Expect drawer menu to be closed + expect(find.byKey(drawerMenuKey).hitTestable(), findsNothing); + }); +} diff --git a/test/widget_test.dart b/test/widget_test.dart index 1013257d..f1d167cf 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -9,4 +9,24 @@ void main() { expect(find.byKey(appBarKey).hitTestable(), findsOneWidget); }); + + testWidgets('Expand textfield and tap save', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + expect(find.byKey(saveButtonKey).hitTestable(), findsNothing); + + // Tap on textfield + await tester.tap(find.byKey(textfieldKey)); + await tester.pumpAndSettle(); + + // Save button should be shown + expect(find.byKey(saveButtonKey).hitTestable(), findsOneWidget); + + // Tap on save button + await tester.tap(find.byKey(saveButtonKey)); + await tester.pumpAndSettle(); + + expect(find.byKey(saveButtonKey).hitTestable(), findsNothing); + }); }