Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #29

Merged
merged 7 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions test/feature_drawer_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<ListTile>(
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<ListTile>(
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<ListTile>(
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<ListTile>(
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));
});
});
}
140 changes: 0 additions & 140 deletions test/feature_read_test.dart

This file was deleted.

Loading
Loading