-
Notifications
You must be signed in to change notification settings - Fork 1
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 #33 from omartoutounji/omartoutounji/restore-delet…
…ed-note-test-coverage #32: added restore deleted note test coverage
- Loading branch information
Showing
2 changed files
with
41 additions
and
50 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 |
---|---|---|
@@ -1,97 +1,92 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:hwyd/screens/journal_page.dart'; | ||
import 'package:share_plus/share_plus.dart'; | ||
|
||
void main() { | ||
testWidgets('Hwyd sanity test', (WidgetTester tester) async { | ||
// Isolate the JournalPage widget out of our app safely so we can test it as testWidget | ||
// Isolate the JournalPage widget out of our app safely so we can test | ||
// it as testWidget and set things up | ||
Widget testWidget = const MediaQuery( | ||
data: MediaQueryData(), child: MaterialApp(home: JournalPage())); | ||
|
||
// Rebuild the widget tree for our test widget | ||
await tester.pumpWidget(testWidget); | ||
|
||
// Ensure testWidget is visible | ||
await tester.ensureVisible(find.byWidget(testWidget)); | ||
|
||
// Ensure user can see the menu, share and add icons | ||
await tester.ensureVisible(find.byIcon(Icons.menu)); | ||
await tester.ensureVisible(find.byIcon(Icons.ios_share)); | ||
await tester.ensureVisible(find.byIcon(Icons.add)); | ||
|
||
// Search for our hint text and verify there is one widget | ||
// Enter journal: "my day was great!" | ||
expect(find.byType(TextField), findsOneWidget); | ||
|
||
// Enter a mock journal | ||
await tester.enterText(find.byType(TextField), 'my day was great!'); | ||
await tester.pumpAndSettle(); | ||
|
||
// Expect to find the new mock journal on screen | ||
// Ensure text is actually there | ||
expect(find.text('my day was great!'), findsOneWidget); | ||
|
||
// Press on menu icon to open drawer | ||
// Open drawer | ||
await tester.tap(find.byIcon(Icons.menu)); | ||
|
||
// Rebuild widget tree or wait for animation to complete | ||
await tester.pumpAndSettle(); | ||
|
||
// Expect the Drawer to be there in widget tree | ||
expect(find.byType(Drawer), findsOneWidget); | ||
|
||
// Ensure the Drawer is visible | ||
await tester.ensureVisible(find.byType(Drawer)); | ||
|
||
// Ensure there is one journal in the drawer only | ||
expect(find.byType(ListTile), findsOneWidget); | ||
|
||
// Tap on rename name button to rename journal | ||
// Rename journal to "journal1" | ||
await tester.tap(find.byIcon(Icons.drive_file_rename_outline)); | ||
|
||
// Rename journal to 'journal1'. We're using the first text field we find. | ||
await tester.enterText(find.byType(TextField).first, 'journal1'); | ||
|
||
// Expect to find renamed journal in Drawer | ||
expect(find.text('journal1'), findsOneWidget); | ||
|
||
// Press on menu icon to close drawer. Disable warning since we intend to tap off-screen share button | ||
// Close drawer | ||
await tester.tap(find.byIcon(Icons.ios_share), warnIfMissed: false); | ||
|
||
// Rebuild widget tree or wait for animation to complete | ||
await tester.pumpAndSettle(); | ||
|
||
// Expect the Drawer to be gone in widget tree | ||
expect(find.byType(Drawer), findsNothing); | ||
|
||
// Press on add button to create new jounrnal | ||
// Create new journal | ||
await tester.tap(find.byIcon(Icons.add)); | ||
|
||
// Rebuild widget tree or wait for animation to complete | ||
await tester.pumpAndSettle(); | ||
|
||
// Press on menu icon to open drawer | ||
// Open drawer | ||
await tester.tap(find.byIcon(Icons.menu)); | ||
|
||
// Rebuild widget tree or wait for animation to complete | ||
await tester.pumpAndSettle(); | ||
|
||
// Expect the Drawer to be there in widget tree | ||
expect(find.byType(Drawer), findsOneWidget); | ||
|
||
// Ensure the Drawer is visible | ||
await tester.ensureVisible(find.byType(Drawer)); | ||
|
||
// Ensure there are 2 journals journal in the drawer only | ||
// Ensure there are now 2 journals journal in the drawer only | ||
expect(find.byType(ListTile), findsNWidgets(2)); | ||
|
||
// Rebuild widget tree or wait for animation to complete | ||
await tester.pumpAndSettle(); | ||
|
||
// Dismiss 1 journal | ||
// Ensure snackbar is not visible | ||
expect(find.byType(SnackBarAction), findsNothing); | ||
|
||
// Delete first journal | ||
await tester.drag(find.byType(Dismissible).first, const Offset(500, 0)); | ||
await tester.pumpAndSettle(); | ||
expect(find.byType(ListTile), findsOneWidget); | ||
|
||
// Make sure snackbar now appears | ||
expect(find.byType(SnackBarAction), findsOneWidget); | ||
await tester.ensureVisible(find.byType(SnackBarAction)); | ||
|
||
// Build the widget until the dismiss animation ends. | ||
// Close drawer | ||
await tester.tap(find.byIcon(Icons.ios_share), warnIfMissed: false); | ||
await tester.pumpAndSettle(); | ||
expect(find.byType(Drawer), findsNothing); | ||
|
||
// Ensure that one journal is now deleted and there is only 1 left | ||
expect(find.byType(ListTile), findsOneWidget); | ||
// Undo delete journal | ||
await tester.tap(find.widgetWithText(SnackBarAction, "Undo"), | ||
warnIfMissed: false); | ||
await tester.pumpAndSettle(); | ||
|
||
// Open Drawer | ||
await tester.tap(find.byIcon(Icons.menu)); | ||
await tester.pumpAndSettle(); | ||
expect(find.byType(Drawer), findsOneWidget); | ||
await tester.ensureVisible(find.byType(Drawer)); | ||
|
||
// Check deleted journal is now restored | ||
expect(find.byType(ListTile), findsNWidgets(2)); | ||
}); | ||
} |