Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added configurable padding #133

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/src/golden_test_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ class FlutterGoldenTestAdapter extends GoldenTestAdapter {
maxHeight: constraints.maxHeight,
child: Center(
key: childKey,
child: widget,
child: Padding(
padding: goldenTestTheme.padding,
child: widget,
),
),
),
);
Expand Down
8 changes: 8 additions & 0 deletions lib/src/golden_test_theme.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:alchemist/src/golden_test_group.dart';
import 'package:alchemist/src/golden_test_scenario.dart';
import 'package:flutter/material.dart';

/// {@template golden_test_theme}
Expand All @@ -12,6 +13,7 @@ class GoldenTestTheme extends ThemeExtension<GoldenTestTheme> {
GoldenTestTheme({
required this.backgroundColor,
required this.borderColor,
this.padding = EdgeInsets.zero,
});

/// The standard theme for golden tests, used when no other theme is provided.
Expand All @@ -30,14 +32,19 @@ class GoldenTestTheme extends ThemeExtension<GoldenTestTheme> {
/// The border color used to separate scenarios in a [GoldenTestGroup].
final Color borderColor;

/// The padding that is used to wrap a [GoldenTestScenario]
final EdgeInsetsGeometry padding;

@override
ThemeExtension<GoldenTestTheme> copyWith({
Color? backgroundColor,
Color? borderColor,
EdgeInsetsGeometry? padding,
}) {
return GoldenTestTheme(
backgroundColor: backgroundColor ?? this.backgroundColor,
borderColor: borderColor ?? this.borderColor,
padding: padding ?? this.padding,
);
}

Expand All @@ -53,6 +60,7 @@ class GoldenTestTheme extends ThemeExtension<GoldenTestTheme> {
backgroundColor: Color.lerp(backgroundColor, other.backgroundColor, t) ??
backgroundColor,
borderColor: Color.lerp(borderColor, other.borderColor, t) ?? borderColor,
padding: padding,
);
}
}
50 changes: 50 additions & 0 deletions test/src/golden_test_adapter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:alchemist/src/blocked_text_image.dart';
import 'package:alchemist/src/golden_test_adapter.dart';
import 'package:alchemist/src/golden_test_group.dart';
import 'package:alchemist/src/golden_test_scenario.dart';
import 'package:alchemist/src/golden_test_theme.dart';
import 'package:alchemist/src/pumps.dart';
import 'package:alchemist/src/utilities.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -316,6 +317,55 @@ void main() {
expect(tester.platformDispatcher.textScaleFactor, 2.0);
});

group('padding', () {
testWidgets('default padding for `GoldenTestTheme`', (tester) async {
await adapter.pumpGoldenTest(
tester: tester,
textScaleFactor: 2,
constraints: const BoxConstraints(),
obscureFont: false,
globalConfigTheme: null,
variantConfigTheme: null,
goldenTestTheme: GoldenTestTheme.standard(),
pumpBeforeTest: onlyPumpAndSettle,
pumpWidget: onlyPumpWidget,
widget: buildGroup(),
);

final box = find.byType(Padding);

expect(
tester.widget<Padding>(box).padding,
EdgeInsets.zero,
);
});
testWidgets('custom padding on `GoldenTetTheme`', (tester) async {
await adapter.pumpGoldenTest(
tester: tester,
textScaleFactor: 2,
constraints: const BoxConstraints(),
obscureFont: false,
globalConfigTheme: null,
variantConfigTheme: null,
goldenTestTheme: GoldenTestTheme(
backgroundColor: Colors.white,
borderColor: Colors.black,
padding: const EdgeInsets.all(16),
),
pumpBeforeTest: onlyPumpAndSettle,
pumpWidget: onlyPumpWidget,
widget: buildGroup(),
);

final box = find.byType(Padding);

expect(
tester.widget<Padding>(box).padding,
const EdgeInsets.all(16),
);
});
});

testWidgets(
'renders FlutterGoldenTestWrapper with provided '
'obscure font, themes and child arguments',
Expand Down
Loading