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 14, 2024
1 parent feb60c5 commit 69fea32
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 17 deletions.
28 changes: 12 additions & 16 deletions forui/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class Application extends StatelessWidget {
data: FThemes.zinc.light,
child: Scaffold(
backgroundColor: FThemes.zinc.light.colorScheme.background,
body: Column(
body: const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const ExampleWidget(),
ExampleWidget(),
],
),
),
Expand Down Expand Up @@ -53,20 +53,16 @@ class _ExampleWidgetState extends State<ExampleWidget> {
text: 'Delete?',
onPress: () => showAdaptiveDialog(
context: context,
builder: (context) {
final style = context.theme.cardStyle;
return FDialog(
title: 'Are you absolutely sure?',
subtitle: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.',
actions: [
FButton(text: 'Continue', onPress: () {}),
FButton(design: FButtonVariant.outlined, text: 'Cancel', onPress: () {
Navigator.of(context).pop();
}),
],
);
// return _dialog(context);
},
builder: (context) => FDialog(
title: 'Are you absolutely sure?',
subtitle: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.',
actions: [
FButton(text: 'Continue', onPress: () {}),
FButton(design: FButtonVariant.outlined, text: 'Cancel', onPress: () {
Navigator.of(context).pop();
}),
],
),
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/widgets/dialog/dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/widgets.dart';
import 'package:forui/forui.dart';
import 'package:meta/meta.dart';
import 'package:sugar/collection.dart';
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.
83 changes: 83 additions & 0 deletions forui/test/src/widgets/dialog_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:forui/forui.dart';

import '../test_scaffold.dart';

class UnderTest extends StatelessWidget {
final FDialogAlignment alignment;

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

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

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


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 {
await tester.pumpWidget(
MaterialApp(
home: TestScaffold(
data: theme,
background: background,
child: UnderTest(alignment: alignment),
),
),
);

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


testWidgets('$name with raw content', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
background: background,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FDialog.raw(
builder: (context, style) => const SizedBox(
width: 50,
height: 50,
),
),
],
),
),
);

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

0 comments on commit 69fea32

Please sign in to comment.