Skip to content

Commit

Permalink
Add a test component with a golden test
Browse files Browse the repository at this point in the history
  • Loading branch information
comigor committed Oct 5, 2018
1 parent d7c8e67 commit 590484e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/components/my_component.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';

class MyComponent extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('This is my text'),
Text('This is another text'),
RaisedButton(
onPressed: () {},
child: Text('This should be a button'),
color: Colors.amber,
),
Switch(
onChanged: (_) {},
value: true,
),
Slider(
value: 2.0,
max: 7.0,
onChanged: (_) {},
),
],
);
}
}
Binary file added test/components/golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions test/components/my_component_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

import 'package:showcase/components/my_component.dart';
import '../helpers/golden_boundary.dart';

void main() {
testWidgets('MyComponent golden', (WidgetTester tester) async {
await tester.pumpWidget(GoldenBoundary(
child: MyComponent(),
));

await expectLater(
find.byType(Container).first,
matchesGoldenFile('golden.png'),
);
});
}
23 changes: 23 additions & 0 deletions test/helpers/golden_boundary.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';

class GoldenBoundary extends StatelessWidget {
final Widget child;

GoldenBoundary({@required this.child});

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: RepaintBoundary(
child: Container(
padding: EdgeInsets.all(10.0),
width: 640.0,
height: 480.0,
child: child,
),
),
),
);
}
}

0 comments on commit 590484e

Please sign in to comment.