Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 14 additions & 5 deletions lib/src/alchemist_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 10 additions & 7 deletions lib/src/golden_test_scenario.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class GoldenTestScenario extends StatelessWidget {

@override
Widget build(BuildContext context) {
final config = AlchemistConfig.current();
final testTheme =
Theme.of(context).extension<GoldenTestTheme>() ??
AlchemistConfig.current().goldenTestTheme ??
Expand All @@ -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) ...<Widget>[
Text(
name,
style: testTheme.nameTextStyle,
textHeightBehavior: const TextHeightBehavior(
applyHeightToFirstAscent: false,
),
),
),
const SizedBox(height: 8),
const SizedBox(height: 8)
Comment on lines +82 to +90
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (config.renderName) ...<Widget>[
Text(
name,
style: testTheme.nameTextStyle,
textHeightBehavior: const TextHeightBehavior(
applyHeightToFirstAscent: false,
),
),
),
const SizedBox(height: 8),
const SizedBox(height: 8)
if (config.renderName) ...[
Text(
name,
style: testTheme.nameTextStyle,
textHeightBehavior: const TextHeightBehavior(
applyHeightToFirstAscent: false,
),
),
const SizedBox(height: 8),

probably updating branch will complain about this

],
ConstrainedBox(
constraints:
constraints ??
Expand Down
15 changes: 14 additions & 1 deletion test/src/golden_test_scenario_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();

Expand Down
Loading