Skip to content

Commit

Permalink
Golden tests implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Daviiddoo committed Jul 16, 2024
1 parent ecb8414 commit e4e49a0
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 8 deletions.
17 changes: 9 additions & 8 deletions forui/lib/src/widgets/alert/alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ part 'alert_styles.dart';
/// * https://forui.dev/docs/alert for working examples.
/// * [FAlertStyle] for customizing an alert's appearance.
class FAlert extends StatelessWidget {
/// The icon.
final Widget? icon;
/// The icon. Defaults to [FAssets.icons.circleAlert].
final SvgAsset? icon;

/// The title.
final Widget? title;
Expand Down Expand Up @@ -52,20 +52,21 @@ class FAlert extends StatelessWidget {
Variant.primary => context.theme.alertStyles.primary,
Variant.destructive => context.theme.alertStyles.destructive,
};
final icon = this.icon ??
FAssets.icons.circleAlert(
height: style.iconSize,
colorFilter: ColorFilter.mode(style.iconColor, BlendMode.srcIn),
);
final icon = this.icon ?? FAssets.icons.circleAlert;

return DecoratedBox(
decoration: style.decoration,
child: Padding(
padding: style.padding,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
icon,
icon(
height: style.iconSize,
colorFilter: ColorFilter.mode(style.iconColor, BlendMode.srcIn),
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 8),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions forui/test/src/widgets/alert_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@Tags(['golden'])
library;

import 'package:flutter/material.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';
import 'package:forui/src/widgets/alert/alert.dart';
import '../test_scaffold.dart';

void main() {
group('FAlert', () {
for (final (name, theme, _) in TestScaffold.themes) {
for (final variant in Variant.values) {
testWidgets('$name with default icon', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FAlert(
title: const Text('Alert Title'),
subtitle: const Text('Alert description with extra text'),
style: variant,
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('alert/$name-$variant-with-default-icon.png'),
);
});

testWidgets('$name without user icon', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FAlert(
icon: FAssets.icons.badgeAlert,
title: const Text('Alert Title'),
subtitle: const Text('Alert description with extra text'),
style: variant,
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('alert/$name-$variant-without-user-icon.png'),
);
});
}
}
});
}

0 comments on commit e4e49a0

Please sign in to comment.