-
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 #127 from ProximaEPFL/circular-value-error
Circular value error handling
- Loading branch information
Showing
5 changed files
with
165 additions
and
43 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import "package:flutter/material.dart"; | ||
|
||
/// A simple alert dialog that displays an error message. | ||
class ErrorAlert extends StatelessWidget { | ||
static const okButtonKey = Key("okButton"); | ||
|
||
/// Constructor for the [ErrorAlert] widget. | ||
/// [error] is the error object to display. | ||
const ErrorAlert({ | ||
super.key, | ||
required this.error, | ||
}); | ||
|
||
final Object error; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog( | ||
title: const Text("An error occurred"), | ||
content: Text(error.toString()), | ||
actions: <Widget>[ | ||
TextButton( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
key: okButtonKey, | ||
child: const Text("OK"), | ||
), | ||
], | ||
); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_test/flutter_test.dart"; | ||
import "package:hooks_riverpod/hooks_riverpod.dart"; | ||
import "package:proxima/utils/ui/circular_value.dart"; | ||
import "package:proxima/utils/ui/error_alert.dart"; | ||
|
||
void main() { | ||
Widget testCircularValue(AsyncValue<void> value) => CircularValue( | ||
value: value, | ||
builder: (context, data) => const Text("Completed"), | ||
fallbackBuilder: (context, error) => const Text("Strange Error"), | ||
); | ||
|
||
testWidgets( | ||
"CircularValue should show CircularProgressIndicator when loading", ( | ||
tester, | ||
) async { | ||
await tester.pumpWidget( | ||
ProviderScope( | ||
child: MaterialApp( | ||
home: testCircularValue(const AsyncValue.loading()), | ||
), | ||
), | ||
); | ||
|
||
expect(find.byType(CircularProgressIndicator), findsOneWidget); | ||
}); | ||
|
||
testWidgets("CicularValue should build with value when finished", ( | ||
tester, | ||
) async { | ||
await tester.pumpWidget( | ||
ProviderScope( | ||
child: MaterialApp( | ||
home: testCircularValue(const AsyncValue.data(null)), | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
expect(find.text("Completed"), findsOneWidget); | ||
}); | ||
|
||
testWidgets("CicularValue should build error when error", ( | ||
tester, | ||
) async { | ||
final testException = Exception("Blue moon"); | ||
|
||
await tester.pumpWidget( | ||
ProviderScope( | ||
child: MaterialApp( | ||
home: testCircularValue( | ||
AsyncValue.error(testException, StackTrace.empty), | ||
), | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
// expect to find a popup dialog | ||
expect(find.byType(AlertDialog), findsOneWidget); | ||
expect(find.textContaining("Blue moon"), findsOneWidget); | ||
// find ok button | ||
final okButton = find.byKey(ErrorAlert.okButtonKey); | ||
expect(okButton, findsOneWidget); | ||
await tester.tap(okButton); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text("Strange Error"), findsOneWidget); | ||
}); | ||
} |