Skip to content

Commit

Permalink
Merge pull request #11 from yako-dev/tests/widget-tests
Browse files Browse the repository at this point in the history
Add widget tests for status alert widgets
  • Loading branch information
yadaniyil committed Oct 17, 2022
2 parents dcf8e3e + a090a3e commit e1106f2
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -364,7 +364,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -413,7 +413,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
</dict>
</plist>
122 changes: 122 additions & 0 deletions test/widget_tests.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:status_alert/src/widgets/status_alert_base_widget.dart';
import 'package:status_alert/src/utils/status_allert_manager.dart';
import 'package:status_alert/status_alert.dart';

void main() {
group('Status Alert Test', () {
final statusAlert = StatusAlertBaseWidget(
duration: Duration(minutes: 1),
title: 'Subscribed',
margin: const EdgeInsets.all(40.0),
padding: EdgeInsets.zero,
subtitle: 'test',
alignment: Alignment.center,
blurPower: 15,
maxWidth: 260,
titleOptions: StatusAlertTextConfiguration(
style: TextStyle(
color: Colors.red,
fontSize: 23,
fontWeight: FontWeight.w600,
),
),
subtitleOptions: StatusAlertTextConfiguration(
style: TextStyle(
color: Colors.orange,
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
borderRadius: const BorderRadius.all(Radius.circular(10.0)),
onHide: StatusAlertManager.dismiss,
configuration: IconConfiguration(
icon: Icons.favorite_border,
color: Colors.blue,
),
backgroundColor: Colors.green,
);

testWidgets('Widget should render correctly', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));

expect(find.byType(StatusAlertBaseWidget), findsOneWidget);
});
});

testWidgets('Title content should match', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));

expect(find.text('Subscribed'), findsOneWidget);
});
});

testWidgets('Title style should match', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));

final titleWidget = tester.widget<Text>(find.text('Subscribed'));

expect(titleWidget.style?.color, Colors.red);
expect(titleWidget.style?.fontSize, 23);
expect(titleWidget.style?.fontWeight, FontWeight.w600);
});
});

testWidgets('SubTitle content should match', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));

expect(find.text('test'), findsOneWidget);
});
});

testWidgets('SubTitle style should match', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));

final titleWidget = tester.widget<Text>(find.text('test'));

expect(titleWidget.style?.color, Colors.orange);
expect(titleWidget.style?.fontSize, 16);
expect(titleWidget.style?.fontWeight, FontWeight.w400);
});
});

testWidgets('Widget color should match', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));

final statusAlertWidget = tester
.widget<StatusAlertBaseWidget>(find.byType(StatusAlertBaseWidget));

expect(statusAlertWidget.backgroundColor, Colors.green);
});
});

testWidgets('Icon content should match', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));

expect(find.byIcon(Icons.favorite_border), findsOneWidget);
});
});

testWidgets('Icon colour should match', (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(_wrapWithMaterialApp(statusAlert));
final iconWidget =
tester.widget<Icon>(find.byIcon(Icons.favorite_border));

expect(iconWidget.color, Colors.blue);
});
});
});
}

Widget _wrapWithMaterialApp(Widget testWidget) {
return MaterialApp(home: testWidget);
}

0 comments on commit e1106f2

Please sign in to comment.