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

Add pathBuilder into expectGolden tester function #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
33 changes: 31 additions & 2 deletions example/simple_app/test/src/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart';

void main() {
testAdaptiveWidgets(
'$App render',
'Adaptive test without pathBuilder',
(tester, variant) async {
await tester.pumpWidget(
AdaptiveWrapper(
Expand All @@ -22,9 +22,38 @@ void main() {
await tester.tap(textField);
await tester.pumpAndSettle();

await tester.expectGolden<App>(variant, suffix: 'simple_with_keyboard');
},
);

testAdaptiveWidgets(
'Adaptive test with pathBuilder',
(tester, variant) async {
await tester.pumpWidget(
AdaptiveWrapper(
windowConfig: variant,
tester: tester,
child: const App(),
),
);

await tester.expectGolden<App>(
variant,
pathBuilder: () {
return "golden/simple/without_keyboard/${variant.name}.png";
},
);

final textField = find.byType(TextField);

await tester.tap(textField);
await tester.pumpAndSettle();

await tester.expectGolden<App>(
variant,
suffix: 'simple_with_keyboard',
pathBuilder: () {
return "golden/simple/with_keyboard/${variant.name}.png";
},
);
},
);
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.
Binary file modified example/simple_app/test/src/preview/desktop-app_simple.png
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.
Binary file modified example/simple_app/test/src/preview/iPadPro-app_simple.png
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.
Binary file modified example/simple_app/test/src/preview/iPhone_13-app_simple.png
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.
Binary file modified example/simple_app/test/src/preview/iPhone_8-app_simple.png
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.
Binary file modified example/simple_app/test/src/preview/pixel_5-app_simple.png
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.
18 changes: 9 additions & 9 deletions lib/src/adaptive/adaptive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,26 @@ extension Adaptive on WidgetTester {
Key?
byKey, // Sometimes we want to find the widget by its unique key in the case they are multiple of the same type.
bool waitForImages = true,
String Function()? pathBuilder,
Copy link
Member

Choose a reason for hiding this comment

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

Why did you choose a function without argument for parameter, instead of a simple String? ?
Ex:

String? path

instead of:

String Function()? pathBuilder,

Also if this parameters is optional, we should add the default value in the documentation

Copy link
Author

Choose a reason for hiding this comment

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

I did this one month ago, and I really don't remember why I used a function instead of a string.
But when I see it now, I think it is possible to use a string there.

}) async {
final enforcedTestPlatform =
AdaptiveTestConfiguration.instance.enforcedTestPlatform;
if (enforcedTestPlatform != null &&
!enforcedTestPlatform.isRuntimePlatform) {
final enforcedTestPlatform = AdaptiveTestConfiguration.instance.enforcedTestPlatform;
if (enforcedTestPlatform != null && !enforcedTestPlatform.isRuntimePlatform) {
throw ('Runtime platform ${Platform.operatingSystem} is not ${enforcedTestPlatform.name}');
}

final localSuffix = suffix != null ? "_${ReCase(suffix).snakeCase}" : '';
pathBuilder ??= () {
final name = ReCase('$T');
final localSuffix = suffix != null ? "_${ReCase(suffix).snakeCase}" : '';
return 'preview/${windowConfig.name}-${name.snakeCase}$localSuffix.png';
};

final name = ReCase('$T');
if (waitForImages) {
await awaitImages();
}
await expectLater(
// Find by its type except if the widget's unique key was given.
byKey != null ? find.byKey(byKey) : find.byType(AdaptiveWrapper),
matchesGoldenFile(
'preview/${windowConfig.name}-${name.snakeCase}$localSuffix.png',
),
matchesGoldenFile(pathBuilder.call()),
);
}
}