Create error_message_test.dart

This commit is contained in:
Ashita Prasad
2023-04-19 03:47:35 +05:30
parent 8a48da4c53
commit f370e782f3

View File

@ -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));
});
}