diff --git a/example/integration_test/screenshot_test.dart b/example/integration_test/screenshot_test.dart new file mode 100644 index 00000000..0b43e6e2 --- /dev/null +++ b/example/integration_test/screenshot_test.dart @@ -0,0 +1,134 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:yaru/yaru.dart'; +import 'package:yaru_example/main.dart' as app; +import 'package:yaru_example/view/home_page.dart'; + +// NOTE: run `flutter test --update-goldens integration_test` to update screenshots + +Future main() async { + final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + binding.window.devicePixelRatioTestValue = 1; + + testWidgets('fonts', (tester) async { + app.main(); + await tester.pumpAndSettle(); + await tester.takeScreenshots('fonts'); + }); + + testWidgets('buttons', (tester) async { + app.main(); + await tester.pumpAndSettle(); + await tester.tap(find.text('Controls')); + await tester.pump(); + await tester.takeScreenshots('buttons'); + }); + + testWidgets('checks', (tester) async { + app.main(); + await tester.pumpAndSettle(); + await tester.tap(find.text('Controls')); + await tester.pump(); + await tester.tap(find.text('Checks')); + await tester.pump(); + await tester.takeScreenshots('checks'); + }); + + testWidgets('switches', (tester) async { + app.main(); + await tester.pumpAndSettle(); + await tester.tap(find.text('Controls')); + await tester.pump(); + await tester.tap(find.text('Switches')); + await tester.pump(); + await tester.takeScreenshots('switches'); + }); + + testWidgets('text fields', (tester) async { + app.main(); + await tester.pumpAndSettle(); + await tester.tap(find.text('Text Fields')); + await tester.pump(); + await tester.takeScreenshots('switches'); + }); + + testWidgets('containers', (tester) async { + app.main(); + await tester.pumpAndSettle(); + await tester.tap(find.text('Containers')); + await tester.pump(); + await tester.takeScreenshots('containers'); + }); +} + +extension on WidgetTester { + Brightness get brightness { + final context = element(find.byType(HomePage)); + return Theme.of(context).brightness; + } + + YaruVariant get variant { + final context = element(find.byType(HomePage)); + return YaruTheme.of(context).variant!; + } + + bool get highContrast { + final context = element(find.byType(HomePage)); + return YaruTheme.of(context).highContrast!; + } + + Future toggleBrightness() async { + for (final icon in [Icons.light_mode, Icons.dark_mode]) { + final button = find.widgetWithIcon(TextButton, icon); + if (button.evaluate().isNotEmpty) { + await tap(button); + await pumpAndSettle(); + break; + } + } + } + + Future selectTheme(Color color) async { + await tap(find.byType(PopupMenuButton)); + await pumpAndSettle(); + + final menuItem = find.byWidgetPredicate((widget) { + return widget is PopupMenuItem && widget.value == color; + }); + await ensureVisible(menuItem); + await tap(menuItem); + await pumpAndSettle(); + } + + Future takeScreenshots(String screen) async { + for (var i = 0; i < 2; ++i) { + await toggleBrightness(); + + await selectTheme(YaruVariant.orange.color); + await takeScreenshot(screen); + + switch (brightness) { + case Brightness.light: + await selectTheme(Colors.black); + break; + case Brightness.dark: + await selectTheme(Colors.white); + break; + } + await takeScreenshot(screen); + } + } + + Future takeScreenshot(String screen) async { + final suffix = [ + if (highContrast) 'high-contrast' else variant.name, + brightness.name, + ].join('-'); + + await expectLater( + find.byType(MaterialApp), + matchesGoldenFile('screenshots/$screen-$suffix.png'), + ); + } +} diff --git a/example/integration_test/screenshots/buttons-high-contrast-dark.png b/example/integration_test/screenshots/buttons-high-contrast-dark.png new file mode 100644 index 00000000..2d3f8b3c Binary files /dev/null and b/example/integration_test/screenshots/buttons-high-contrast-dark.png differ diff --git a/example/integration_test/screenshots/buttons-high-contrast-light.png b/example/integration_test/screenshots/buttons-high-contrast-light.png new file mode 100644 index 00000000..2f409b8b Binary files /dev/null and b/example/integration_test/screenshots/buttons-high-contrast-light.png differ diff --git a/example/integration_test/screenshots/buttons-orange-dark.png b/example/integration_test/screenshots/buttons-orange-dark.png new file mode 100644 index 00000000..ce42f7f8 Binary files /dev/null and b/example/integration_test/screenshots/buttons-orange-dark.png differ diff --git a/example/integration_test/screenshots/buttons-orange-light.png b/example/integration_test/screenshots/buttons-orange-light.png new file mode 100644 index 00000000..589608c9 Binary files /dev/null and b/example/integration_test/screenshots/buttons-orange-light.png differ diff --git a/example/integration_test/screenshots/checks-high-contrast-dark.png b/example/integration_test/screenshots/checks-high-contrast-dark.png new file mode 100644 index 00000000..0faca6c2 Binary files /dev/null and b/example/integration_test/screenshots/checks-high-contrast-dark.png differ diff --git a/example/integration_test/screenshots/checks-high-contrast-light.png b/example/integration_test/screenshots/checks-high-contrast-light.png new file mode 100644 index 00000000..f81efa55 Binary files /dev/null and b/example/integration_test/screenshots/checks-high-contrast-light.png differ diff --git a/example/integration_test/screenshots/checks-orange-dark.png b/example/integration_test/screenshots/checks-orange-dark.png new file mode 100644 index 00000000..192fa19d Binary files /dev/null and b/example/integration_test/screenshots/checks-orange-dark.png differ diff --git a/example/integration_test/screenshots/checks-orange-light.png b/example/integration_test/screenshots/checks-orange-light.png new file mode 100644 index 00000000..83fbf835 Binary files /dev/null and b/example/integration_test/screenshots/checks-orange-light.png differ diff --git a/example/integration_test/screenshots/containers-high-contrast-dark.png b/example/integration_test/screenshots/containers-high-contrast-dark.png new file mode 100644 index 00000000..1decebbb Binary files /dev/null and b/example/integration_test/screenshots/containers-high-contrast-dark.png differ diff --git a/example/integration_test/screenshots/containers-high-contrast-light.png b/example/integration_test/screenshots/containers-high-contrast-light.png new file mode 100644 index 00000000..fd543039 Binary files /dev/null and b/example/integration_test/screenshots/containers-high-contrast-light.png differ diff --git a/example/integration_test/screenshots/containers-orange-dark.png b/example/integration_test/screenshots/containers-orange-dark.png new file mode 100644 index 00000000..55479699 Binary files /dev/null and b/example/integration_test/screenshots/containers-orange-dark.png differ diff --git a/example/integration_test/screenshots/containers-orange-light.png b/example/integration_test/screenshots/containers-orange-light.png new file mode 100644 index 00000000..434e934c Binary files /dev/null and b/example/integration_test/screenshots/containers-orange-light.png differ diff --git a/example/integration_test/screenshots/fonts-high-contrast-dark.png b/example/integration_test/screenshots/fonts-high-contrast-dark.png new file mode 100644 index 00000000..1b800554 Binary files /dev/null and b/example/integration_test/screenshots/fonts-high-contrast-dark.png differ diff --git a/example/integration_test/screenshots/fonts-high-contrast-light.png b/example/integration_test/screenshots/fonts-high-contrast-light.png new file mode 100644 index 00000000..67d29b34 Binary files /dev/null and b/example/integration_test/screenshots/fonts-high-contrast-light.png differ diff --git a/example/integration_test/screenshots/fonts-orange-dark.png b/example/integration_test/screenshots/fonts-orange-dark.png new file mode 100644 index 00000000..471f540c Binary files /dev/null and b/example/integration_test/screenshots/fonts-orange-dark.png differ diff --git a/example/integration_test/screenshots/fonts-orange-light.png b/example/integration_test/screenshots/fonts-orange-light.png new file mode 100644 index 00000000..8460592d Binary files /dev/null and b/example/integration_test/screenshots/fonts-orange-light.png differ diff --git a/example/integration_test/screenshots/switches-high-contrast-dark.png b/example/integration_test/screenshots/switches-high-contrast-dark.png new file mode 100644 index 00000000..7221b5e9 Binary files /dev/null and b/example/integration_test/screenshots/switches-high-contrast-dark.png differ diff --git a/example/integration_test/screenshots/switches-high-contrast-light.png b/example/integration_test/screenshots/switches-high-contrast-light.png new file mode 100644 index 00000000..32904ff2 Binary files /dev/null and b/example/integration_test/screenshots/switches-high-contrast-light.png differ diff --git a/example/integration_test/screenshots/switches-orange-dark.png b/example/integration_test/screenshots/switches-orange-dark.png new file mode 100644 index 00000000..74e89acd Binary files /dev/null and b/example/integration_test/screenshots/switches-orange-dark.png differ diff --git a/example/integration_test/screenshots/switches-orange-light.png b/example/integration_test/screenshots/switches-orange-light.png new file mode 100644 index 00000000..e09479de Binary files /dev/null and b/example/integration_test/screenshots/switches-orange-light.png differ diff --git a/example/lib/view/home_page.dart b/example/lib/view/home_page.dart index 8b92bdbc..31181e13 100644 --- a/example/lib/view/home_page.dart +++ b/example/lib/view/home_page.dart @@ -69,6 +69,9 @@ class HomePageState extends State { itemBuilder: (context) { return [ PopupMenuItem( + value: theme.themeMode == ThemeMode.light + ? Colors.black + : Colors.white, onTap: () => AppTheme.apply(context, highContrast: true), child: Row( children: [ @@ -84,6 +87,7 @@ class HomePageState extends State { ), for (final variant in YaruVariant.values) // skip flavors PopupMenuItem( + value: variant.color, onTap: () => AppTheme.apply( context, variant: variant, diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 4486510c..a74a62b1 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -18,6 +18,8 @@ dev_dependencies: flutter_lints: ^2.0.1 flutter_test: sdk: flutter + integration_test: + sdk: flutter flutter: uses-material-design: true