Skip to content

Commit

Permalink
Add golden tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Jun 18, 2024
1 parent 06d503d commit c63cbca
Show file tree
Hide file tree
Showing 124 changed files with 398 additions and 118 deletions.
9 changes: 0 additions & 9 deletions forui/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ class _ExampleWidgetState extends State<ExampleWidget> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FTextField(
rawHelp: Text('Some error text'),
),
const SizedBox(height: 10),
FTextField(rawHelp: Text('Some error text', style: context.theme.textFieldStyle.enabled.footer,)),
const SizedBox(height: 10),
Text('Some error text', style: context.theme.textFieldStyle.enabled.footer,),
FTextField(help: 'Some error text', textAlign: TextAlign.start,),
const SizedBox(height: 10),
FButton(
design: FButtonVariant.destructive,
labelText: 'Delete?',
Expand Down
4 changes: 2 additions & 2 deletions forui/lib/src/widgets/badge/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ final class FBadgeStyle with Diagnosticable implements FBadgeDesign {
properties
..add(ColorProperty('background', background))
..add(ColorProperty('border', border))
..add(DiagnosticsProperty<BorderRadius>('borderRadius', borderRadius, defaultValue: BorderRadius.circular(100)))
..add(DiagnosticsProperty('borderRadius', borderRadius, defaultValue: BorderRadius.circular(100)))
..add(DoubleProperty('borderWidth', borderWidth))
..add(DiagnosticsProperty<FBadgeContentStyle>('content', content));
..add(DiagnosticsProperty('content', content));
}

@override
Expand Down
5 changes: 5 additions & 0 deletions forui/lib/src/widgets/button/button_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class FButtonIcon extends StatelessWidget {
colorFilter: ColorFilter.mode(enabled ? style.icon.enabled : style.icon.disabled, BlendMode.srcIn),
);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty('icon', icon));
}
}

/// [FButtonIcon]'s style.
Expand Down
Binary file not shown.
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.
Binary file not shown.
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.
Binary file not shown.
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.
Binary file not shown.
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.
Binary file not shown.
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.
Binary file not shown.
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.
Binary file not shown.
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.
Binary file not shown.
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.
Binary file removed forui/test/golden/card/zinc-dark-card-content.png
Diff not rendered.
Binary file removed forui/test/golden/card/zinc-light-card-content.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file modified forui/test/golden/header/zinc-dark-header.png
Diff not rendered.
Binary file modified forui/test/golden/header/zinc-light-header.png
Binary file modified forui/test/golden/text_field/default-zinc-dark-focused-no-text.png
Binary file modified forui/test/golden/text_field/default-zinc-dark-focused-text.png
Binary file modified forui/test/golden/text_field/email-zinc-dark-focused-text.png
Binary file modified forui/test/golden/text_field/email-zinc-dark-unfocused-text.png
Binary file modified forui/test/golden/text_field/email-zinc-light-focused-text.png
Binary file modified forui/test/golden/text_field/email-zinc-light-unfocused-text.png
Binary file modified forui/test/golden/text_field/error-zinc-dark-focused-no-text.png
Binary file modified forui/test/golden/text_field/error-zinc-dark-focused-text.png
Binary file modified forui/test/golden/text_field/error-zinc-dark-unfocused-no-text.png
Binary file modified forui/test/golden/text_field/error-zinc-dark-unfocused-text.png
Binary file modified forui/test/golden/text_field/error-zinc-light-focused-text.png
Binary file modified forui/test/golden/text_field/password-zinc-dark-focused-text.png
Binary file modified forui/test/golden/text_field/password-zinc-dark-unfocused-text.png
Binary file modified forui/test/golden/text_field/password-zinc-light-focused-text.png
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';
import '../test_scaffold.dart';
import '../../test_scaffold.dart';

void main() {
group('FCard', () {
for (final (name, theme, background) in TestScaffold.themes) {
testWidgets('$name with FCardContent', (tester) async {
testWidgets('$name with text FCardContent', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
Expand All @@ -30,7 +30,30 @@ void main() {

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('card/$name-card-content.png'),
matchesGoldenFile('card/$name-text-card-content.png'),
);
});

testWidgets('$name with raw FCardContent', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
background: background,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FCard(
rawTitle: const Text('Notifications'),
rawSubtitle: const Text('You have 3 unread messages.'),
),
],
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('card/$name-raw-card-content.png'),
);
});

Expand Down
59 changes: 59 additions & 0 deletions forui/test/src/widgets/card/card_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';

void main() {
group('FCard', () {
for (final (string, raw) in [
(null, null),
('', null),
(null, const SizedBox()),
]) {
testWidgets('constructor title does not throw error', (tester) async {
expect(
() => FCard(
title: string,
rawTitle: raw,
),
returnsNormally,
);
});

testWidgets('constructor subtitle does not throw error', (tester) async {
expect(
() => FCard(
subtitle: string,
rawSubtitle: raw,
),
returnsNormally,
);
});
}

for (final (string, raw) in [
('', const SizedBox()),
]) {
testWidgets('constructor title throws error', (tester) async {
expect(
() => FCard(
title: string,
rawTitle: raw,
),
throwsAssertionError,
);
});

testWidgets('constructor subtitle throws error', (tester) async {
expect(
() => FCard(
subtitle: string,
rawSubtitle: raw,
),
throwsAssertionError,
);
});
}
});
}
59 changes: 46 additions & 13 deletions forui/test/src/widgets/dialog/dialog_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,43 @@ import '../../test_scaffold.dart';

class UnderTest extends StatelessWidget {
final FDialogAlignment alignment;
final bool raw;

const UnderTest({required this.alignment, super.key});
const UnderTest({required this.alignment, required this.raw, super.key});

@override
Widget build(BuildContext context) => FDialog(
alignment: alignment,
title: 'Are you absolutely sure?',
body: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.',
actions: [
Widget build(BuildContext context) {
final actions = [
FButton(labelText: 'Continue', onPress: () {}),
FButton(design: FButtonVariant.outlined, labelText: 'Cancel', onPress: () {
Navigator.of(context).pop();
}),
],
);
];

if (raw) {
return FDialog(
alignment: alignment,
rawTitle: const Text('Are you absolutely sure?'),
rawBody: const Text('This action cannot be undone. This will permanently delete your account and remove your data from our servers.'),
actions: actions,
);

} else {
return FDialog(
alignment: alignment,
title: 'Are you absolutely sure?',
body: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.',
actions: actions,
);
}
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(EnumProperty<FDialogAlignment>('alignment', alignment));
properties
..add(EnumProperty('alignment', alignment))
..add(DiagnosticsProperty('raw', raw));
}
}

Expand All @@ -36,24 +53,40 @@ void main() {
group('FDialog', () {
for (final (name, theme, background) in TestScaffold.themes) {
for (final alignment in [FDialogAlignment.horizontal, FDialogAlignment.vertical]) {
testWidgets('$name with $alignment content', (tester) async {
testWidgets('$name with $alignment text FDialogContent', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestScaffold(
data: theme,
background: background,
child: UnderTest(alignment: alignment, raw: false),
),
),
);

await expectLater(
find.byType(UnderTest),
matchesGoldenFile('dialog/$name-$alignment-text-dialog-content.png'),
);
});

testWidgets('$name with $alignment raw FDialogContent', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: TestScaffold(
data: theme,
background: background,
child: UnderTest(alignment: alignment),
child: UnderTest(alignment: alignment, raw: true),
),
),
);

await expectLater(
find.byType(UnderTest),
matchesGoldenFile('dialog/$name-$alignment-content.png'),
matchesGoldenFile('dialog/$name-$alignment-raw-dialog-content.png'),
);
});
}


testWidgets('$name with raw content', (tester) async {
await tester.pumpWidget(
Expand Down
63 changes: 63 additions & 0 deletions forui/test/src/widgets/dialog/dialog_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';

void main() {
group('FDialog', () {
for (final (string, raw) in [
(null, null),
('', null),
(null, const SizedBox()),
]) {
testWidgets('constructor title does not throw error', (tester) async {
expect(
() => FDialog(
title: string,
rawTitle: raw,
actions: const [],
),
returnsNormally,
);
});

testWidgets('constructor body does not throw error', (tester) async {
expect(
() => FDialog(
body: string,
rawBody: raw,
actions: const [],
),
returnsNormally,
);
});
}

for (final (string, raw) in [
('', const SizedBox()),
]) {
testWidgets('constructor title throws error', (tester) async {
expect(
() => FDialog(
title: string,
rawTitle: raw,
actions: const [],
),
throwsAssertionError,
);
});

testWidgets('constructor body throws error', (tester) async {
expect(
() => FDialog(
body: string,
rawBody: raw,
actions: const [],
),
throwsAssertionError,
);
});
}
});
}
75 changes: 75 additions & 0 deletions forui/test/src/widgets/header/header_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@Tags(['golden'])
library;

import 'package:flutter/cupertino.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';
import '../../test_scaffold.dart';

const title = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';

void main() {
group('FHeader', () {
for (final (name, theme, _) in TestScaffold.themes) {
testWidgets('$name with FHeader actions', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FHeader(
title: title,
actions: [
FHeaderAction(
icon: FAssets.icons.alarmClock,
onPress: null,
),
FHeaderAction(
icon: FAssets.icons.plus,
onPress: () {},
),
],
),
)
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('header/$name-header.png'),
);
});

testWidgets('$name with raw title', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FHeader(
rawTitle: const Text('Title'),
actions: [
FHeaderAction(
icon: FAssets.icons.alarmClock,
onPress: null,
),
FHeaderAction(
icon: FAssets.icons.plus,
onPress: () {},
),
],
),
)
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('header/$name-raw-title.png'),
);
});
}
});
}
Loading

0 comments on commit c63cbca

Please sign in to comment.