diff --git a/test/feature_drawer_test.dart b/test/feature_drawer_test.dart index 71f7dff..776cf1d 100644 --- a/test/feature_drawer_test.dart +++ b/test/feature_drawer_test.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pessoa_bonito/ui/widget/text_reader.dart'; +import 'package:pessoa_bonito/ui/widget/text_selection_drawer.dart'; import 'utils.dart'; @@ -119,4 +120,191 @@ void main() { expect(tile.selected, equals(true)); }); + + group('Read and read filter', () { + testWidgets('Long pressing an unread text should mark it as read', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + var textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + var tile = tester.firstWidget( + find.ancestor(of: textFinder, matching: find.byType(ListTile))); + + expect(tile.textColor, equals(Colors.white)); + expect(tile.selectedColor, equals(Colors.white)); + expect(tile.selected, equals(false)); + expect(find.text('0/41'), findsOne); + + await tester.longPress(textFinder); + await tester.pumpAndSettle(); + + tile = tester.firstWidget( + find.ancestor(of: textFinder, matching: find.byType(ListTile))); + + expect(tile.textColor, equals(Colors.white60)); + expect(tile.selectedColor, equals(Colors.white60)); + expect(tile.selected, equals(false)); + expect(find.text('1/41'), findsOne); + }); + + testWidgets('Long pressing a read text should mark it as unread', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + final textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + var tile = tester.firstWidget( + find.ancestor(of: textFinder, matching: find.byType(ListTile))); + + expect(tile.textColor, equals(Colors.white)); + expect(tile.selectedColor, equals(Colors.white)); + expect(tile.selected, equals(false)); + expect(find.text('0/41'), findsOne); + + await tester.longPress(textFinder); + await tester.pumpAndSettle(); + + await tester.longPress(textFinder); + await tester.pumpAndSettle(); + + tile = tester.firstWidget( + find.ancestor(of: textFinder, matching: find.byType(ListTile))); + + expect(tile.textColor, equals(Colors.white)); + expect(tile.selectedColor, equals(Colors.white)); + expect(tile.selected, equals(false)); + expect(find.text('0/41'), findsOne); + }); + + testWidgets( + 'When filtering for unread texts, only the unread texts should appear', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + final textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.longPress(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(SearchReadFilter.all.icon)); + await tester.pumpAndSettle(); + + expect(textFinder, findsNothing); + }); + + testWidgets( + 'When filtering for read texts, only the the read text should appear', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + final textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.longPress(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(SearchReadFilter.all.icon)); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(SearchReadFilter.unread.icon)); + await tester.pumpAndSettle(); + + expect(textFinder, findsOne); + expect(find.byIcon(Icons.text_snippet_rounded), findsOne); + }); + + testWidgets('When filtering for all texts, all texts should appear', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + final textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.longPress(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(SearchReadFilter.all.icon)); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(SearchReadFilter.unread.icon)); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(SearchReadFilter.read.icon)); + await tester.pumpAndSettle(); + + expect(textFinder, findsOne); + }); + }); + + group('Text filter', () { + final exampleTextFinder = find.text('A DIVINA INVEJA'); + + testWidgets('When searching a term of an existing text and others, that text and others should appear', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Livro do Desassossego')); + await tester.pumpAndSettle(); + + await tester.enterText(find.byType(TextField), 'DiVina'); + await tester.pumpAndSettle(); + + expect(exampleTextFinder, findsOne); + expect(find.byIcon(Icons.text_snippet_rounded), findsAtLeast(2)); + expect(find.byIcon(Icons.subdirectory_arrow_right_rounded), findsExactly(3)); + }); + + testWidgets('When searching a term of one existing text only, only that text should appear', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Livro do Desassossego')); + await tester.pumpAndSettle(); + + await tester.enterText(find.byType(TextField), 'A DIVINA INVEJ'); + await tester.pumpAndSettle(); + + debugDumpApp(); + + expect(exampleTextFinder, findsOne); + expect(find.byIcon(Icons.text_snippet_rounded), findsOne); + expect(find.byIcon(Icons.subdirectory_arrow_right_rounded), findsExactly(3)); + }); + + testWidgets('When searching a term of a non-existing text, no text should appear', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Livro do Desassossego')); + await tester.pumpAndSettle(); + + await tester.enterText(find.byType(TextField), 'wak2jios9'); + await tester.pumpAndSettle(); + + expect(exampleTextFinder, findsNothing); + expect(find.byIcon(Icons.text_snippet_rounded), findsNothing); + expect(find.byIcon(Icons.subdirectory_arrow_right_rounded), findsExactly(3)); + }); + }); } diff --git a/test/feature_read_test.dart b/test/feature_read_test.dart deleted file mode 100644 index c8de0bf..0000000 --- a/test/feature_read_test.dart +++ /dev/null @@ -1,140 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:pessoa_bonito/ui/widget/text_selection_drawer.dart'; - -import 'utils.dart'; - -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - testWidgets('Long pressing an unread text should mark it as read', - (tester) async { - await startApp(tester); - await openDrawer(tester); - - await tester.tap(find.text('Rubaiyat')); - await tester.pumpAndSettle(); - - var textFinder = find.text('A vida é terra e o vivê-la é lodo.'); - var tile = tester.firstWidget( - find.ancestor(of: textFinder, matching: find.byType(ListTile))); - - expect(tile.textColor, equals(Colors.white)); - expect(tile.selectedColor, equals(Colors.white)); - expect(tile.selected, equals(false)); - expect(find.text('0/41'), findsOne); - - await tester.longPress(textFinder); - await tester.pumpAndSettle(); - - tile = tester.firstWidget( - find.ancestor(of: textFinder, matching: find.byType(ListTile))); - - expect(tile.textColor, equals(Colors.white60)); - expect(tile.selectedColor, equals(Colors.white60)); - expect(tile.selected, equals(false)); - expect(find.text('1/41'), findsOne); - }); - - testWidgets('Long pressing a read text should mark it as unread', - (tester) async { - await startApp(tester); - await openDrawer(tester); - - await tester.tap(find.text('Rubaiyat')); - await tester.pumpAndSettle(); - - final textFinder = find.text('A vida é terra e o vivê-la é lodo.'); - - var tile = tester.firstWidget( - find.ancestor(of: textFinder, matching: find.byType(ListTile))); - - expect(tile.textColor, equals(Colors.white)); - expect(tile.selectedColor, equals(Colors.white)); - expect(tile.selected, equals(false)); - expect(find.text('0/41'), findsOne); - - await tester.longPress(textFinder); - await tester.pumpAndSettle(); - - await tester.longPress(textFinder); - await tester.pumpAndSettle(); - - tile = tester.firstWidget( - find.ancestor(of: textFinder, matching: find.byType(ListTile))); - - expect(tile.textColor, equals(Colors.white)); - expect(tile.selectedColor, equals(Colors.white)); - expect(tile.selected, equals(false)); - expect(find.text('0/41'), findsOne); - }); - - testWidgets( - 'When filtering for unread texts, only the unread texts should appear', - (tester) async { - await startApp(tester); - await openDrawer(tester); - - await tester.tap(find.text('Rubaiyat')); - await tester.pumpAndSettle(); - - final textFinder = find.text('A vida é terra e o vivê-la é lodo.'); - - await tester.longPress(textFinder); - await tester.pumpAndSettle(); - - await tester.tap(find.byIcon(SearchReadFilter.all.icon)); - await tester.pumpAndSettle(); - - expect(textFinder, findsNothing); - }); - - testWidgets( - 'When filtering for read texts, only the the read text should appear', - (tester) async { - await startApp(tester); - await openDrawer(tester); - - await tester.tap(find.text('Rubaiyat')); - await tester.pumpAndSettle(); - - final textFinder = find.text('A vida é terra e o vivê-la é lodo.'); - - await tester.longPress(textFinder); - await tester.pumpAndSettle(); - - await tester.tap(find.byIcon(SearchReadFilter.all.icon)); - await tester.pumpAndSettle(); - - await tester.tap(find.byIcon(SearchReadFilter.unread.icon)); - await tester.pumpAndSettle(); - - expect(textFinder, findsOne); - expect(find.byIcon(Icons.text_snippet_rounded), findsOne); - }); - - testWidgets('When filtering for all texts, all texts should appear', - (tester) async { - await startApp(tester); - await openDrawer(tester); - - await tester.tap(find.text('Rubaiyat')); - await tester.pumpAndSettle(); - - final textFinder = find.text('A vida é terra e o vivê-la é lodo.'); - - await tester.longPress(textFinder); - await tester.pumpAndSettle(); - - await tester.tap(find.byIcon(SearchReadFilter.all.icon)); - await tester.pumpAndSettle(); - - await tester.tap(find.byIcon(SearchReadFilter.unread.icon)); - await tester.pumpAndSettle(); - - await tester.tap(find.byIcon(SearchReadFilter.read.icon)); - await tester.pumpAndSettle(); - - expect(textFinder, findsOne); - }); -} diff --git a/test/feature_saved_test.dart b/test/feature_saved_test.dart index 36d3728..b4172ef 100644 --- a/test/feature_saved_test.dart +++ b/test/feature_saved_test.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pessoa_bonito/ui/screen/saved_texts_screen.dart'; +import 'package:pessoa_bonito/ui/widget/text_reader.dart'; import 'utils.dart'; @@ -34,17 +36,50 @@ void main() { await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); await tester.pumpAndSettle(); + expect(find.byIcon(Icons.bookmark_outlined), findsOne); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + expect( + find.descendant( + of: find.widgetWithText(ExpansionTile, 'Rubaiyat'), + matching: textFinder), + findsOne); + }); + + testWidgets( + 'Saving a text of a subcategory should appear ' + 'in the saved texts screen with the root category', (tester) async { + await startApp(tester); await openDrawer(tester); + await tester.tap(find.text('Poemas de Alberto Caeiro')); + await tester.pumpAndSettle(); + await tester.tap(find.text('POEMAS INCONJUNTOS')); + await tester.pumpAndSettle(); + + var textFinder = find.text('A criança que pensa em fadas e acredita nas fadas'); + + await tester.tap(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + expect(find.byIcon(Icons.bookmark_outlined), findsOne); + await openDrawer(tester); + await tester.tap(find.byIcon(Icons.bookmarks)); await tester.pumpAndSettle(); expect( find.descendant( - of: find.widgetWithText(ExpansionTile, 'Rubaiyat'), - matching: find.text('A vida é terra e o vivê-la é lodo.')), + of: find.widgetWithText(ExpansionTile, 'Poemas de Alberto Caeiro'), + matching: textFinder), findsOne); }); @@ -65,16 +100,15 @@ void main() { await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); await tester.pumpAndSettle(); - await openDrawer(tester); - expect(find.byIcon(Icons.bookmark_outlined), findsOne); + await openDrawer(tester); + await tester.tap(find.byIcon(Icons.bookmarks)); await tester.pumpAndSettle(); - final tileFinder = find.ancestor( - of: find.text('A vida é terra e o vivê-la é lodo.'), - matching: find.byType(Slidable)); + final tileFinder = + find.ancestor(of: textFinder, matching: find.byType(Slidable)); await tester.drag(tileFinder, const Offset(-500.0, 0)); await tester.pumpAndSettle(); @@ -95,5 +129,357 @@ void main() { await tester.pumpAndSettle(); expect(find.byIcon(Icons.bookmark_outline_outlined), findsOne); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + expect(tileFinder, findsNothing); + }); + + testWidgets( + 'Clicking on a saved text should make the saved reader screen show with it', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + var textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.tap(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + await tester.tap(textFinder); + await tester.pumpAndSettle(); + + final reader = tester.widget(find.byType(TextReader)); + + expect(reader.author, equals('Fernando Pessoa')); + expect(reader.categoryTitle, equals('Rubaiyat')); + expect(reader.title, equals('A vida é terra e o vivê-la é lodo.')); + expect(reader.content, contains('Em tudo quanto faças sê só tu')); + + expect(textFinder, findsOne); + expect(find.textContaining('Em tudo quanto faças sê só tu'), findsOne); + }); + + testWidgets( + 'Undoing an unsave of a text should NOT remove it from the saved texts screen', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + var textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.tap(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + expect(find.byIcon(Icons.bookmark_outlined), findsOne); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + final tileFinder = + find.ancestor(of: textFinder, matching: find.byType(Slidable)); + + await tester.drag(tileFinder, const Offset(-500.0, 0)); + await tester.pumpAndSettle(); + + expect(find.byIcon(Icons.delete), findsOne); + await tester.tap(find.byIcon(Icons.delete)); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Cancelar')); + await tester.pumpAndSettle(); + + expect(textFinder, findsOne); + + await tester.pageBack(); + await tester.pumpAndSettle(); + + await tester.tap(find + .byWidgetPredicate((widget) => widget is ListTile && widget.selected)); + await tester.pumpAndSettle(); + + expect(find.byIcon(Icons.bookmark_outlined), findsOne); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + expect(tileFinder, findsOne); + }); + + testWidgets( + 'Saving two texts of the same category should appear in the same group of the saved texts screen', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + var firstTextFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.tap(firstTextFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + await openDrawer(tester); + + var secondTextFinder = find.text('Ao gozo segue a dor, e o gozo a esta.'); + + await tester.tap(secondTextFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + expect( + find.descendant( + of: find.byType(SavedTextsScreen), + matching: find.byType(ExpansionTile)), + findsOne); + expect(find.widgetWithText(ExpansionTile, 'Rubaiyat'), findsOne); + expect( + find.descendant( + of: find.widgetWithText(ExpansionTile, 'Rubaiyat'), + matching: firstTextFinder), + findsOne); + expect( + find.descendant( + of: find.widgetWithText(ExpansionTile, 'Rubaiyat'), + matching: secondTextFinder), + findsOne); + }); + + testWidgets( + 'Saving two texts of the different categories should appear in different groups of the saved texts screen', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + var firstTextFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.tap(firstTextFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + await openDrawer(tester); + + await tester.tap(find.text('Voltar')); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Livro do Desassossego')); + await tester.pumpAndSettle(); + + var secondTextFinder = + find.text('Vivo sempre no presente. O futuro, não o conheço.'); + + await tester.scrollUntilVisible(secondTextFinder, 300.0, + scrollable: findScrollableTile( + find.byKey(const PageStorageKey("drawer-list-view"))), + maxScrolls: 500); + + await tester.tap(secondTextFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + expect( + find.descendant( + of: find.byType(SavedTextsScreen), + matching: find.byType(ExpansionTile)), + findsNWidgets(2)); + expect(find.widgetWithText(ExpansionTile, 'Rubaiyat'), findsOne); + expect( + find.descendant( + of: find.widgetWithText(ExpansionTile, 'Rubaiyat'), + matching: firstTextFinder), + findsOne); + + expect( + find.widgetWithText(ExpansionTile, 'Livro do Desassossego'), findsOne); + expect( + find.descendant( + of: find.widgetWithText(ExpansionTile, 'Livro do Desassossego'), + matching: secondTextFinder), + findsOne); + }); + + group('Expansion status', () { + testWidgets( + 'When a text is saved with no other texts, it should be expanded', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + var textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.tap(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + expect( + find.widgetWithIcon( + ExpansionTile, Icons.arrow_drop_down_circle_outlined), + findsOne); + expect( + find.widgetWithIcon( + SliverAppBar, Icons.arrow_drop_down_circle_outlined), + findsOne); + }); + + testWidgets( + 'When a text is expanded and its expansion button is pressed, it should become collapsed', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + var textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.tap(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + await tester.tap(find.descendant( + of: find.byType(ExpansionTile), + matching: find.byIcon(Icons.arrow_drop_down_circle_outlined))); + await tester.pumpAndSettle(); + + expect( + find.widgetWithIcon( + ExpansionTile, Icons.arrow_drop_down_circle_rounded), + findsOne); + expect(textFinder, findsNothing); + + await tester.pageBack(); + await openDrawer(tester); + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + expect( + find.widgetWithIcon( + ExpansionTile, Icons.arrow_drop_down_circle_rounded), + findsOne); + expect(textFinder, findsNothing); + expect( + find.descendant( + of: find.byType(SliverAppBar), + matching: find.byIcon(Icons.arrow_drop_down_circle_outlined)), + findsOne); + }); + + testWidgets( + 'When a text is collapsed and its expansion button is pressed, it should become expanded', + (tester) async { + await startApp(tester); + await openDrawer(tester); + + await tester.tap(find.text('Rubaiyat')); + await tester.pumpAndSettle(); + + var textFinder = find.text('A vida é terra e o vivê-la é lodo.'); + + await tester.tap(textFinder); + await tester.pumpAndSettle(); + + await tester.tap(find.byIcon(Icons.bookmark_outline_outlined)); + await tester.pumpAndSettle(); + + await openDrawer(tester); + + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + await tester.tap(find.descendant( + of: find.byType(ExpansionTile), + matching: find.byIcon(Icons.arrow_drop_down_circle_outlined))); + await tester.pumpAndSettle(); + + await tester.tap(find.descendant( + of: find.byType(ExpansionTile), + matching: find.byIcon(Icons.arrow_drop_down_circle_rounded))); + await tester.pumpAndSettle(); + + expect( + find.widgetWithIcon( + ExpansionTile, Icons.arrow_drop_down_circle_outlined), + findsOne); + expect(textFinder, findsOne); + + await tester.pageBack(); + await openDrawer(tester); + await tester.tap(find.byIcon(Icons.bookmarks)); + await tester.pumpAndSettle(); + + expect( + find.widgetWithIcon( + ExpansionTile, Icons.arrow_drop_down_circle_outlined), + findsOne); + expect(textFinder, findsOne); + expect( + find.widgetWithIcon( + SliverAppBar, Icons.arrow_drop_down_circle_outlined), + findsOne); + }); }); }