mirror of
https://github.com/foss42/apidash.git
synced 2025-05-22 00:36:43 +08:00
Create error_message_test.dart
This commit is contained in:
58
test/widgets/error_message_test.dart
Normal file
58
test/widgets/error_message_test.dart
Normal 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));
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user