Skip to content

Commit

Permalink
feat: Adding tests. #305
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Feb 21, 2023
1 parent 11137a6 commit 0c0ca49
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
8 changes: 7 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -32,7 +35,7 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
bool showMenu = false;
bool showMenu = true;
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();

@override
Expand All @@ -58,6 +61,7 @@ class _HomePageState extends State<HomePage> {
maintainState: true,
visible: showMenu,
child: IconButton(
key: iconKey,
onPressed: () {
_scaffoldKey.currentState!.openEndDrawer();
},
Expand Down Expand Up @@ -95,6 +99,7 @@ class _MyTextFieldState extends State<MyTextField> {
focus ? extendsFieldText() : minimizeFieldText();
},
child: TextField(
key: textfieldKey,
decoration: const InputDecoration(hintText: 'Capture what is on your mind..!.', border: OutlineInputBorder()),
expands: _expands,
maxLines: _maxLines,
Expand All @@ -107,6 +112,7 @@ class _MyTextFieldState extends State<MyTextField> {
Align(
alignment: Alignment.bottomRight,
child: ElevatedButton(
key: saveButtonKey,
onPressed: () {
minimizeFieldText();
},
Expand Down
16 changes: 6 additions & 10 deletions lib/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: () {
},
),
),
])),
Expand Down
27 changes: 27 additions & 0 deletions test/menu_test.dart
Original file line number Diff line number Diff line change
@@ -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);
});
}
20 changes: 20 additions & 0 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

0 comments on commit 0c0ca49

Please sign in to comment.