-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds DeviceBuilder class to generate single golden file for all Devic…
…es/Scenarios DeviceBuilder will create a single widget to lay out multiple scenarios vertically and multiple devices for those scenarios horizontally. This single widget can then be used to create one golden png file. Updates workspace setting to include lineLength that is enforced by pr pipelines
- Loading branch information
1 parent
c1028fd
commit 869496e
Showing
15 changed files
with
742 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export 'src/flutter_demo_page.dart'; | ||
export 'src/weather_widgets.dart'; |
63 changes: 63 additions & 0 deletions
63
packages/golden_toolkit/example/lib/src/flutter_demo_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Counter page from flutters default generated app | ||
class FlutterDemoPage extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Flutter Demo', | ||
theme: ThemeData( | ||
primarySwatch: Colors.blue, | ||
visualDensity: VisualDensity.adaptivePlatformDensity, | ||
), | ||
home: const _MyHomePage(title: 'Flutter Demo Home Page'), | ||
); | ||
} | ||
} | ||
|
||
class _MyHomePage extends StatefulWidget { | ||
const _MyHomePage({Key key, this.title}) : super(key: key); | ||
|
||
final String title; | ||
|
||
@override | ||
_MyHomePageState createState() => _MyHomePageState(); | ||
} | ||
|
||
class _MyHomePageState extends State<_MyHomePage> { | ||
int _counter = 0; | ||
|
||
void _incrementCounter() { | ||
setState(() { | ||
_counter++; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(widget.title), | ||
), | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
const Text( | ||
'You have pushed the button this many times:', | ||
), | ||
Text( | ||
'$_counter', | ||
style: Theme.of(context).textTheme.headline4, | ||
), | ||
], | ||
), | ||
), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: _incrementCounter, | ||
tooltip: 'Increment', | ||
child: const Icon(Icons.add), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/golden_toolkit/example/test/flutter_demo_page_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:golden_toolkit/golden_toolkit.dart'; | ||
|
||
// ignore: avoid_relative_lib_imports | ||
import '../lib/src/flutter_demo_page.dart'; | ||
|
||
void main() { | ||
testGoldens('DeviceBuilder - one scenario - default devices', (tester) async { | ||
final builder = DeviceBuilder() | ||
..addScenario( | ||
widget: FlutterDemoPage(), | ||
name: 'default page', | ||
); | ||
|
||
await tester.pumpDeviceBuilder(builder); | ||
|
||
await screenMatchesGolden(tester, 'flutter_demo_page_single_scenario'); | ||
}); | ||
|
||
testGoldens('DeviceBuilder - one scenario - override devices', (tester) async { | ||
final builder = DeviceBuilder() | ||
..overrideDevicesForAllScenarios(devices: [ | ||
Device.phone, | ||
Device.iphone11, | ||
Device.tabletPortrait, | ||
Device.tabletLandscape, | ||
]) | ||
..addScenario( | ||
widget: FlutterDemoPage(), | ||
name: 'default page', | ||
); | ||
|
||
await tester.pumpDeviceBuilder(builder); | ||
|
||
await screenMatchesGolden(tester, 'flutter_demo_page_single_scenario_more_devices'); | ||
}); | ||
|
||
testGoldens('DeviceBuilder - multiple scenarios - with onCreate', (tester) async { | ||
final builder = DeviceBuilder() | ||
..overrideDevicesForAllScenarios(devices: [ | ||
Device.phone, | ||
Device.iphone11, | ||
Device.tabletPortrait, | ||
Device.tabletLandscape, | ||
]) | ||
..addScenario( | ||
widget: FlutterDemoPage(), | ||
name: 'default page', | ||
) | ||
..addScenario( | ||
widget: FlutterDemoPage(), | ||
name: 'tap once', | ||
onCreate: (scenarioWidgetKey) async { | ||
final finder = find.descendant( | ||
of: find.byKey(scenarioWidgetKey), | ||
matching: find.byIcon(Icons.add), | ||
); | ||
expect(finder, findsOneWidget); | ||
await tester.tap(finder); | ||
}, | ||
) | ||
..addScenario( | ||
widget: FlutterDemoPage(), | ||
name: 'tap five times', | ||
onCreate: (scenarioWidgetKey) async { | ||
final finder = find.descendant( | ||
of: find.byKey(scenarioWidgetKey), | ||
matching: find.byIcon(Icons.add), | ||
); | ||
expect(finder, findsOneWidget); | ||
|
||
await tester.tap(finder); | ||
await tester.tap(finder); | ||
await tester.tap(finder); | ||
await tester.tap(finder); | ||
await tester.tap(finder); | ||
}, | ||
); | ||
|
||
await tester.pumpDeviceBuilder(builder); | ||
|
||
await screenMatchesGolden(tester, 'flutter_demo_page_multiple_scenarios'); | ||
}); | ||
} |
Binary file added
BIN
+238 KB
...es/golden_toolkit/example/test/goldens/flutter_demo_page_multiple_scenarios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+43.9 KB
packages/golden_toolkit/example/test/goldens/flutter_demo_page_single_scenario.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+80.6 KB
...toolkit/example/test/goldens/flutter_demo_page_single_scenario_more_devices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.