Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaijoe committed Aug 16, 2024
1 parent 5dd0b57 commit 7e84c44
Show file tree
Hide file tree
Showing 88 changed files with 138 additions and 15 deletions.
4 changes: 2 additions & 2 deletions forui/example/lib/sandbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class _SandboxState extends State<Sandbox> {
FCheckbox(
label: Text('Remember me'),
description: Text('Remember me on this device.'),
// forceErrorText: 'Please check the box to continue.',
// initialValue: true,
forceErrorText: 'Please check the box to continue.',
initialValue: true,
enabled: false,
),
SizedBox(height: 20),
Expand Down
6 changes: 3 additions & 3 deletions forui/lib/src/widgets/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FCheckbox extends FStatelessFormField<bool> {
super.forceErrorText,
super.validator,
super.initialValue = false,
super.enabled = false,
super.enabled = true,
super.autovalidateMode,
super.restorationId,
super.key,
Expand Down Expand Up @@ -117,8 +117,8 @@ class FCheckbox extends FStatelessFormField<bool> {
),
child: value
? FAssets.icons.check(
height: 15,
width: 15,
height: 14,
width: 14,
colorFilter: ColorFilter.mode(
stateStyle.iconColor,
BlendMode.srcIn,
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 63 additions & 10 deletions forui/test/src/widgets/checkbox_golden_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@Tags(['golden'])
library;

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';
Expand All @@ -9,29 +10,81 @@ import '../test_scaffold.dart';
void main() {
group('FCheckBox', () {
for (final (name, theme, background) in TestScaffold.themes) {
for (final (enabled, initialValue) in [
(true, true),
(true, false),
(false, true),
(true, true),
for (final (enabled, initialValue, error) in [
(true, true, false),
(true, true, true),
(true, false, false),
(true, false, true),
(false, true, false),
(false, true, true),
(false, false, false),
(false, false, true),
]) {
testWidgets('$name with ${enabled ? 'enabled' : 'disabled'} & ${initialValue ? 'value' : 'no-value'}',
testWidgets(
'$name with ${enabled ? 'enabled' : 'disabled'}, ${initialValue.toString() + ' value'} & ${error ? 'with error' : 'without error'}',
(tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
background: background,
child: FCheckbox(
enabled: enabled,
initialValue: initialValue,
child: error
? FCheckbox(
enabled: enabled,
initialValue: initialValue,
forceErrorText: '',
)
: FCheckbox(
enabled: enabled,
initialValue: initialValue,
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile(
'check-box/$name-${enabled ? 'enabled' : 'disabled'}-${initialValue}${error ? '-error' : ''}.png',
),
);
});
}
}

for (final (name, theme, background) in TestScaffold.themes) {
for (final (enabled, initialValue, error) in [
(true, true, false),
(true, true, true),
(true, false, false),
(true, false, true),
(false, true, false),
(false, true, true),
(false, false, false),
(false, false, true),
]) {
testWidgets(
'$name with label, ${enabled ? 'enabled' : 'disabled'}, ${initialValue.toString() + ' value'} & ${error ? 'with error' : 'without error'}',
(tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
background: background,
child: SizedBox(
width: 300,
child: FCheckbox(
label: const Text('Terms and Conditions'),
description: const Text('I agree to the terms and conditions.'),
enabled: enabled,
initialValue: initialValue,
forceErrorText: error ? 'Please check the agree to continue.' : null,
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile(
'check-box/$name-${enabled ? 'enabled' : 'disabled'}-${initialValue ? 'value' : 'no-value'}.png',
'check-box/$name-label-${enabled ? 'enabled' : 'disabled'}-${initialValue}${error ? '-error' : ''}.png',
),
);
});
Expand Down
70 changes: 70 additions & 0 deletions forui/test/src/widgets/label_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@Tags(['golden'])
library;

import 'package:flutter/material.dart';

import 'package:flutter_test/flutter_test.dart';

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

void main() {
group('FLabel', () {
for (final (name, theme, _) in TestScaffold.themes) {
for (final state in FLabelState.values) {
testWidgets('$name horizontal with ${state}', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: SizedBox(
width: 300,
child: FLabel(
axis: Axis.horizontal,
label: Text('Email'),
description: Text('Enter your email address.'),
error: Text('Please enter a valid email address.'),
state: state,
child: DecoratedBox(
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(5)), color: Colors.grey),
child: SizedBox(width: 16, height: 16),
),
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('label/$name-horizontal-${state}.png'),
);
});
}

for (final state in FLabelState.values) {
testWidgets('$name vertical with ${state}', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: FLabel(
axis: Axis.vertical,
label: Text('Email'),
description: Text('Enter your email address.'),
error: Text('Please enter a valid email address.'),
state: state,
child: DecoratedBox(
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(5)), color: Colors.grey),
child: SizedBox(width: 200, height: 30),
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('label/$name-vertical-${state}.png'),
);
});
}
}
});
}

0 comments on commit 7e84c44

Please sign in to comment.