fix: updated tests

This commit is contained in:
DenserMeerkat
2024-07-04 16:11:01 +05:30
parent 8ee7bc843b
commit 3f17840361
2 changed files with 79 additions and 22 deletions

View File

@ -19,11 +19,26 @@ void main() {
),
);
expect(find.byIcon(Icons.content_copy), findsOneWidget);
expect(find.text(kLabelCopy), findsOneWidget);
final textButton1 = find.byType(TextButton);
expect(textButton1, findsOneWidget);
await tester.tap(textButton1);
final icon = find.byIcon(Icons.content_copy);
expect(icon, findsOneWidget);
Finder button;
if (tester.any(find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
expect(find.text(kLabelCopy), findsOneWidget);
button = find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton));
} else if (tester
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
button = find.byType(IconButton);
} else {
fail('No TextButton or IconButton found');
}
expect(button, findsOneWidget);
await tester.tap(button);
//TODO: The below test works for `flutter run` but not for `flutter test`
//var data = await Clipboard.getData('text/plain');
@ -91,13 +106,27 @@ void main() {
),
);
expect(find.byIcon(Icons.download), findsOneWidget);
expect(find.text("Download"), findsOneWidget);
final icon = find.byIcon(Icons.download);
expect(icon, findsOneWidget);
final button1 = find.byType(TextButton);
expect(button1, findsOneWidget);
expect(tester.widget<TextButton>(button1).enabled, isFalse);
Finder button;
if (tester.any(find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
expect(find.text(kLabelDownload), findsOneWidget);
button = find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton));
expect(button, findsOneWidget);
expect(tester.widget<TextButton>(button).enabled, isFalse);
} else if (tester
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
button = find.byType(IconButton);
expect(button, findsOneWidget);
expect(tester.widget<IconButton>(button).onPressed == null, isFalse);
} else {
fail('No TextButton or IconButton found');
}
});
testWidgets('Testing for Save in Downloads button 2', (tester) async {
@ -113,13 +142,27 @@ void main() {
),
);
expect(find.byIcon(Icons.download), findsOneWidget);
expect(find.text("Download"), findsOneWidget);
final icon = find.byIcon(Icons.download);
expect(icon, findsOneWidget);
final button1 = find.byType(TextButton);
expect(button1, findsOneWidget);
expect(tester.widget<TextButton>(button1).enabled, isTrue);
Finder button;
if (tester.any(find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
expect(find.text(kLabelDownload), findsOneWidget);
button = find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton));
expect(button, findsOneWidget);
expect(tester.widget<TextButton>(button).enabled, isTrue);
} else if (tester
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
button = find.byType(IconButton);
expect(button, findsOneWidget);
expect(tester.widget<IconButton>(button).onPressed == null, isTrue);
} else {
fail('No TextButton or IconButton found');
}
});
testWidgets('Testing for Repo button', (tester) async {

View File

@ -122,12 +122,26 @@ void main() {
expect(find.text('xyz (2 items)'), findsOneWidget);
expect(find.byIcon(Icons.content_copy), findsOneWidget);
expect(find.text(kLabelCopy), findsOneWidget);
final icon = find.byIcon(Icons.content_copy);
expect(icon, findsOneWidget);
final textButton1 = find.byType(TextButton);
expect(textButton1, findsOneWidget);
await tester.tap(textButton1);
Finder button;
if (tester.any(find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
expect(find.text(kLabelCopy), findsOneWidget);
button = find.ancestor(
of: icon,
matching: find.byWidgetPredicate((widget) => widget is TextButton));
} else if (tester
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
button = find.byType(IconButton);
} else {
fail('No TextButton or IconButton found');
}
expect(button, findsOneWidget);
await tester.tap(button);
});
testWidgets('Testing Response Headers', (tester) async {