diff --git a/.github/workflows/flutter-ci.yml b/.github/workflows/flutter-ci.yml index 52eb6b55..44b54921 100644 --- a/.github/workflows/flutter-ci.yml +++ b/.github/workflows/flutter-ci.yml @@ -58,6 +58,35 @@ jobs: - name: Check for any formatting issues run: dart format --set-exit-if-changed . + integration: + runs-on: ubuntu-22.04 + steps: + + - uses: actions/checkout@v2 + - uses: subosito/flutter-action@v2 + with: + channel: 'stable' + flutter-version: '3.10.x' + + - name: Install dependencies + run: | + sudo apt update + sudo apt -y install clang cmake curl libgtk-3-dev ninja-build pkg-config unzip xvfb + sudo apt -y install fonts-noto-cjk fonts-ubuntu fonts-tibetan-machine + + - name: Get dependencies + run: flutter pub get + + - name: Run integration tests + run: xvfb-run -a -s '-screen 0 1280x800x24 +extension GLX' flutter test -d linux integration_test + working-directory: example/ + + - uses: actions/upload-artifact@v3 + if: failure() + with: + name: failures + path: example/integration_test/failures + pub: runs-on: ubuntu-20.04 steps: diff --git a/example/integration_test/golden_test.dart b/example/integration_test/golden_test.dart new file mode 100644 index 00000000..559b0325 --- /dev/null +++ b/example/integration_test/golden_test.dart @@ -0,0 +1,117 @@ +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/main.dart'; +import 'package:yaru_example/view/home_page.dart'; + +// NOTE: run `flutter test --update-goldens integration_test` to update screenshots + +Future main() async { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('fonts', (tester) async { + tester.runApp(); + await tester.pumpAndSettle(); + await tester.takeScreenshots('fonts'); + }); + + testWidgets('buttons', (tester) async { + tester.runApp(); + await tester.pumpAndSettle(); + await tester.tap(find.text('Controls')); + await tester.pump(); + await tester.takeScreenshots('buttons'); + }); + + testWidgets('checks', (tester) async { + tester.runApp(); + 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 { + tester.runApp(); + 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 { + tester.runApp(); + await tester.pumpAndSettle(); + await tester.tap(find.text('Text Fields')); + await tester.pump(); + primaryFocus?.unfocus(); + await tester.pump(); + await tester.takeScreenshots('text-fields'); + }); + + testWidgets('containers', (tester) async { + tester.runApp(); + await tester.pumpAndSettle(); + await tester.tap(find.text('Containers')); + await tester.pump(); + await tester.takeScreenshots('containers'); + }); +} + +extension on WidgetTester { + void runApp() { + view.devicePixelRatio = 1; + view.physicalSize = const Size(600, 700); + app.main(); + } + + void selectTheme({ + YaruVariant? variant, + bool? highContrast, + ThemeMode? themeMode, + }) async { + final context = element(find.byType(HomePage)); + AppTheme.apply( + context, + variant: variant, + highContrast: highContrast, + themeMode: themeMode, + ); + } + + Future takeScreenshots(String screen) async { + for (final themeMode in [ThemeMode.light, ThemeMode.dark]) { + selectTheme( + variant: YaruVariant.orange, + themeMode: themeMode, + highContrast: false, + ); + await pumpAndSettle(); + await takeScreenshot(screen); + + selectTheme(themeMode: themeMode, highContrast: true); + await pumpAndSettle(); + await takeScreenshot(screen); + } + } + + Future takeScreenshot(String screen) async { + final context = element(find.byType(HomePage)); + final theme = AppTheme.of(context); + final suffix = [ + if (theme.highContrast == true) 'high-contrast' else theme.variant?.name, + theme.themeMode?.name, + ].join('-'); + + await expectLater( + find.byType(MaterialApp), + matchesGoldenFile('goldens/$screen-$suffix.png'), + ); + } +} diff --git a/example/integration_test/goldens/buttons-high-contrast-dark.png b/example/integration_test/goldens/buttons-high-contrast-dark.png new file mode 100644 index 00000000..bf831055 Binary files /dev/null and b/example/integration_test/goldens/buttons-high-contrast-dark.png differ diff --git a/example/integration_test/goldens/buttons-high-contrast-light.png b/example/integration_test/goldens/buttons-high-contrast-light.png new file mode 100644 index 00000000..46384d86 Binary files /dev/null and b/example/integration_test/goldens/buttons-high-contrast-light.png differ diff --git a/example/integration_test/goldens/buttons-orange-dark.png b/example/integration_test/goldens/buttons-orange-dark.png new file mode 100644 index 00000000..09b62688 Binary files /dev/null and b/example/integration_test/goldens/buttons-orange-dark.png differ diff --git a/example/integration_test/goldens/buttons-orange-light.png b/example/integration_test/goldens/buttons-orange-light.png new file mode 100644 index 00000000..9d3f23ad Binary files /dev/null and b/example/integration_test/goldens/buttons-orange-light.png differ diff --git a/example/integration_test/goldens/checks-high-contrast-dark.png b/example/integration_test/goldens/checks-high-contrast-dark.png new file mode 100644 index 00000000..73b64d77 Binary files /dev/null and b/example/integration_test/goldens/checks-high-contrast-dark.png differ diff --git a/example/integration_test/goldens/checks-high-contrast-light.png b/example/integration_test/goldens/checks-high-contrast-light.png new file mode 100644 index 00000000..993aa7df Binary files /dev/null and b/example/integration_test/goldens/checks-high-contrast-light.png differ diff --git a/example/integration_test/goldens/checks-orange-dark.png b/example/integration_test/goldens/checks-orange-dark.png new file mode 100644 index 00000000..c71b5a68 Binary files /dev/null and b/example/integration_test/goldens/checks-orange-dark.png differ diff --git a/example/integration_test/goldens/checks-orange-light.png b/example/integration_test/goldens/checks-orange-light.png new file mode 100644 index 00000000..8c35f0f4 Binary files /dev/null and b/example/integration_test/goldens/checks-orange-light.png differ diff --git a/example/integration_test/goldens/containers-high-contrast-dark.png b/example/integration_test/goldens/containers-high-contrast-dark.png new file mode 100644 index 00000000..ad58d5cc Binary files /dev/null and b/example/integration_test/goldens/containers-high-contrast-dark.png differ diff --git a/example/integration_test/goldens/containers-high-contrast-light.png b/example/integration_test/goldens/containers-high-contrast-light.png new file mode 100644 index 00000000..1f76bb1e Binary files /dev/null and b/example/integration_test/goldens/containers-high-contrast-light.png differ diff --git a/example/integration_test/goldens/containers-orange-dark.png b/example/integration_test/goldens/containers-orange-dark.png new file mode 100644 index 00000000..bc2e0e14 Binary files /dev/null and b/example/integration_test/goldens/containers-orange-dark.png differ diff --git a/example/integration_test/goldens/containers-orange-light.png b/example/integration_test/goldens/containers-orange-light.png new file mode 100644 index 00000000..b7f6d278 Binary files /dev/null and b/example/integration_test/goldens/containers-orange-light.png differ diff --git a/example/integration_test/goldens/fonts-high-contrast-dark.png b/example/integration_test/goldens/fonts-high-contrast-dark.png new file mode 100644 index 00000000..4994d638 Binary files /dev/null and b/example/integration_test/goldens/fonts-high-contrast-dark.png differ diff --git a/example/integration_test/goldens/fonts-high-contrast-light.png b/example/integration_test/goldens/fonts-high-contrast-light.png new file mode 100644 index 00000000..51f2c57f Binary files /dev/null and b/example/integration_test/goldens/fonts-high-contrast-light.png differ diff --git a/example/integration_test/goldens/fonts-orange-dark.png b/example/integration_test/goldens/fonts-orange-dark.png new file mode 100644 index 00000000..f729a6fc Binary files /dev/null and b/example/integration_test/goldens/fonts-orange-dark.png differ diff --git a/example/integration_test/goldens/fonts-orange-light.png b/example/integration_test/goldens/fonts-orange-light.png new file mode 100644 index 00000000..30029df2 Binary files /dev/null and b/example/integration_test/goldens/fonts-orange-light.png differ diff --git a/example/integration_test/goldens/switches-high-contrast-dark.png b/example/integration_test/goldens/switches-high-contrast-dark.png new file mode 100644 index 00000000..f340960f Binary files /dev/null and b/example/integration_test/goldens/switches-high-contrast-dark.png differ diff --git a/example/integration_test/goldens/switches-high-contrast-light.png b/example/integration_test/goldens/switches-high-contrast-light.png new file mode 100644 index 00000000..f06b082c Binary files /dev/null and b/example/integration_test/goldens/switches-high-contrast-light.png differ diff --git a/example/integration_test/goldens/switches-orange-dark.png b/example/integration_test/goldens/switches-orange-dark.png new file mode 100644 index 00000000..0723c3de Binary files /dev/null and b/example/integration_test/goldens/switches-orange-dark.png differ diff --git a/example/integration_test/goldens/switches-orange-light.png b/example/integration_test/goldens/switches-orange-light.png new file mode 100644 index 00000000..cba91f64 Binary files /dev/null and b/example/integration_test/goldens/switches-orange-light.png differ diff --git a/example/integration_test/goldens/text-fields-high-contrast-dark.png b/example/integration_test/goldens/text-fields-high-contrast-dark.png new file mode 100644 index 00000000..9d53c061 Binary files /dev/null and b/example/integration_test/goldens/text-fields-high-contrast-dark.png differ diff --git a/example/integration_test/goldens/text-fields-high-contrast-light.png b/example/integration_test/goldens/text-fields-high-contrast-light.png new file mode 100644 index 00000000..5c7492ac Binary files /dev/null and b/example/integration_test/goldens/text-fields-high-contrast-light.png differ diff --git a/example/integration_test/goldens/text-fields-orange-dark.png b/example/integration_test/goldens/text-fields-orange-dark.png new file mode 100644 index 00000000..1559b9f5 Binary files /dev/null and b/example/integration_test/goldens/text-fields-orange-dark.png differ diff --git a/example/integration_test/goldens/text-fields-orange-light.png b/example/integration_test/goldens/text-fields-orange-light.png new file mode 100644 index 00000000..1796114c Binary files /dev/null and b/example/integration_test/goldens/text-fields-orange-light.png differ diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a8bfbd64..6c0247c1 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