Skip to content

Commit

Permalink
fix: Dialog and dropdown are no longer visible on the golden files (B…
Browse files Browse the repository at this point in the history
  • Loading branch information
SchachtLyth committed May 10, 2023
1 parent 5117adc commit e53fedd
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/src/golden_test_adapter.dart
Expand Up @@ -136,6 +136,9 @@ abstract class GoldenTestAdapter {

/// Pumps the given [widget] with the given [tester] for use in golden tests.
///
/// The [rootKey], if provided, will be attached to the top-most [Widget] in
/// the tree.
///
/// The [textScaleFactor], if provided, sets the text scale size (usually in
/// a range from 1 to 3).
///
Expand All @@ -154,6 +157,7 @@ abstract class GoldenTestAdapter {
/// max width is unbounded, a default width value will be used as initial
/// surface size. The same applies to the max height.
Future<void> pumpGoldenTest({
Key? rootKey,
required WidgetTester tester,
required double textScaleFactor,
required BoxConstraints constraints,
Expand Down Expand Up @@ -181,6 +185,9 @@ class FlutterGoldenTestAdapter extends GoldenTestAdapter {
/// Create a new [FlutterGoldenTestAdapter].
const FlutterGoldenTestAdapter() : super();

/// Key for the root of the golden test.
static final rootKey = UniqueKey();

/// Key for the child container in the golden test.
static final childKey = UniqueKey();

Expand Down Expand Up @@ -213,6 +220,7 @@ class FlutterGoldenTestAdapter extends GoldenTestAdapter {

@override
Future<void> pumpGoldenTest({
Key? rootKey,
required WidgetTester tester,
required double textScaleFactor,
required BoxConstraints constraints,
Expand All @@ -230,6 +238,7 @@ class FlutterGoldenTestAdapter extends GoldenTestAdapter {
await pumpWidget(
tester,
FlutterGoldenTestWrapper(
key: rootKey,
obscureFont: obscureFont,
globalConfigTheme: globalConfigTheme,
variantConfigTheme: variantConfigTheme,
Expand Down
5 changes: 3 additions & 2 deletions lib/src/golden_test_runner.dart
Expand Up @@ -69,14 +69,15 @@ class FlutterGoldenTestRunner extends GoldenTestRunner {
'Golden path must be a String or Uri.',
);

final childKey = FlutterGoldenTestAdapter.childKey;
final rootKey = FlutterGoldenTestAdapter.rootKey;

final mementoDebugDisableShadows = debugDisableShadows;
debugDisableShadows = !renderShadows;

try {
await goldenTestAdapter.pumpGoldenTest(
tester: tester,
rootKey: rootKey,
textScaleFactor: textScaleFactor,
constraints: constraints,
obscureFont: obscureText,
Expand All @@ -92,7 +93,7 @@ class FlutterGoldenTestRunner extends GoldenTestRunner {
cleanup = await whilePerforming(tester);
}

final finder = find.byKey(childKey);
final finder = find.byKey(rootKey);

final toMatch = obscureText
? goldenTestAdapter.getBlockedTextImage(
Expand Down
50 changes: 50 additions & 0 deletions test/smoke_tests/dropdown_smoke_test.dart
@@ -0,0 +1,50 @@
import 'package:alchemist/src/golden_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

class TestDropdownButton extends StatelessWidget {
const TestDropdownButton({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) => Center(
child: DropdownButton<String>(
value: '0',
items: const [
DropdownMenuItem<String>(
value: '0',
child: Text('0'),
),
DropdownMenuItem<String>(
value: '1',
child: Text('1'),
),
DropdownMenuItem<String>(
value: '2',
child: Text('2'),
),
],
onChanged: (_) {},
),
);
}

void main() {
group('smoke test', () {
goldenTest(
'succeeds after tapping dropdown',
fileName: 'dropdown_smoke_test',
constraints: const BoxConstraints(
maxWidth: 200,
maxHeight: 250,
),
pumpBeforeTest: (tester) async {
await tester.pumpAndSettle();
await tester.tap(find.byType(DropdownButton<String>));
await tester.pumpAndSettle();
},
builder: () {
return const TestDropdownButton();
},
);
});
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions test/src/golden_test_runner_test.dart
Expand Up @@ -51,6 +51,7 @@ void main() {

when(
() => goldenTestAdapter.pumpGoldenTest(
rootKey: any(named: 'rootKey'),
tester: any(named: 'tester'),
textScaleFactor: any(named: 'textScaleFactor'),
constraints: any(named: 'constraints'),
Expand Down Expand Up @@ -155,6 +156,7 @@ void main() {
final originalSize = tester.binding.window.physicalSize;
when(
() => goldenTestAdapter.pumpGoldenTest(
rootKey: any(named: 'rootKey'),
tester: any(named: 'tester'),
textScaleFactor: any(named: 'textScaleFactor'),
constraints: any(named: 'constraints'),
Expand Down
1 change: 1 addition & 0 deletions test/src/golden_test_test.dart
Expand Up @@ -34,6 +34,7 @@ class FakeGoldenTestAdapter extends Mock implements GoldenTestAdapter {

@override
Future<void> pumpGoldenTest({
Key? rootKey,
required WidgetTester tester,
required double textScaleFactor,
required BoxConstraints constraints,
Expand Down

0 comments on commit e53fedd

Please sign in to comment.