Skip to content

Commit

Permalink
Implement all SmallButton golden test into a single image
Browse files Browse the repository at this point in the history
  • Loading branch information
JvnSlv committed Jul 31, 2024
1 parent 8016369 commit 2ab17e3
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 43 deletions.
43 changes: 43 additions & 0 deletions packages/widget_toolkit/test/helpers/golden_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,46 @@ Future<void> pumpDeviceBuilderWithMaterialApp(
),
);
}

void runGoldenBuilderTests(
String testName, {
required Size surfaceSize,
required GoldenBuilder builder,
WidgetTesterCallback? act,
CustomPump? matcherCustomPump,
}) {
for (final theme in Themes.values) {
final themeName = theme.name;
final directory = '${themeName}_theme';

testGoldens('$testName - $themeName', (tester) async {
await tester.pumpWidgetBuilder(
builder.build(),
wrapper: materialAppWrapper(
localizations: [
...GlobalMaterialLocalizations.delegates,
],
theme: theme == Themes.light
? ThemeData(
extensions: <ThemeExtension<dynamic>>[
WidgetToolkitTheme.light(),
],
)
: ThemeData(
extensions: <ThemeExtension<dynamic>>[
WidgetToolkitTheme.dark(),
],
),
),
surfaceSize: surfaceSize,
);

if (act != null) {
await act.call(tester);
}

await screenMatchesGolden(tester, '$directory/$testName',
customPump: matcherCustomPump);
});
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:golden_toolkit/golden_toolkit.dart';
import 'package:widget_toolkit/ui_components.dart';

import '../../../helpers/golden_helper.dart';
import '../factory/small_button_factory.dart';

void main() {
runGoldenBuilderTests(
'SmallButton Golden Tests',
surfaceSize: const Size(700, 350),
matcherCustomPump: (widget) =>
widget.pump(const Duration(milliseconds: 350)),
builder: GoldenBuilder.grid(
columns: 4,
widthToHeightRatio: 1,
)
..addScenario(
'loading filled',
smallButtonFactory(
type: SmallButtonType.filled, state: ButtonStateModel.loading))
..addScenario(
'enabled filled',
smallButtonFactory(
type: SmallButtonType.filled, state: ButtonStateModel.enabled))
..addScenario(
'disabled filled',
smallButtonFactory(
type: SmallButtonType.filled, state: ButtonStateModel.disabled))
..addScenario(
'pressed filled',
smallButtonFactory(
type: SmallButtonType.filled, state: ButtonStateModel.pressed))
..addScenario(
'loading outlined',
smallButtonFactory(
type: SmallButtonType.outline, state: ButtonStateModel.loading))
..addScenario(
'enabled outlined',
smallButtonFactory(
type: SmallButtonType.outline, state: ButtonStateModel.enabled))
..addScenario(
'disabled outlined',
smallButtonFactory(
type: SmallButtonType.outline, state: ButtonStateModel.disabled))
..addScenario(
'pressed outlined',
smallButtonFactory(
type: SmallButtonType.outline, state: ButtonStateModel.pressed)),
);
}

0 comments on commit 2ab17e3

Please sign in to comment.