diff --git a/test/widgets/error_message_test.dart b/test/widgets/error_message_test.dart new file mode 100644 index 00000000..b85b1355 --- /dev/null +++ b/test/widgets/error_message_test.dart @@ -0,0 +1,58 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:apidash/widgets/error_message.dart'; +import 'package:apidash/consts.dart'; + +void main() { + String errorMessage = + 'This is an error message generated by the application '; + testWidgets('Testing when Error Message is sent', (tester) async { + await tester.pumpWidget( + MaterialApp( + title: 'Error Message', + home: Scaffold( + body: ErrorMessage(message: errorMessage), + ), + ), + ); + + expect(find.byIcon(Icons.warning_rounded), findsOneWidget); + expect(find.byType(Center), findsNWidgets(3)); + expect(find.byIcon(Icons.arrow_outward_rounded), findsOneWidget); + expect(find.byType(SelectableText), findsOneWidget); + expect(find.text(errorMessage), findsOneWidget); + expect(find.text('Raise Issue'), findsOneWidget); + expect( + find.text('An error occurred. $kUnexpectedRaiseIssue'), findsNothing); + final dynamic filledButtonWithIconWidget = tester.widget( + find.byWidgetPredicate((Widget widget) => + '${widget.runtimeType}' == '_FilledButtonWithIcon')); + expect(find.byType(filledButtonWithIconWidget.runtimeType), findsOneWidget); + await tester.tap(find.byType(filledButtonWithIconWidget.runtimeType)); + }); + + testWidgets('Testing when no error message is sent', (tester) async { + await tester.pumpWidget( + const MaterialApp( + title: 'Error Message', + home: Scaffold( + body: ErrorMessage(message: null), + ), + ), + ); + + expect(find.byIcon(Icons.warning_rounded), findsOneWidget); + expect(find.byType(Center), findsNWidgets(3)); + expect(find.byIcon(Icons.arrow_outward_rounded), findsOneWidget); + expect(find.byType(SelectableText), findsOneWidget); + expect(find.text('Raise Issue'), findsOneWidget); + expect(find.text(errorMessage), findsNothing); + expect( + find.text('An error occurred. $kUnexpectedRaiseIssue'), findsOneWidget); + final dynamic filledButtonWithIconWidget = tester.widget( + find.byWidgetPredicate((Widget widget) => + '${widget.runtimeType}' == '_FilledButtonWithIcon')); + expect(find.byType(filledButtonWithIconWidget.runtimeType), findsOneWidget); + await tester.tap(find.byType(filledButtonWithIconWidget.runtimeType)); + }); +}