diff --git a/lib/src/alchemist_config.dart b/lib/src/alchemist_config.dart index b2c6a03..41eccf7 100644 --- a/lib/src/alchemist_config.dart +++ b/lib/src/alchemist_config.dart @@ -65,15 +65,17 @@ class AlchemistConfig extends Equatable { /// {@macro alchemist_config} const AlchemistConfig({ bool? forceUpdateGoldenFiles, + bool? renderName, GoldenTestTheme? goldenTestTheme, ThemeData? theme, PlatformGoldensConfig? platformGoldensConfig, CiGoldensConfig? ciGoldensConfig, - }) : _forceUpdateGoldenFiles = forceUpdateGoldenFiles, - _theme = theme, - _goldenTestTheme = goldenTestTheme, - _platformGoldensConfig = platformGoldensConfig, - _ciGoldensConfig = ciGoldensConfig; + }) : _forceUpdateGoldenFiles = forceUpdateGoldenFiles, + _renderName = renderName, + _theme = theme, + _goldenTestTheme = goldenTestTheme, + _platformGoldensConfig = platformGoldensConfig, + _ciGoldensConfig = ciGoldensConfig; /// The instance of the [AlchemistConfig] in the current zone used by the /// `alchemist` package. @@ -170,6 +172,13 @@ class AlchemistConfig extends Equatable { bool get forceUpdateGoldenFiles => _forceUpdateGoldenFiles ?? false; final bool? _forceUpdateGoldenFiles; + /// Whether to render the name of the test scenario on top of the image. + /// + /// If set to `false`, the name will not be rendered. This can be useful when + /// Alchemist is used to create screenshots for a store page. + bool get renderName => _renderName ?? true; + final bool? _renderName; + /// The [ThemeData] to use when generating golden tests. /// /// If no [ThemeData] is provided, the default [ThemeData.light] will be used. diff --git a/lib/src/golden_test_scenario.dart b/lib/src/golden_test_scenario.dart index e14484a..74c45f1 100644 --- a/lib/src/golden_test_scenario.dart +++ b/lib/src/golden_test_scenario.dart @@ -68,6 +68,7 @@ class GoldenTestScenario extends StatelessWidget { @override Widget build(BuildContext context) { + final config = AlchemistConfig.current(); final testTheme = Theme.of(context).extension() ?? AlchemistConfig.current().goldenTestTheme ?? @@ -78,14 +79,16 @@ class GoldenTestScenario extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - Text( - name, - style: testTheme.nameTextStyle, - textHeightBehavior: const TextHeightBehavior( - applyHeightToFirstAscent: false, + if (config.renderName) ...[ + Text( + name, + style: testTheme.nameTextStyle, + textHeightBehavior: const TextHeightBehavior( + applyHeightToFirstAscent: false, + ), ), - ), - const SizedBox(height: 8), + const SizedBox(height: 8) + ], ConstrainedBox( constraints: constraints ?? diff --git a/test/src/golden_test_scenario_test.dart b/test/src/golden_test_scenario_test.dart index ce0651f..35d70ed 100644 --- a/test/src/golden_test_scenario_test.dart +++ b/test/src/golden_test_scenario_test.dart @@ -1,4 +1,4 @@ -import 'package:alchemist/src/golden_test_scenario.dart'; +import 'package:alchemist/alchemist.dart'; import 'package:alchemist/src/golden_test_scenario_constraints.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -31,6 +31,19 @@ void main() { expect(find.text('name'), findsOneWidget); }); + testWidgets('does not render name as label', (tester) async { + await AlchemistConfig.runWithConfig( + config: const AlchemistConfig(renderName: false), + run: () async { + final subject = buildSubject(); + + await tester.pumpWidget(subject); + + expect(find.text('name'), findsNothing); + }, + ); + }); + testWidgets('renders child', (tester) async { final subject = buildSubject();