diff --git a/.fvmrc b/.fvmrc new file mode 100644 index 0000000..e8b4151 --- /dev/null +++ b/.fvmrc @@ -0,0 +1,3 @@ +{ + "flutter": "3.35.7" +} \ No newline at end of file diff --git a/.github/workflows/.env b/.github/workflows/.env deleted file mode 100644 index 6eef3cd..0000000 --- a/.github/workflows/.env +++ /dev/null @@ -1 +0,0 @@ -FLUTTER_VERSION=3.35.2 diff --git a/.github/workflows/publish-to-pub-on-tag.yaml b/.github/workflows/publish-to-pub-on-tag.yaml index ebb5d61..cece620 100644 --- a/.github/workflows/publish-to-pub-on-tag.yaml +++ b/.github/workflows/publish-to-pub-on-tag.yaml @@ -13,22 +13,21 @@ jobs: id-token: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dart-lang/setup-dart@v1 - - id: dotenv - uses: falti/dotenv-action@v0.2.8 - with: - path: .github/workflows/.env + - id: fvm + name: Read pinned Flutter version from .fvmrc + run: echo "flutter_version=$(jq -r .flutter "$GITHUB_WORKSPACE/.fvmrc")" >> "$GITHUB_OUTPUT" - uses: subosito/flutter-action@v2.5.0 with: - flutter-version: ${{ steps.dotenv.outputs.flutter_version }} + flutter-version: ${{ steps.fvm.outputs.flutter_version }} channel: "stable" cache: true - cache-key: flutter-macos-${{ steps.dotenv.outputs.flutter_version }} - cache-path: ${{ runner.tool_cache }}/flutter-${{ steps.dotenv.outputs.flutter_version }} + cache-key: flutter-macos-${{ steps.fvm.outputs.flutter_version }} + cache-path: ${{ runner.tool_cache }}/flutter-${{ steps.fvm.outputs.flutter_version }} - name: Install Dependencies run: flutter pub get diff --git a/.github/workflows/test-flutter.yaml b/.github/workflows/test-flutter.yaml index 363c041..6601796 100644 --- a/.github/workflows/test-flutter.yaml +++ b/.github/workflows/test-flutter.yaml @@ -10,8 +10,11 @@ jobs: test: runs-on: macos-latest strategy: + fail-fast: false matrix: include: + - dir: . + name: package - dir: example/simple_app name: simple_app - dir: example/multi_packages_app/app @@ -23,20 +26,19 @@ jobs: working-directory: ${{ matrix.dir }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - id: dotenv - uses: falti/dotenv-action@v0.2.8 - with: - path: .github/workflows/.env + - id: fvm + name: Read pinned Flutter version from .fvmrc + run: echo "flutter_version=$(jq -r .flutter "$GITHUB_WORKSPACE/.fvmrc")" >> "$GITHUB_OUTPUT" - uses: subosito/flutter-action@v2.5.0 with: - flutter-version: ${{ steps.dotenv.outputs.flutter_version }} + flutter-version: ${{ steps.fvm.outputs.flutter_version }} channel: "stable" cache: true - cache-key: flutter-macos-${{ steps.dotenv.outputs.flutter_version }} - cache-path: ${{ runner.tool_cache }}/flutter-${{ steps.dotenv.outputs.flutter_version }} + cache-key: flutter-macos-${{ steps.fvm.outputs.flutter_version }} + cache-path: ${{ runner.tool_cache }}/flutter-${{ steps.fvm.outputs.flutter_version }} - name: Install Dependencies run: flutter packages get diff --git a/.github/workflows/update-goldens.yaml b/.github/workflows/update-goldens.yaml new file mode 100644 index 0000000..443a4f8 --- /dev/null +++ b/.github/workflows/update-goldens.yaml @@ -0,0 +1,42 @@ +name: Format and update goldens +on: + workflow_dispatch: + +permissions: + contents: write + +jobs: + update: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + + - id: dotenv + uses: falti/dotenv-action@v0.2.8 + with: + path: .github/workflows/.env + + - uses: subosito/flutter-action@v2.5.0 + with: + flutter-version: ${{ steps.dotenv.outputs.flutter_version }} + channel: "stable" + cache: true + cache-key: flutter-macos-${{ steps.dotenv.outputs.flutter_version }} + cache-path: ${{ runner.tool_cache }}/flutter-${{ steps.dotenv.outputs.flutter_version }} + + - name: Format + run: dart format lib test example + + - name: Regenerate goldens + run: | + for dir in example/simple_app example/multi_packages_app/app example/multi_packages_app/theme; do + (cd "$dir" && flutter pub get && flutter test --update-goldens) + done + + - name: Commit goldens + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add -A lib test example + git diff --cached --quiet || git commit -m "chore: format and update goldens" + git push diff --git a/.gitignore b/.gitignore index 96486fd..fd72688 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ migrate_working_dir/ .dart_tool/ .packages build/ + +# FVM Version Cache +.fvm/ diff --git a/.pubignore b/.pubignore index 4e1d1b0..708f919 100644 --- a/.pubignore +++ b/.pubignore @@ -2,3 +2,6 @@ doc/example.png example/test/**/preview/ +# FVM +.fvm/ +.fvmrc diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7f0468a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dart.flutterSdkPath": ".fvm/versions/3.35.7" +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a56c17..ebe4c4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,33 @@ +## 0.11.0 + +First release as `adaptive_test_plus`, a drop-in compatible continuation of +`adaptive_test` 0.10.4. Golden file paths and existing APIs are unchanged. + +- feat: `testAdaptiveThemedWidgets` runs each device in light and dark mode and + sets the platform brightness accordingly. +- feat: `AdaptiveTestConfiguration.themedDeviceVariant`. +- feat: `WindowConfigData.light()`, `dark()`, `withThemeMode()`. +- feat: localized goldens with `setLocalizedDeviceVariants`, + `WindowConfigData.locale` and `withLocale()`. The locale is applied to the + test platform dispatcher. +- feat: `setApplyThemeModeToPlatformBrightness` (opt-in) for + `testAdaptiveWidgets`. +- feat: `setGoldenFileNameFactory` with `GoldenFileNameFactories.flat` + (default) and `GoldenFileNameFactories.nested`. +- feat: `setCustomDescribeValue` to customize test descriptions. +- feat: `setSkipGoldenAssertion` to skip adaptive tests conditionally. +- feat: `expectGolden(onDeviceSetup: ...)` hook. +- feat: `awaitImages` waits for images appearing after other images loaded + (`maxPasses`). +- fix: `ViewPaddingImpl` value equality, so identical `WindowConfigData` are + equal. +- chore: rename package to `adaptive_test_plus`. + `package:adaptive_test_plus/adaptive_test.dart` is kept as an alias entry + point. +- chore: widen `cupertino_icons` constraint to `>=1.0.5 <3.0.0` to allow cupertino_icons 2.x. +- chore: widen `equatable` constraint to `>=2.0.5 <4.0.0` to allow equatable 3.x. +- chore: widen `package_config` constraint to `>=2.1.0 <4.0.0` to allow package_config 3.x. + ## 0.10.4 - fix: catch flaky offstage widget finder errors in awaitImages diff --git a/LICENSE b/LICENSE index 31ac6ec..38f7d43 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License Copyright 2022 BAM +Copyright 2026 monawebapp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9a24721 --- /dev/null +++ b/Makefile @@ -0,0 +1,49 @@ +# Uses the FVM-pinned Flutter when FVM is installed, the global one otherwise. +# Override with e.g. `make test FLUTTER=flutter DART=dart`. +ifneq ($(shell command -v fvm 2>/dev/null),) +FLUTTER ?= fvm flutter +DART ?= fvm dart +else +FLUTTER ?= flutter +DART ?= dart +endif + +PACKAGES := . \ + example/simple_app \ + example/multi_packages_app/app \ + example/multi_packages_app/theme + +.PHONY: full-checks analyze test gen-golden deps + +## Run analyze then test on the package and all example apps. +full-checks: analyze test + +## Fetch dependencies for the package and all example apps. +deps: + @set -e; for pkg in $(PACKAGES); do \ + echo "==> pub get: $$pkg"; \ + (cd $$pkg && $(FLUTTER) pub get); \ + done + +## Check formatting and run the analyzer on the package and all example apps. +analyze: deps + @set -e; for pkg in $(PACKAGES); do \ + echo "==> format: $$pkg"; \ + (cd $$pkg && $(DART) format --set-exit-if-changed lib test); \ + echo "==> analyze: $$pkg"; \ + (cd $$pkg && $(FLUTTER) analyze --no-pub lib test); \ + done + +## Run the tests (including goldens) of the package and all example apps. +test: deps + @set -e; for pkg in $(PACKAGES); do \ + echo "==> test: $$pkg"; \ + (cd $$pkg && $(FLUTTER) test --no-pub --test-randomize-ordering-seed random); \ + done + +## Regenerate the golden files of the package and all example apps. +gen-golden: deps + @set -e; for pkg in $(PACKAGES); do \ + echo "==> update goldens: $$pkg"; \ + (cd $$pkg && $(FLUTTER) test --no-pub --update-goldens); \ + done diff --git a/README.md b/README.md index 091716d..147499e 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,28 @@ -# Adaptive Test +# Adaptive Test Plus -

- - logo - -
-

Devtools to write stunning widget test in Flutter.
Made by Theodo Apps ❤️💙💛.

-

+[![pub package](https://img.shields.io/pub/v/adaptive_test_plus.svg)](https://pub.dev/packages/adaptive_test_plus) -![Example](https://raw.githubusercontent.com/bamlab/adaptive_test/main/doc/example.png) +A maintained, **drop-in compatible** continuation of +[adaptive_test](https://pub.dev/packages/adaptive_test) by +[Theodo Apps](https://apps.theodo.com), with light/dark themed and localized +golden tests on top. + +![Example](https://raw.githubusercontent.com/monawebapp/adaptive_test_plus/main/doc/example.png) + +### Coming from `adaptive_test` + +Nothing else changes, golden file paths included: + +```diff + dev_dependencies: +- adaptive_test: ^0.10.4 ++ adaptive_test_plus: ^0.11.0 +``` + +```diff +-import 'package:adaptive_test/adaptive_test.dart'; ++import 'package:adaptive_test_plus/adaptive_test_plus.dart'; +``` ## Table of Contents 1. [Features](#features) @@ -19,6 +33,10 @@ - [Configuring Difference Threshold](#configuring-difference-threshold) - [Enforcing Test Platform](#enforcing-test-platform) - [Writing a Test](#writing-a-test) + - [Light and Dark Themes](#light-and-dark-themes) + - [Localized Goldens](#localized-goldens) + - [Golden File Names](#golden-file-names) + - [Skipping Goldens](#skipping-goldens) 4. [Migration Guide](#migration-guide) 5. [Additional Information](#additional-information) @@ -33,10 +51,13 @@ Use this package in your tests to: - Render a keyboard during tests - Set a preferred OS for running tests - Configure a difference tolerance threshold for file comparison +- Run every test in light and dark mode +- Run every test once per locale +- Customize golden file names and test descriptions ## Getting Started -1. Add `adaptive_test` to your dev dependencies. +1. Add `adaptive_test_plus` to your dev dependencies. 2. Create a `flutter_test_config.dart` file at the root of your `test` folder with a `testExecutable` function: @@ -161,8 +182,111 @@ void main() { } ``` +### Light and Dark Themes + +`testAdaptiveThemedWidgets` runs each configured device twice, as +`_light` and `_dark`. The platform brightness is set +accordingly, so apps using `ThemeMode.system` render both themes. The theme +mode is also available as `variant.themeMode`. + +```dart +testAdaptiveThemedWidgets( + 'Settings page', + (tester, variant) async { + await tester.pumpWidget( + AdaptiveWrapper( + windowConfig: variant, + tester: tester, + child: const App(), // MaterialApp(themeMode: ThemeMode.system, ...) + ), + ); + + await tester.expectGolden(variant); + }, +); +``` + +Single devices can be derived with `device.light()`, `device.dark()` or +`device.withThemeMode(mode)`. + +To make `testAdaptiveWidgets` apply the platform brightness of dark devices +such as `iPhone16Dark` too (off by default to keep existing goldens): + +```dart +AdaptiveTestConfiguration.instance.setApplyThemeModeToPlatformBrightness(true); +``` + +### Localized Goldens + +Run every test once per device and locale. The locale is applied to the test +platform dispatcher and appended to the golden name, e.g. +`preview/iPhone_16-app-de.png`: + +```dart +AdaptiveTestConfiguration.instance.setLocalizedDeviceVariants( + defaultDeviceConfigs, + AppLocalizations.supportedLocales, +); +``` + +Themed tests combine with it automatically. A single device can be localized +with `device.withLocale(const Locale('de'))`. + +### Golden File Names + +The default layout is unchanged: `preview/-[_].png`. +Switch layouts or provide your own: + +```dart +AdaptiveTestConfiguration.instance + // golden//[/][/].png + ..setGoldenFileNameFactory(GoldenFileNameFactories.nested) + // Test names shown in the runner + ..setCustomDescribeValue((config) => '${config.name} ${config.themeMode?.name}'); +``` + +`expectGolden` also accepts `onDeviceSetup`, called after images are loaded and +right before the comparison, for per-device tweaks: + +```dart +await tester.expectGolden( + variant, + onDeviceSetup: (tester, config) async { + await tester.drag(find.byType(ListView), const Offset(0, -300)); + await tester.pumpAndSettle(); + }, +); +``` + +### Skipping Goldens + +Skip all adaptive tests on machines that can't reproduce your references: + +```dart +AdaptiveTestConfiguration.instance + .setSkipGoldenAssertion(() => !Platform.isMacOS); +``` + ## Migration Guide +
+Migrating from adaptive_test_extended + +`adaptive_test_extended` features are available without its breaking changes: + +| adaptive_test_extended | adaptive_test_plus | +| --- | --- | +| `package:adaptive_test_extended/adaptive_test_extended.dart` | `package:adaptive_test_plus/adaptive_test_plus.dart` | +| `testAdaptiveThemedWidgets` | same | +| `setLocalizedDeviceVariants(devices, locales)` | same | +| `setCustomDescribeValue` | same | +| `setSkipGoldenChecker` (skipped off macOS by default) | `setSkipGoldenAssertion` (never skips by default) | +| `fileNameFactory = ...` | `setGoldenFileNameFactory(...)`, `GoldenFileNameFactories.nested` for the same layout | +| `expectGolden(onDeviceSetup: ...)` | same | +| `homeIndicator:` | `systemNavBar: SystemNavBarData.gestureIndicator(...)` | +| Device names `Desktop`, `Pixel_5` | `desktop`, `pixel_5`: rename or regenerate those goldens | +| Implicit `golden` tag | pass `tags: ['golden']` explicitly | +
Migrating to version 0.7.x @@ -219,12 +343,19 @@ Save this script as a `.sh` file and run it from your project root directory. ## Additional Information -We welcome feedback, issues, contributions, and suggestions! Feel free to contribute to the development of this package. +Issues and pull requests are welcome on +[GitHub](https://github.com/monawebapp/adaptive_test_plus/issues). -👉 About Theodo Apps +This package is based on [adaptive_test](https://github.com/bamlab/adaptive_test), +created by [Theodo Apps](https://apps.theodo.com) and released under the MIT +license. -We are a 130 people company developing and designing universal applications with React Native and Flutter using the Lean & Agile methodology. To get more information on the solutions that would suit your needs, feel free to get in touch by email or through or contact form! +### Contributing -We will always answer you with pleasure 😁 +The Flutter version used by CI and for the committed goldens is pinned in +`.fvmrc`. With [FVM](https://fvm.app), run `fvm install` once, then prefix +commands with `fvm` (`fvm flutter test`). FVM is optional: any Flutter version +matching the SDK constraints in `pubspec.yaml` works for development, but +goldens may differ slightly from the ones rendered with the pinned version. diff --git a/example/multi_packages_app/app/analysis_options.yaml b/example/multi_packages_app/app/analysis_options.yaml index 6517a43..abfedda 100644 --- a/example/multi_packages_app/app/analysis_options.yaml +++ b/example/multi_packages_app/app/analysis_options.yaml @@ -1,4 +1,8 @@ include: package:theodo_analysis/analysis_options.yaml +analyzer: + errors: + # theodo_analysis references DCM rules unknown to the Dart analyzer. + included_file_warning: ignore # Additional information about this file can be found at # https://pub.dev/packages/theodo_analysis linter: diff --git a/example/multi_packages_app/app/lib/main.dart b/example/multi_packages_app/app/lib/main.dart index bf0523b..4ff8a7b 100644 --- a/example/multi_packages_app/app/lib/main.dart +++ b/example/multi_packages_app/app/lib/main.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'src/app.dart'; +import 'package:multi_packages_example_app/src/app.dart'; void main() { runApp(const App()); diff --git a/example/multi_packages_app/app/lib/src/app.dart b/example/multi_packages_app/app/lib/src/app.dart index a3856cf..cbc18e6 100644 --- a/example/multi_packages_app/app/lib/src/app.dart +++ b/example/multi_packages_app/app/lib/src/app.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -import 'view/home.dart'; +import 'package:multi_packages_example_app/src/view/home.dart'; class App extends StatelessWidget { - const App({Key? key, this.themeMode}) : super(key: key); + const App({super.key, this.themeMode}); final ThemeMode? themeMode; @override diff --git a/example/multi_packages_app/app/lib/src/view/home.dart b/example/multi_packages_app/app/lib/src/view/home.dart index 2ece87f..1b9e13f 100644 --- a/example/multi_packages_app/app/lib/src/view/home.dart +++ b/example/multi_packages_app/app/lib/src/view/home.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:multi_packages_example_theme/main.dart'; class HomeLayout extends StatelessWidget { - const HomeLayout({Key? key}) : super(key: key); + const HomeLayout({super.key}); @override Widget build(BuildContext context) { diff --git a/example/multi_packages_app/app/pubspec.lock b/example/multi_packages_app/app/pubspec.lock index f5c0d3e..db59412 100644 --- a/example/multi_packages_app/app/pubspec.lock +++ b/example/multi_packages_app/app/pubspec.lock @@ -1,13 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - adaptive_test: + adaptive_test_plus: dependency: "direct dev" description: path: "../../.." relative: true source: path - version: "0.10.3" + version: "0.11.0" async: dependency: transitive description: @@ -28,10 +28,10 @@ packages: dependency: transitive description: name: characters - sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 url: "https://pub.dev" source: hosted - version: "1.4.1" + version: "1.4.0" clock: dependency: transitive description: @@ -118,18 +118,18 @@ packages: dependency: transitive description: name: matcher - sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 url: "https://pub.dev" source: hosted - version: "0.12.19" + version: "0.12.17" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.13.0" + version: "0.11.1" material_symbols_icons: dependency: transitive description: @@ -142,10 +142,10 @@ packages: dependency: transitive description: name: meta - sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.16.0" multi_packages_example_theme: dependency: "direct main" description: @@ -234,10 +234,10 @@ packages: dependency: transitive description: name: test_api - sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" + sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" url: "https://pub.dev" source: hosted - version: "0.7.10" + version: "0.7.6" theodo_analysis: dependency: "direct dev" description: @@ -263,5 +263,5 @@ packages: source: hosted version: "14.2.5" sdks: - dart: ">=3.9.0-0 <4.0.0" + dart: ">=3.8.0-0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/multi_packages_app/app/pubspec.yaml b/example/multi_packages_app/app/pubspec.yaml index 76841a7..910e3b3 100644 --- a/example/multi_packages_app/app/pubspec.yaml +++ b/example/multi_packages_app/app/pubspec.yaml @@ -1,5 +1,5 @@ name: multi_packages_example_app -description: A multi packages Flutter app to illustrate the package adaptive_test. This "multi_packages_app" package holds the app related code +description: A multi packages Flutter app to illustrate the package adaptive_test_plus. This "multi_packages_app" package holds the app related code publish_to: 'none' # Remove this line if you wish to publish to pub.dev @@ -9,18 +9,18 @@ environment: sdk: '>=3.0.5 <4.0.0' dependencies: + cupertino_icons: ^1.0.2 flutter: sdk: flutter - cupertino_icons: ^1.0.2 multi_packages_example_theme: path: '../theme' dev_dependencies: - flutter_test: - sdk: flutter - adaptive_test: + adaptive_test_plus: path: ../../../ + flutter_test: + sdk: flutter theodo_analysis: ^1.3.0 flutter: diff --git a/example/multi_packages_app/app/test/flutter_test_config.dart b/example/multi_packages_app/app/test/flutter_test_config.dart index ef7852f..6d780b0 100644 --- a/example/multi_packages_app/app/test/flutter_test_config.dart +++ b/example/multi_packages_app/app/test/flutter_test_config.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:adaptive_test/adaptive_test.dart'; +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/example/multi_packages_app/app/test/src/app_test.dart b/example/multi_packages_app/app/test/src/app_test.dart index 71301ad..82ba997 100644 --- a/example/multi_packages_app/app/test/src/app_test.dart +++ b/example/multi_packages_app/app/test/src/app_test.dart @@ -1,4 +1,4 @@ -import 'package:adaptive_test/adaptive_test.dart'; +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:multi_packages_example_app/src/app.dart'; diff --git a/example/multi_packages_app/app/test/src/preview/desktop-app_multi_packages.png b/example/multi_packages_app/app/test/src/preview/desktop-app_multi_packages.png index 2223309..a12504e 100644 Binary files a/example/multi_packages_app/app/test/src/preview/desktop-app_multi_packages.png and b/example/multi_packages_app/app/test/src/preview/desktop-app_multi_packages.png differ diff --git a/example/multi_packages_app/app/test/src/preview/desktop-app_multi_packages_with_keyboard.png b/example/multi_packages_app/app/test/src/preview/desktop-app_multi_packages_with_keyboard.png index 3440f8e..81845ce 100644 Binary files a/example/multi_packages_app/app/test/src/preview/desktop-app_multi_packages_with_keyboard.png and b/example/multi_packages_app/app/test/src/preview/desktop-app_multi_packages_with_keyboard.png differ diff --git a/example/multi_packages_app/app/test/src/preview/iPadPro-app_multi_packages.png b/example/multi_packages_app/app/test/src/preview/iPadPro-app_multi_packages.png index bd56588..82943a7 100644 Binary files a/example/multi_packages_app/app/test/src/preview/iPadPro-app_multi_packages.png and b/example/multi_packages_app/app/test/src/preview/iPadPro-app_multi_packages.png differ diff --git a/example/multi_packages_app/app/test/src/preview/iPadPro-app_multi_packages_with_keyboard.png b/example/multi_packages_app/app/test/src/preview/iPadPro-app_multi_packages_with_keyboard.png index 2b1a676..e1d070b 100644 Binary files a/example/multi_packages_app/app/test/src/preview/iPadPro-app_multi_packages_with_keyboard.png and b/example/multi_packages_app/app/test/src/preview/iPadPro-app_multi_packages_with_keyboard.png differ diff --git a/example/multi_packages_app/app/test/src/preview/iPhone_16-app_multi_packages.png b/example/multi_packages_app/app/test/src/preview/iPhone_16-app_multi_packages.png index 880506b..6e329ae 100644 Binary files a/example/multi_packages_app/app/test/src/preview/iPhone_16-app_multi_packages.png and b/example/multi_packages_app/app/test/src/preview/iPhone_16-app_multi_packages.png differ diff --git a/example/multi_packages_app/app/test/src/preview/iPhone_16-app_multi_packages_with_keyboard.png b/example/multi_packages_app/app/test/src/preview/iPhone_16-app_multi_packages_with_keyboard.png index 6bec36a..b2d0218 100644 Binary files a/example/multi_packages_app/app/test/src/preview/iPhone_16-app_multi_packages_with_keyboard.png and b/example/multi_packages_app/app/test/src/preview/iPhone_16-app_multi_packages_with_keyboard.png differ diff --git a/example/multi_packages_app/app/test/src/preview/iPhone_16_dark-app_multi_packages.png b/example/multi_packages_app/app/test/src/preview/iPhone_16_dark-app_multi_packages.png index 22dbd6f..bf277a6 100644 Binary files a/example/multi_packages_app/app/test/src/preview/iPhone_16_dark-app_multi_packages.png and b/example/multi_packages_app/app/test/src/preview/iPhone_16_dark-app_multi_packages.png differ diff --git a/example/multi_packages_app/app/test/src/preview/iPhone_16_dark-app_multi_packages_with_keyboard.png b/example/multi_packages_app/app/test/src/preview/iPhone_16_dark-app_multi_packages_with_keyboard.png index 1e07303..7fd68c7 100644 Binary files a/example/multi_packages_app/app/test/src/preview/iPhone_16_dark-app_multi_packages_with_keyboard.png and b/example/multi_packages_app/app/test/src/preview/iPhone_16_dark-app_multi_packages_with_keyboard.png differ diff --git a/example/multi_packages_app/app/test/src/preview/iPhone_8-app_multi_packages.png b/example/multi_packages_app/app/test/src/preview/iPhone_8-app_multi_packages.png index a4e8150..59b2d61 100644 Binary files a/example/multi_packages_app/app/test/src/preview/iPhone_8-app_multi_packages.png and b/example/multi_packages_app/app/test/src/preview/iPhone_8-app_multi_packages.png differ diff --git a/example/multi_packages_app/app/test/src/preview/iPhone_8-app_multi_packages_with_keyboard.png b/example/multi_packages_app/app/test/src/preview/iPhone_8-app_multi_packages_with_keyboard.png index ad47108..2b86223 100644 Binary files a/example/multi_packages_app/app/test/src/preview/iPhone_8-app_multi_packages_with_keyboard.png and b/example/multi_packages_app/app/test/src/preview/iPhone_8-app_multi_packages_with_keyboard.png differ diff --git a/example/multi_packages_app/app/test/src/preview/pixel_9-app_multi_packages.png b/example/multi_packages_app/app/test/src/preview/pixel_9-app_multi_packages.png index 71a0df2..b6cc5c1 100644 Binary files a/example/multi_packages_app/app/test/src/preview/pixel_9-app_multi_packages.png and b/example/multi_packages_app/app/test/src/preview/pixel_9-app_multi_packages.png differ diff --git a/example/multi_packages_app/app/test/src/preview/pixel_9-app_multi_packages_with_keyboard.png b/example/multi_packages_app/app/test/src/preview/pixel_9-app_multi_packages_with_keyboard.png index 2450405..7427dd5 100644 Binary files a/example/multi_packages_app/app/test/src/preview/pixel_9-app_multi_packages_with_keyboard.png and b/example/multi_packages_app/app/test/src/preview/pixel_9-app_multi_packages_with_keyboard.png differ diff --git a/example/multi_packages_app/theme/analysis_options.yaml b/example/multi_packages_app/theme/analysis_options.yaml index 6517a43..abfedda 100644 --- a/example/multi_packages_app/theme/analysis_options.yaml +++ b/example/multi_packages_app/theme/analysis_options.yaml @@ -1,4 +1,8 @@ include: package:theodo_analysis/analysis_options.yaml +analyzer: + errors: + # theodo_analysis references DCM rules unknown to the Dart analyzer. + included_file_warning: ignore # Additional information about this file can be found at # https://pub.dev/packages/theodo_analysis linter: diff --git a/example/multi_packages_app/theme/lib/main.dart b/example/multi_packages_app/theme/lib/main.dart index 928652b..b8a4943 100644 --- a/example/multi_packages_app/theme/lib/main.dart +++ b/example/multi_packages_app/theme/lib/main.dart @@ -1,3 +1,3 @@ +export './src/widgets/icon.dart'; export './src/widgets/text.dart'; export './src/widgets/text_field.dart'; -export './src/widgets/icon.dart'; diff --git a/example/multi_packages_app/theme/pubspec.lock b/example/multi_packages_app/theme/pubspec.lock index 2eb15f1..88e8101 100644 --- a/example/multi_packages_app/theme/pubspec.lock +++ b/example/multi_packages_app/theme/pubspec.lock @@ -1,13 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - adaptive_test: + adaptive_test_plus: dependency: "direct dev" description: path: "../../.." relative: true source: path - version: "0.10.3" + version: "0.11.0" async: dependency: transitive description: @@ -28,10 +28,10 @@ packages: dependency: transitive description: name: characters - sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 url: "https://pub.dev" source: hosted - version: "1.4.1" + version: "1.4.0" clock: dependency: transitive description: @@ -118,18 +118,18 @@ packages: dependency: transitive description: name: matcher - sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 url: "https://pub.dev" source: hosted - version: "0.12.19" + version: "0.12.17" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.13.0" + version: "0.11.1" material_symbols_icons: dependency: "direct main" description: @@ -142,10 +142,10 @@ packages: dependency: transitive description: name: meta - sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.16.0" package_config: dependency: transitive description: @@ -227,10 +227,10 @@ packages: dependency: transitive description: name: test_api - sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" + sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" url: "https://pub.dev" source: hosted - version: "0.7.10" + version: "0.7.6" theodo_analysis: dependency: "direct dev" description: @@ -256,5 +256,5 @@ packages: source: hosted version: "14.2.5" sdks: - dart: ">=3.9.0-0 <4.0.0" + dart: ">=3.8.0-0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/multi_packages_app/theme/pubspec.yaml b/example/multi_packages_app/theme/pubspec.yaml index 5c9c32b..a90c437 100644 --- a/example/multi_packages_app/theme/pubspec.yaml +++ b/example/multi_packages_app/theme/pubspec.yaml @@ -1,5 +1,5 @@ name: multi_packages_example_theme -description: A multi packages Flutter app to illustrate the package adaptive_test. This "multi_packages_theme" package holds the theme related code +description: A multi packages Flutter app to illustrate the package adaptive_test_plus. This "multi_packages_theme" package holds the theme related code publish_to: 'none' # Remove this line if you wish to publish to pub.dev @@ -9,17 +9,17 @@ environment: sdk: '>=3.0.5 <4.0.0' dependencies: + cupertino_icons: ^1.0.2 flutter: sdk: flutter - cupertino_icons: ^1.0.2 material_symbols_icons: ^4.2771.0 dev_dependencies: - flutter_test: - sdk: flutter - adaptive_test: + adaptive_test_plus: path: ../../../ + flutter_test: + sdk: flutter theodo_analysis: ^1.3.0 flutter: diff --git a/example/multi_packages_app/theme/test/flutter_test_config.dart b/example/multi_packages_app/theme/test/flutter_test_config.dart index d4d1c9d..2db4f76 100644 --- a/example/multi_packages_app/theme/test/flutter_test_config.dart +++ b/example/multi_packages_app/theme/test/flutter_test_config.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:adaptive_test/adaptive_test.dart'; +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/example/multi_packages_app/theme/test/src/text_test.dart b/example/multi_packages_app/theme/test/src/text_test.dart index e5b1004..328388e 100644 --- a/example/multi_packages_app/theme/test/src/text_test.dart +++ b/example/multi_packages_app/theme/test/src/text_test.dart @@ -1,4 +1,4 @@ -import 'package:adaptive_test/adaptive_test.dart'; +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:multi_packages_example_theme/src/widgets/text.dart'; diff --git a/example/simple_app/analysis_options.yaml b/example/simple_app/analysis_options.yaml index 6517a43..abfedda 100644 --- a/example/simple_app/analysis_options.yaml +++ b/example/simple_app/analysis_options.yaml @@ -1,4 +1,8 @@ include: package:theodo_analysis/analysis_options.yaml +analyzer: + errors: + # theodo_analysis references DCM rules unknown to the Dart analyzer. + included_file_warning: ignore # Additional information about this file can be found at # https://pub.dev/packages/theodo_analysis linter: diff --git a/example/simple_app/lib/src/showcase_app.dart b/example/simple_app/lib/src/showcase_app.dart new file mode 100644 index 0000000..3043cf1 --- /dev/null +++ b/example/simple_app/lib/src/showcase_app.dart @@ -0,0 +1,74 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; + +const showcaseLocales = [Locale('en'), Locale('de')]; + +const _strings = { + 'en': (title: 'Settings', notifications: 'Notifications', dark: 'Dark mode'), + 'de': ( + title: 'Einstellungen', + notifications: 'Benachrichtigungen', + dark: 'Dunkelmodus', + ), +}; + +/// App following the platform brightness and locale, used to showcase +/// `testAdaptiveThemedWidgets` and `setLocalizedDeviceVariants`. +class ShowcaseApp extends StatelessWidget { + const ShowcaseApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( + debugShowCheckedModeBanner: false, + themeMode: ThemeMode.system, + theme: ThemeData( + colorSchemeSeed: Colors.blue, + fontFamily: 'roboto', + ), + darkTheme: ThemeData( + colorSchemeSeed: Colors.blue, + brightness: Brightness.dark, + fontFamily: 'roboto', + ), + supportedLocales: showcaseLocales, + localizationsDelegates: GlobalMaterialLocalizations.delegates, + home: const _SettingsPage(), + ); + } +} + +class _SettingsPage extends StatelessWidget { + const _SettingsPage(); + + @override + Widget build(BuildContext context) { + final languageCode = Localizations.localeOf(context).languageCode; + final strings = _strings[languageCode] ?? _strings['en']!; + final isDark = Theme.of(context).brightness == Brightness.dark; + + return Scaffold( + appBar: AppBar(title: Text(strings.title)), + body: ListView( + children: [ + SwitchListTile( + value: true, + onChanged: (_) {}, + title: Text(strings.notifications), + secondary: const Icon(Icons.notifications), + ), + SwitchListTile( + value: isDark, + onChanged: (_) {}, + title: Text(strings.dark), + secondary: const Icon(Icons.dark_mode), + ), + ListTile( + leading: const Icon(Icons.language), + title: Text(languageCode.toUpperCase()), + ), + ], + ), + ); + } +} diff --git a/example/simple_app/pubspec.lock b/example/simple_app/pubspec.lock index aa29345..dc09b0e 100644 --- a/example/simple_app/pubspec.lock +++ b/example/simple_app/pubspec.lock @@ -1,13 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - adaptive_test: + adaptive_test_plus: dependency: "direct dev" description: path: "../.." relative: true source: path - version: "0.10.3" + version: "0.11.0" async: dependency: transitive description: @@ -28,10 +28,10 @@ packages: dependency: transitive description: name: characters - sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 url: "https://pub.dev" source: hosted - version: "1.4.1" + version: "1.4.0" clock: dependency: transitive description: @@ -85,11 +85,24 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + intl: + dependency: transitive + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" leak_tracker: dependency: transitive description: @@ -118,18 +131,18 @@ packages: dependency: transitive description: name: matcher - sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 url: "https://pub.dev" source: hosted - version: "0.12.19" + version: "0.12.17" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.13.0" + version: "0.11.1" material_symbols_icons: dependency: "direct main" description: @@ -142,10 +155,10 @@ packages: dependency: transitive description: name: meta - sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.16.0" package_config: dependency: transitive description: @@ -227,10 +240,10 @@ packages: dependency: transitive description: name: test_api - sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" + sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" url: "https://pub.dev" source: hosted - version: "0.7.10" + version: "0.7.6" theodo_analysis: dependency: "direct dev" description: @@ -256,5 +269,5 @@ packages: source: hosted version: "14.2.5" sdks: - dart: ">=3.9.0-0 <4.0.0" + dart: ">=3.8.0-0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/simple_app/pubspec.yaml b/example/simple_app/pubspec.yaml index b28a0df..a8690c1 100644 --- a/example/simple_app/pubspec.yaml +++ b/example/simple_app/pubspec.yaml @@ -1,5 +1,5 @@ name: simple_app_example -description: A simple Flutter app to illustrate the package adaptive_test. +description: A simple Flutter app to illustrate the package adaptive_test_plus. publish_to: 'none' # Remove this line if you wish to publish to pub.dev @@ -9,17 +9,19 @@ environment: sdk: '>=3.0.5 <4.0.0' dependencies: + cupertino_icons: ^1.0.2 flutter: sdk: flutter - cupertino_icons: ^1.0.2 + flutter_localizations: + sdk: flutter material_symbols_icons: ^4.2771.0 dev_dependencies: - flutter_test: - sdk: flutter - adaptive_test: + adaptive_test_plus: path: ../../ + flutter_test: + sdk: flutter theodo_analysis: ^1.3.0 flutter: diff --git a/example/simple_app/test/flutter_test_config.dart b/example/simple_app/test/flutter_test_config.dart index 866c904..c7dd4cf 100644 --- a/example/simple_app/test/flutter_test_config.dart +++ b/example/simple_app/test/flutter_test_config.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:adaptive_test/adaptive_test.dart'; +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -16,7 +16,7 @@ final defaultDeviceConfigs = { desktop, pixel9, pixel5ThreeButton, - pixel5TwoButton + pixel5TwoButton, }; Future testExecutable(FutureOr Function() testMain) async { diff --git a/example/simple_app/test/src/app_test.dart b/example/simple_app/test/src/app_test.dart index 3af43ff..9e725ec 100644 --- a/example/simple_app/test/src/app_test.dart +++ b/example/simple_app/test/src/app_test.dart @@ -1,4 +1,4 @@ -import 'package:adaptive_test/adaptive_test.dart'; +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:simple_app_example/src/app.dart'; diff --git a/example/simple_app/test/src/preview/custom_path_desktop.png b/example/simple_app/test/src/preview/custom_path_desktop.png index 166ffda..a12504e 100644 Binary files a/example/simple_app/test/src/preview/custom_path_desktop.png and b/example/simple_app/test/src/preview/custom_path_desktop.png differ diff --git a/example/simple_app/test/src/preview/custom_path_iPadPro.png b/example/simple_app/test/src/preview/custom_path_iPadPro.png index 034b058..82943a7 100644 Binary files a/example/simple_app/test/src/preview/custom_path_iPadPro.png and b/example/simple_app/test/src/preview/custom_path_iPadPro.png differ diff --git a/example/simple_app/test/src/preview/custom_path_iPhone_16.png b/example/simple_app/test/src/preview/custom_path_iPhone_16.png index 9997651..6e329ae 100644 Binary files a/example/simple_app/test/src/preview/custom_path_iPhone_16.png and b/example/simple_app/test/src/preview/custom_path_iPhone_16.png differ diff --git a/example/simple_app/test/src/preview/custom_path_iPhone_8.png b/example/simple_app/test/src/preview/custom_path_iPhone_8.png index e481e9f..59b2d61 100644 Binary files a/example/simple_app/test/src/preview/custom_path_iPhone_8.png and b/example/simple_app/test/src/preview/custom_path_iPhone_8.png differ diff --git a/example/simple_app/test/src/preview/custom_path_pixel_5_three_button.png b/example/simple_app/test/src/preview/custom_path_pixel_5_three_button.png index 4931dc2..9652200 100644 Binary files a/example/simple_app/test/src/preview/custom_path_pixel_5_three_button.png and b/example/simple_app/test/src/preview/custom_path_pixel_5_three_button.png differ diff --git a/example/simple_app/test/src/preview/custom_path_pixel_5_two_button.png b/example/simple_app/test/src/preview/custom_path_pixel_5_two_button.png index 6a123da..e8b41db 100644 Binary files a/example/simple_app/test/src/preview/custom_path_pixel_5_two_button.png and b/example/simple_app/test/src/preview/custom_path_pixel_5_two_button.png differ diff --git a/example/simple_app/test/src/preview/custom_path_pixel_9.png b/example/simple_app/test/src/preview/custom_path_pixel_9.png index 31aed53..b6cc5c1 100644 Binary files a/example/simple_app/test/src/preview/custom_path_pixel_9.png and b/example/simple_app/test/src/preview/custom_path_pixel_9.png differ diff --git a/example/simple_app/test/src/preview/desktop-app_fade_in_image.png b/example/simple_app/test/src/preview/desktop-app_fade_in_image.png index 166ffda..a12504e 100644 Binary files a/example/simple_app/test/src/preview/desktop-app_fade_in_image.png and b/example/simple_app/test/src/preview/desktop-app_fade_in_image.png differ diff --git a/example/simple_app/test/src/preview/desktop-app_simple.png b/example/simple_app/test/src/preview/desktop-app_simple.png index 166ffda..a12504e 100644 Binary files a/example/simple_app/test/src/preview/desktop-app_simple.png and b/example/simple_app/test/src/preview/desktop-app_simple.png differ diff --git a/example/simple_app/test/src/preview/desktop-app_simple_with_keyboard.png b/example/simple_app/test/src/preview/desktop-app_simple_with_keyboard.png index 85b5f58..81845ce 100644 Binary files a/example/simple_app/test/src/preview/desktop-app_simple_with_keyboard.png and b/example/simple_app/test/src/preview/desktop-app_simple_with_keyboard.png differ diff --git a/example/simple_app/test/src/preview/iPadPro-app_fade_in_image.png b/example/simple_app/test/src/preview/iPadPro-app_fade_in_image.png index 034b058..82943a7 100644 Binary files a/example/simple_app/test/src/preview/iPadPro-app_fade_in_image.png and b/example/simple_app/test/src/preview/iPadPro-app_fade_in_image.png differ diff --git a/example/simple_app/test/src/preview/iPadPro-app_simple.png b/example/simple_app/test/src/preview/iPadPro-app_simple.png index 034b058..82943a7 100644 Binary files a/example/simple_app/test/src/preview/iPadPro-app_simple.png and b/example/simple_app/test/src/preview/iPadPro-app_simple.png differ diff --git a/example/simple_app/test/src/preview/iPadPro-app_simple_with_keyboard.png b/example/simple_app/test/src/preview/iPadPro-app_simple_with_keyboard.png index eba251c..e1d070b 100644 Binary files a/example/simple_app/test/src/preview/iPadPro-app_simple_with_keyboard.png and b/example/simple_app/test/src/preview/iPadPro-app_simple_with_keyboard.png differ diff --git a/example/simple_app/test/src/preview/iPhone_16-app_fade_in_image.png b/example/simple_app/test/src/preview/iPhone_16-app_fade_in_image.png index 9997651..6e329ae 100644 Binary files a/example/simple_app/test/src/preview/iPhone_16-app_fade_in_image.png and b/example/simple_app/test/src/preview/iPhone_16-app_fade_in_image.png differ diff --git a/example/simple_app/test/src/preview/iPhone_16-app_simple.png b/example/simple_app/test/src/preview/iPhone_16-app_simple.png index 9997651..6e329ae 100644 Binary files a/example/simple_app/test/src/preview/iPhone_16-app_simple.png and b/example/simple_app/test/src/preview/iPhone_16-app_simple.png differ diff --git a/example/simple_app/test/src/preview/iPhone_16-app_simple_with_keyboard.png b/example/simple_app/test/src/preview/iPhone_16-app_simple_with_keyboard.png index e236318..b2d0218 100644 Binary files a/example/simple_app/test/src/preview/iPhone_16-app_simple_with_keyboard.png and b/example/simple_app/test/src/preview/iPhone_16-app_simple_with_keyboard.png differ diff --git a/example/simple_app/test/src/preview/iPhone_16_dark-showcase_app-de.png b/example/simple_app/test/src/preview/iPhone_16_dark-showcase_app-de.png new file mode 100644 index 0000000..398b813 Binary files /dev/null and b/example/simple_app/test/src/preview/iPhone_16_dark-showcase_app-de.png differ diff --git a/example/simple_app/test/src/preview/iPhone_16_dark-showcase_app-en.png b/example/simple_app/test/src/preview/iPhone_16_dark-showcase_app-en.png new file mode 100644 index 0000000..cc97072 Binary files /dev/null and b/example/simple_app/test/src/preview/iPhone_16_dark-showcase_app-en.png differ diff --git a/example/simple_app/test/src/preview/iPhone_16_light-showcase_app-de.png b/example/simple_app/test/src/preview/iPhone_16_light-showcase_app-de.png new file mode 100644 index 0000000..0db7fc6 Binary files /dev/null and b/example/simple_app/test/src/preview/iPhone_16_light-showcase_app-de.png differ diff --git a/example/simple_app/test/src/preview/iPhone_16_light-showcase_app-en.png b/example/simple_app/test/src/preview/iPhone_16_light-showcase_app-en.png new file mode 100644 index 0000000..8fd8d07 Binary files /dev/null and b/example/simple_app/test/src/preview/iPhone_16_light-showcase_app-en.png differ diff --git a/example/simple_app/test/src/preview/iPhone_8-app_fade_in_image.png b/example/simple_app/test/src/preview/iPhone_8-app_fade_in_image.png index e481e9f..59b2d61 100644 Binary files a/example/simple_app/test/src/preview/iPhone_8-app_fade_in_image.png and b/example/simple_app/test/src/preview/iPhone_8-app_fade_in_image.png differ diff --git a/example/simple_app/test/src/preview/iPhone_8-app_simple.png b/example/simple_app/test/src/preview/iPhone_8-app_simple.png index e481e9f..59b2d61 100644 Binary files a/example/simple_app/test/src/preview/iPhone_8-app_simple.png and b/example/simple_app/test/src/preview/iPhone_8-app_simple.png differ diff --git a/example/simple_app/test/src/preview/iPhone_8-app_simple_with_keyboard.png b/example/simple_app/test/src/preview/iPhone_8-app_simple_with_keyboard.png index 4a088be..2b86223 100644 Binary files a/example/simple_app/test/src/preview/iPhone_8-app_simple_with_keyboard.png and b/example/simple_app/test/src/preview/iPhone_8-app_simple_with_keyboard.png differ diff --git a/example/simple_app/test/src/preview/pixel_5_three_button-app_fade_in_image.png b/example/simple_app/test/src/preview/pixel_5_three_button-app_fade_in_image.png index 4931dc2..9652200 100644 Binary files a/example/simple_app/test/src/preview/pixel_5_three_button-app_fade_in_image.png and b/example/simple_app/test/src/preview/pixel_5_three_button-app_fade_in_image.png differ diff --git a/example/simple_app/test/src/preview/pixel_5_three_button-app_simple.png b/example/simple_app/test/src/preview/pixel_5_three_button-app_simple.png index 4931dc2..9652200 100644 Binary files a/example/simple_app/test/src/preview/pixel_5_three_button-app_simple.png and b/example/simple_app/test/src/preview/pixel_5_three_button-app_simple.png differ diff --git a/example/simple_app/test/src/preview/pixel_5_three_button-app_simple_with_keyboard.png b/example/simple_app/test/src/preview/pixel_5_three_button-app_simple_with_keyboard.png index f93bf7b..3f7abec 100644 Binary files a/example/simple_app/test/src/preview/pixel_5_three_button-app_simple_with_keyboard.png and b/example/simple_app/test/src/preview/pixel_5_three_button-app_simple_with_keyboard.png differ diff --git a/example/simple_app/test/src/preview/pixel_5_two_button-app_fade_in_image.png b/example/simple_app/test/src/preview/pixel_5_two_button-app_fade_in_image.png index 6a123da..e8b41db 100644 Binary files a/example/simple_app/test/src/preview/pixel_5_two_button-app_fade_in_image.png and b/example/simple_app/test/src/preview/pixel_5_two_button-app_fade_in_image.png differ diff --git a/example/simple_app/test/src/preview/pixel_5_two_button-app_simple.png b/example/simple_app/test/src/preview/pixel_5_two_button-app_simple.png index 6a123da..e8b41db 100644 Binary files a/example/simple_app/test/src/preview/pixel_5_two_button-app_simple.png and b/example/simple_app/test/src/preview/pixel_5_two_button-app_simple.png differ diff --git a/example/simple_app/test/src/preview/pixel_5_two_button-app_simple_with_keyboard.png b/example/simple_app/test/src/preview/pixel_5_two_button-app_simple_with_keyboard.png index 4795dbe..68d3319 100644 Binary files a/example/simple_app/test/src/preview/pixel_5_two_button-app_simple_with_keyboard.png and b/example/simple_app/test/src/preview/pixel_5_two_button-app_simple_with_keyboard.png differ diff --git a/example/simple_app/test/src/preview/pixel_9-app_fade_in_image.png b/example/simple_app/test/src/preview/pixel_9-app_fade_in_image.png index 31aed53..b6cc5c1 100644 Binary files a/example/simple_app/test/src/preview/pixel_9-app_fade_in_image.png and b/example/simple_app/test/src/preview/pixel_9-app_fade_in_image.png differ diff --git a/example/simple_app/test/src/preview/pixel_9-app_simple.png b/example/simple_app/test/src/preview/pixel_9-app_simple.png index 31aed53..b6cc5c1 100644 Binary files a/example/simple_app/test/src/preview/pixel_9-app_simple.png and b/example/simple_app/test/src/preview/pixel_9-app_simple.png differ diff --git a/example/simple_app/test/src/preview/pixel_9-app_simple_with_keyboard.png b/example/simple_app/test/src/preview/pixel_9-app_simple_with_keyboard.png index 629413e..7427dd5 100644 Binary files a/example/simple_app/test/src/preview/pixel_9-app_simple_with_keyboard.png and b/example/simple_app/test/src/preview/pixel_9-app_simple_with_keyboard.png differ diff --git a/example/simple_app/test/src/preview/pixel_9_dark-showcase_app-de.png b/example/simple_app/test/src/preview/pixel_9_dark-showcase_app-de.png new file mode 100644 index 0000000..3519b50 Binary files /dev/null and b/example/simple_app/test/src/preview/pixel_9_dark-showcase_app-de.png differ diff --git a/example/simple_app/test/src/preview/pixel_9_dark-showcase_app-en.png b/example/simple_app/test/src/preview/pixel_9_dark-showcase_app-en.png new file mode 100644 index 0000000..89161ea Binary files /dev/null and b/example/simple_app/test/src/preview/pixel_9_dark-showcase_app-en.png differ diff --git a/example/simple_app/test/src/preview/pixel_9_light-showcase_app-de.png b/example/simple_app/test/src/preview/pixel_9_light-showcase_app-de.png new file mode 100644 index 0000000..6e88c2e Binary files /dev/null and b/example/simple_app/test/src/preview/pixel_9_light-showcase_app-de.png differ diff --git a/example/simple_app/test/src/preview/pixel_9_light-showcase_app-en.png b/example/simple_app/test/src/preview/pixel_9_light-showcase_app-en.png new file mode 100644 index 0000000..4dbf2f9 Binary files /dev/null and b/example/simple_app/test/src/preview/pixel_9_light-showcase_app-en.png differ diff --git a/example/simple_app/test/src/showcase_test.dart b/example/simple_app/test/src/showcase_test.dart new file mode 100644 index 0000000..d81b714 --- /dev/null +++ b/example/simple_app/test/src/showcase_test.dart @@ -0,0 +1,31 @@ +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:simple_app_example/src/showcase_app.dart'; + +final _devices = {iPhone16, pixel9}; + +void main() { + group('Themed and localized goldens', () { + testAdaptiveThemedWidgets( + '$ShowcaseApp render', + (tester, variant) async { + await tester.pumpWidget( + AdaptiveWrapper( + windowConfig: variant, + tester: tester, + child: const ShowcaseApp(), + ), + ); + + await tester.expectGolden(variant); + }, + variantOverride: WindowVariant({ + for (final device in _devices) + for (final locale in showcaseLocales) ...[ + device.light().withLocale(locale), + device.dark().withLocale(locale), + ], + }), + ); + }); +} diff --git a/lib/adaptive_test.dart b/lib/adaptive_test.dart index 33a304e..5e84e67 100644 --- a/lib/adaptive_test.dart +++ b/lib/adaptive_test.dart @@ -1,15 +1,6 @@ -export 'src/adaptive/adaptive_test.dart'; -export 'src/adaptive/devices_data.dart'; -export 'src/adaptive/widgets/adaptive_wrapper.dart'; -export 'src/adaptive/window_configuration_tester.dart'; -export 'src/adaptive/window_config.dart'; -export 'src/configuration.dart'; -export 'src/helpers/await_images.dart'; -export 'src/helpers/fonts_loader.dart'; -export 'src/helpers/goldens_difference.dart'; -export 'src/helpers/skip_test_extension.dart'; -export 'src/adaptive/window_config_data/window_config_data.dart'; -export 'src/adaptive/window_config_data/system_nav_bar_data.dart' - show SystemNavBarData; -export 'src/adaptive/window_config_data/punch_hole_data.dart'; -export 'src/adaptive/window_config_data/dynamic_island_data.dart'; +/// Compatibility entry point mirroring `package:adaptive_test/adaptive_test.dart`. +/// +/// Prefer importing `package:adaptive_test_plus/adaptive_test_plus.dart`. +library; + +export 'adaptive_test_plus.dart'; diff --git a/lib/adaptive_test_plus.dart b/lib/adaptive_test_plus.dart new file mode 100644 index 0000000..fcd1c65 --- /dev/null +++ b/lib/adaptive_test_plus.dart @@ -0,0 +1,15 @@ +export 'src/adaptive/adaptive_test.dart'; +export 'src/adaptive/devices_data.dart'; +export 'src/adaptive/widgets/adaptive_wrapper.dart'; +export 'src/adaptive/window_config.dart'; +export 'src/adaptive/window_config_data/dynamic_island_data.dart'; +export 'src/adaptive/window_config_data/punch_hole_data.dart'; +export 'src/adaptive/window_config_data/system_nav_bar_data.dart' + show SystemNavBarData; +export 'src/adaptive/window_config_data/window_config_data.dart'; +export 'src/adaptive/window_configuration_tester.dart'; +export 'src/configuration.dart'; +export 'src/helpers/await_images.dart'; +export 'src/helpers/fonts_loader.dart'; +export 'src/helpers/goldens_difference.dart'; +export 'src/helpers/skip_test_extension.dart'; diff --git a/lib/src/adaptive/adaptive_test.dart b/lib/src/adaptive/adaptive_test.dart index 47f6f38..23cfd13 100644 --- a/lib/src/adaptive/adaptive_test.dart +++ b/lib/src/adaptive/adaptive_test.dart @@ -1,17 +1,16 @@ import 'dart:io'; -import 'package:adaptive_test/src/adaptive/widgets/adaptive_wrapper.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/window_config_data.dart'; -import 'package:adaptive_test/src/adaptive/window_configuration_tester.dart'; -import 'package:adaptive_test/src/configuration.dart'; -import 'package:adaptive_test/src/helpers/await_images.dart'; -import 'package:adaptive_test/src/helpers/skip_test_extension.dart'; -import 'package:adaptive_test/src/helpers/target_platform_extension.dart'; +import 'package:adaptive_test_plus/src/adaptive/widgets/adaptive_wrapper.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/window_config_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_configuration_tester.dart'; +import 'package:adaptive_test_plus/src/configuration.dart'; +import 'package:adaptive_test_plus/src/helpers/await_images.dart'; +import 'package:adaptive_test_plus/src/helpers/skip_test_extension.dart'; +import 'package:adaptive_test_plus/src/helpers/target_platform_extension.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:meta/meta.dart'; -import 'package:recase/recase.dart'; /// Type of [callback] that will be executed inside the Flutter test /// environment. @@ -40,25 +39,77 @@ void testAdaptiveWidgets( dynamic tags, }) { final configuration = AdaptiveTestConfiguration.instance; - final defaultVariant = configuration.deviceVariant; - final variant = variantOverride ?? defaultVariant; - final _skip = skip ?? configuration.shouldSkipTest; + _testAdaptiveWidgets( + description, + callback, + variant: variantOverride ?? configuration.deviceVariant, + applyBrightness: configuration.applyThemeModeToPlatformBrightness, + skip: skip, + timeout: timeout, + semanticsEnabled: semanticsEnabled, + tags: tags, + ); +} + +/// Same as [testAdaptiveWidgets], but runs every device of +/// [AdaptiveTestConfiguration.deviceVariant] twice: once in light mode and +/// once in dark mode (see [AdaptiveTestConfiguration.themedDeviceVariant]). +/// +/// The platform brightness follows [WindowConfigData.themeMode], so apps +/// using [ThemeMode.system] are rendered in both modes. The theme mode is +/// also available on the `windowConfig` passed to [callback]. +@isTest +void testAdaptiveThemedWidgets( + String description, + WidgetTesterAdaptiveCallback callback, { + bool? skip, + Timeout? timeout, + bool semanticsEnabled = true, + ValueVariant? variantOverride, + // ignore: avoid-dynamic, argument type of testWidgets + dynamic tags, +}) { + _testAdaptiveWidgets( + description, + callback, + variant: variantOverride ?? + AdaptiveTestConfiguration.instance.themedDeviceVariant, + applyBrightness: true, + skip: skip, + timeout: timeout, + semanticsEnabled: semanticsEnabled, + tags: tags, + ); +} +void _testAdaptiveWidgets( + String description, + WidgetTesterAdaptiveCallback callback, { + required ValueVariant variant, + required bool applyBrightness, + required bool? skip, + required Timeout? timeout, + required bool semanticsEnabled, + // ignore: avoid-dynamic, argument type of testWidgets + required dynamic tags, +}) { testWidgets( description, (tester) async { // ignore: avoid-non-null-assertion, will throw in test - debugDefaultTargetPlatformOverride = variant.currentValue!.targetPlatform; + final windowConfig = variant.currentValue!; + debugDefaultTargetPlatformOverride = windowConfig.targetPlatform; debugDisableShadows = false; - // ignore: avoid-non-null-assertion, will throw in test - tester.configureWindow(variant.currentValue!); - // ignore: avoid-non-null-assertion, will throw in test - await callback(tester, variant.currentValue!); + tester.configureWindow(windowConfig); + if (applyBrightness) { + tester.configurePlatformBrightness(windowConfig); + } + await callback(tester, windowConfig); debugDisableShadows = true; debugDefaultTargetPlatformOverride = null; }, - skip: _skip, + skip: skip ?? AdaptiveTestConfiguration.instance.shouldSkipTest, timeout: timeout, semanticsEnabled: semanticsEnabled, variant: variant, @@ -83,6 +134,9 @@ extension Adaptive on WidgetTester { /// By default, the path of the generated golden file is constructed as /// follows: /// `preview/${windowConfig.name}-${name.snakeCase}$localSuffix.png`. + /// For localized variants, `-` is appended before the extension. + /// The layout can be changed with + /// [AdaptiveTestConfiguration.setGoldenFileNameFactory]. /// If a [path] is provided, it will override this default behavior. /// /// The [byKey] argument allows the test to find the widget by its unique key, @@ -94,6 +148,9 @@ extension Adaptive on WidgetTester { /// Set [waitForImages] to `false` if you want to skip waiting for all images /// to load before taking the snapshot. By default, it waits for all images to /// load. + /// + /// [onDeviceSetup] runs right before the golden assertion, after images + /// are loaded. Use it for per-device adjustments such as scrolling. @isTest Future expectGolden( WindowConfigData windowConfig, { @@ -102,6 +159,8 @@ extension Adaptive on WidgetTester { Key? byKey, int? version, bool waitForImages = true, + Future Function(WidgetTester tester, WindowConfigData windowConfig)? + onDeviceSetup, }) async { final enforcedTestPlatform = AdaptiveTestConfiguration.instance.enforcedTestPlatform; @@ -113,15 +172,14 @@ extension Adaptive on WidgetTester { ); } - final localSuffix = suffix != null ? '_${ReCase(suffix).snakeCase}' : ''; - - final name = ReCase('$T'); if (waitForImages) { await awaitImages(); } + await onDeviceSetup?.call(this, windowConfig); final key = path ?? - 'preview/${windowConfig.name}-${name.snakeCase}$localSuffix.png'; + AdaptiveTestConfiguration.instance + .goldenFileNameFactory(windowConfig, T, suffix); await expectLater( // Find by its type except if the widget's unique key was given. byKey != null ? find.byKey(byKey) : find.byType(AdaptiveWrapper), diff --git a/lib/src/adaptive/devices_data.dart b/lib/src/adaptive/devices_data.dart index 74b3b44..404189d 100644 --- a/lib/src/adaptive/devices_data.dart +++ b/lib/src/adaptive/devices_data.dart @@ -1,9 +1,11 @@ -import 'package:adaptive_test/src/adaptive/window_config_data/dynamic_island_data.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/punch_hole_data.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/system_nav_bar_data.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/window_config_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/dynamic_island_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/punch_hole_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/system_nav_bar_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/window_config_data.dart'; import 'package:flutter/material.dart'; +// Names are used as golden file names, so they must not be renamed. +// ignore_for_file: constant_identifier_names enum _Device { iPhone_8, iPhone_13, @@ -18,7 +20,7 @@ enum _Device { String get keyboardName => 'assets/keyboards/$name.png'; } -const _keyboardPackage = 'adaptive_test'; +const _keyboardPackage = 'adaptive_test_plus'; /// [WindowConfigData] for an iPhone 8. final WindowConfigData iPhone8 = WindowConfigData( diff --git a/lib/src/adaptive/widgets/adaptive_wrapper.dart b/lib/src/adaptive/widgets/adaptive_wrapper.dart index a259f81..e34a0f9 100644 --- a/lib/src/adaptive/widgets/adaptive_wrapper.dart +++ b/lib/src/adaptive/widgets/adaptive_wrapper.dart @@ -1,8 +1,8 @@ -import 'package:adaptive_test/src/adaptive/widgets/layers/hardware_layer.dart'; -import 'package:adaptive_test/src/adaptive/widgets/layers/keyboard_layer.dart'; -import 'package:adaptive_test/src/adaptive/widgets/layers/system_nav_bar_layer.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/window_config_data.dart'; -import 'package:adaptive_test/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/widgets/layers/hardware_layer.dart'; +import 'package:adaptive_test_plus/src/adaptive/widgets/layers/keyboard_layer.dart'; +import 'package:adaptive_test_plus/src/adaptive/widgets/layers/system_nav_bar_layer.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/window_config_data.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/lib/src/adaptive/widgets/layers/gesture_indicator_system_nav_bar_layer.dart b/lib/src/adaptive/widgets/layers/gesture_indicator_system_nav_bar_layer.dart index 122d650..5ae3d03 100644 --- a/lib/src/adaptive/widgets/layers/gesture_indicator_system_nav_bar_layer.dart +++ b/lib/src/adaptive/widgets/layers/gesture_indicator_system_nav_bar_layer.dart @@ -1,5 +1,5 @@ -import 'package:adaptive_test/src/adaptive/window_config.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/system_nav_bar_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/system_nav_bar_data.dart'; import 'package:flutter/material.dart'; class GestureIndicatorSystemNavBarLayer extends StatelessWidget { diff --git a/lib/src/adaptive/widgets/layers/hardware_layer.dart b/lib/src/adaptive/widgets/layers/hardware_layer.dart index 37743e2..add5cf2 100644 --- a/lib/src/adaptive/widgets/layers/hardware_layer.dart +++ b/lib/src/adaptive/widgets/layers/hardware_layer.dart @@ -1,4 +1,4 @@ -import 'package:adaptive_test/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config.dart'; import 'package:flutter/material.dart'; /// Widget wrapper that paint hardware elements over a child. diff --git a/lib/src/adaptive/widgets/layers/keyboard_layer.dart b/lib/src/adaptive/widgets/layers/keyboard_layer.dart index b5d832e..e167c94 100644 --- a/lib/src/adaptive/widgets/layers/keyboard_layer.dart +++ b/lib/src/adaptive/widgets/layers/keyboard_layer.dart @@ -1,5 +1,5 @@ -import 'package:adaptive_test/src/adaptive/window_configuration_tester.dart'; -import 'package:adaptive_test/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_configuration_tester.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/lib/src/adaptive/widgets/layers/system_nav_bar_layer.dart b/lib/src/adaptive/widgets/layers/system_nav_bar_layer.dart index c36a0c1..5093840 100644 --- a/lib/src/adaptive/widgets/layers/system_nav_bar_layer.dart +++ b/lib/src/adaptive/widgets/layers/system_nav_bar_layer.dart @@ -1,8 +1,8 @@ -import 'package:adaptive_test/src/adaptive/widgets/layers/gesture_indicator_system_nav_bar_layer.dart'; -import 'package:adaptive_test/src/adaptive/widgets/layers/three_button_system_nav_bar_layer.dart'; -import 'package:adaptive_test/src/adaptive/widgets/layers/two_button_system_nav_bar_layer.dart'; -import 'package:adaptive_test/src/adaptive/window_config.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/system_nav_bar_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/widgets/layers/gesture_indicator_system_nav_bar_layer.dart'; +import 'package:adaptive_test_plus/src/adaptive/widgets/layers/three_button_system_nav_bar_layer.dart'; +import 'package:adaptive_test_plus/src/adaptive/widgets/layers/two_button_system_nav_bar_layer.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/system_nav_bar_data.dart'; import 'package:flutter/material.dart'; class SystemNavBarLayer extends StatelessWidget { diff --git a/lib/src/adaptive/widgets/layers/three_button_system_nav_bar_layer.dart b/lib/src/adaptive/widgets/layers/three_button_system_nav_bar_layer.dart index 53c2134..f1c196d 100644 --- a/lib/src/adaptive/widgets/layers/three_button_system_nav_bar_layer.dart +++ b/lib/src/adaptive/widgets/layers/three_button_system_nav_bar_layer.dart @@ -1,5 +1,5 @@ -import 'package:adaptive_test/src/adaptive/window_config.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/system_nav_bar_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/system_nav_bar_data.dart'; import 'package:flutter/material.dart'; class ThreeButtonSystemNavBarLayer extends StatelessWidget { @@ -32,7 +32,7 @@ class ThreeButtonSystemNavBarLayer extends StatelessWidget { children: const [ Icons.arrow_back_ios_rounded, Icons.circle, - Icons.square_rounded + Icons.square_rounded, ] .map( (iconData) => Icon( diff --git a/lib/src/adaptive/widgets/layers/two_button_system_nav_bar_layer.dart b/lib/src/adaptive/widgets/layers/two_button_system_nav_bar_layer.dart index 01227b4..269f2da 100644 --- a/lib/src/adaptive/widgets/layers/two_button_system_nav_bar_layer.dart +++ b/lib/src/adaptive/widgets/layers/two_button_system_nav_bar_layer.dart @@ -1,5 +1,5 @@ -import 'package:adaptive_test/src/adaptive/window_config.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/system_nav_bar_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/system_nav_bar_data.dart'; import 'package:flutter/material.dart'; class TwoButtonSystemNavBarLayer extends StatelessWidget { diff --git a/lib/src/adaptive/window_config.dart b/lib/src/adaptive/window_config.dart index f3017eb..d26d94d 100644 --- a/lib/src/adaptive/window_config.dart +++ b/lib/src/adaptive/window_config.dart @@ -1,4 +1,5 @@ -import 'package:adaptive_test/src/adaptive/window_config_data/window_config_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/window_config_data.dart'; +import 'package:adaptive_test_plus/src/configuration.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -8,7 +9,8 @@ class WindowVariant extends ValueVariant { final Set windowConfigs; @override - String describeValue(WindowConfigData value) => value.name; + String describeValue(WindowConfigData value) => + AdaptiveTestConfiguration.instance.describeValue(value); } /// Establish a subtree in which adaptive window resolves to the given data. diff --git a/lib/src/adaptive/window_config_data/window_config_data.dart b/lib/src/adaptive/window_config_data/window_config_data.dart index 02253c1..1632400 100644 --- a/lib/src/adaptive/window_config_data/window_config_data.dart +++ b/lib/src/adaptive/window_config_data/window_config_data.dart @@ -1,6 +1,6 @@ -import 'package:adaptive_test/src/adaptive/window_config_data/dynamic_island_data.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/punch_hole_data.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/system_nav_bar_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/dynamic_island_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/punch_hole_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/system_nav_bar_data.dart'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -22,6 +22,7 @@ class WindowConfigData extends Equatable { this.punchHole, this.systemNavBar, this.themeMode = ThemeMode.light, + this.locale, }) : viewInsets = ViewPaddingImpl( bottom: keyboardSize?.height ?? 0, ) * @@ -53,7 +54,8 @@ class WindowConfigData extends Equatable { /// This is null when the device has no notch. final Size? notchSize; - /// Describe the size of the device physical screen top dynamic island in `dp`. + /// Describe the size of the device physical screen top dynamic island in + /// `dp`. /// /// This is null when the device has no dynamic island. final DynamicIslandData? dynamicIsland; @@ -74,6 +76,11 @@ class WindowConfigData extends Equatable { /// This is null when the device has no theme mode. final ThemeMode? themeMode; + /// Locale applied to the test platform dispatcher while the test runs. + /// + /// This is null when the device keeps the default test locale. + final Locale? locale; + /// Device Platform. /// /// See: [TargetPlatform] @@ -121,6 +128,7 @@ class WindowConfigData extends Equatable { keyboardName, keyboardPackage, dynamicIsland, + locale, ]; WindowConfigData copyWith({ @@ -138,6 +146,7 @@ class WindowConfigData extends Equatable { PunchHoleData? punchHole, SystemNavBarData? systemNavBar, ThemeMode? themeMode, + Locale? locale, }) { final newDensity = pixelDensity ?? this.pixelDensity; @@ -160,12 +169,38 @@ class WindowConfigData extends Equatable { punchHole: punchHole ?? this.punchHole, systemNavBar: systemNavBar ?? this.systemNavBar, themeMode: themeMode ?? this.themeMode, + locale: locale ?? this.locale, + ); + } + + /// Returns a light variant of this device, suffixing its [name] with + /// `_light`. + WindowConfigData light() => withThemeMode(ThemeMode.light); + + /// Returns a dark variant of this device, suffixing its [name] with `_dark`. + WindowConfigData dark() => withThemeMode(ThemeMode.dark); + + /// Returns a copy of this device using [themeMode], suffixing its [name] + /// with the theme mode name so golden files and test descriptions stay + /// unique. + WindowConfigData withThemeMode(ThemeMode themeMode) { + final suffix = '_${themeMode.name}'; + + return copyWith( + name: name.endsWith(suffix) ? name : '$name$suffix', + themeMode: themeMode, ); } + + /// Returns a copy of this device using [locale]. + /// + /// The [name] is kept as is: the locale is appended to the golden file name + /// and to the test description by `AdaptiveTestConfiguration`. + WindowConfigData withLocale(Locale locale) => copyWith(locale: locale); } /// Implementation of the abstract class [FakeViewPadding]. -class ViewPaddingImpl implements FakeViewPadding { +class ViewPaddingImpl extends Equatable implements FakeViewPadding { const ViewPaddingImpl({ this.bottom = 0, this.top = 0, @@ -198,6 +233,9 @@ class ViewPaddingImpl implements FakeViewPadding { left: left * operand, right: right * operand, ); + + @override + List get props => [bottom, top, left, right]; } extension FakeViewPaddingX on FakeViewPadding { diff --git a/lib/src/adaptive/window_configuration_tester.dart b/lib/src/adaptive/window_configuration_tester.dart index eaba821..052636b 100644 --- a/lib/src/adaptive/window_configuration_tester.dart +++ b/lib/src/adaptive/window_configuration_tester.dart @@ -1,4 +1,5 @@ -import 'package:adaptive_test/src/adaptive/window_config_data/window_config_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/window_config_data.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; /// Dart extension to add configuration functions to a [WidgetTester] object, @@ -17,15 +18,41 @@ extension WidgetTesterWithConfigurableWindow on WidgetTester { addTearDown(view.resetDevicePixelRatio); addTearDown(view.resetPhysicalSize); addTearDown(view.resetViewInsets); + + final locale = windowConfig.locale; + if (locale != null) { + platformDispatcher + ..localeTestValue = locale + ..localesTestValue = [locale]; + addTearDown(platformDispatcher.clearLocaleTestValue); + addTearDown(platformDispatcher.clearLocalesTestValue); + } + } + + /// Sets the platform brightness from [WindowConfigData.themeMode]. + /// + /// [ThemeMode.system] (or null) keeps the current platform brightness. + void configurePlatformBrightness(WindowConfigData windowConfig) { + final brightness = switch (windowConfig.themeMode) { + ThemeMode.dark => Brightness.dark, + ThemeMode.light => Brightness.light, + ThemeMode.system || null => null, + }; + if (brightness == null) return; + + platformDispatcher.platformBrightnessTestValue = brightness; + addTearDown(platformDispatcher.clearPlatformBrightnessTestValue); } - /// Configure the tester window to represent an opened keyboard on the given device variant. + /// Configure the tester window to represent an opened keyboard on the given + /// device variant. void configureOpenedKeyboardWindow(WindowConfigData windowConfig) { view.viewInsets = windowConfig.viewInsets; view.padding = windowConfig.padding.copyWith(bottom: 0); } - /// Configure the tester window to represent a closed keyboard on the given device variant. + /// Configure the tester window to represent a closed keyboard on the given + /// device variant. void configureClosedKeyboardWindow(WindowConfigData windowConfig) { view.resetViewInsets(); view.padding = windowConfig.padding; diff --git a/lib/src/configuration.dart b/lib/src/configuration.dart index 11b7f4d..cdfd36a 100644 --- a/lib/src/configuration.dart +++ b/lib/src/configuration.dart @@ -1,12 +1,81 @@ -import 'package:adaptive_test/src/adaptive/window_config.dart'; -import 'package:adaptive_test/src/adaptive/window_config_data/window_config_data.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config.dart'; +import 'package:adaptive_test_plus/src/adaptive/window_config_data/window_config_data.dart'; import 'package:flutter/material.dart'; +import 'package:recase/recase.dart'; + +/// Builds the golden file path used by `expectGolden` when no explicit `path` +/// is given. +typedef GoldenFileNameFactory = String Function( + WindowConfigData windowConfig, + Type widgetType, + String? suffix, +); + +/// Builds the description of a [WindowConfigData] variant, displayed in the +/// test name. +typedef WindowConfigDescriber = String Function(WindowConfigData windowConfig); + +/// Returns true when golden tests should be skipped, e.g. on CI machines that +/// cannot reproduce the reference rendering. +typedef SkipGoldenAssertion = bool Function(); + +/// Ready-made [GoldenFileNameFactory] implementations. +abstract final class GoldenFileNameFactories { + /// Default layout, identical to `adaptive_test`: + /// `preview/-[_][-].png`. + /// + /// The locale part is only added for localized variants. + static String flat( + WindowConfigData windowConfig, + Type widgetType, + String? suffix, + ) { + final localSuffix = suffix != null ? '_${ReCase(suffix).snakeCase}' : ''; + final locale = windowConfig.locale; + final localeSuffix = locale != null ? '-${localeTag(locale)}' : ''; + final widgetName = ReCase('$widgetType').snakeCase; + + return 'preview/${windowConfig.name}-$widgetName' + '$localSuffix$localeSuffix.png'; + } + + /// Nested layout, as introduced by `adaptive_test_extended`: + /// `golden//[/][/].png`. + static String nested( + WindowConfigData windowConfig, + Type widgetType, + String? suffix, + ) { + final locale = windowConfig.locale; + + return [ + 'golden', + ReCase('$widgetType').snakeCase, + if (suffix != null && suffix.isNotEmpty) ReCase(suffix).snakeCase, + if (locale != null) localeTag(locale), + '${windowConfig.name}.png', + ].join('/'); + } + + /// File-system friendly locale tag, e.g. `en`, `pt_BR`. + static String localeTag(Locale locale) => + locale.toLanguageTag().replaceAll('-', '_'); +} + +String _defaultDescribe(WindowConfigData windowConfig) { + final locale = windowConfig.locale; + + return locale == null + ? windowConfig.name + : '${windowConfig.name}-${GoldenFileNameFactories.localeTag(locale)}'; +} /// Singleton class that configures global variables for the test. /// /// Notably: /// * `enforcedTestPlatform`, see [TargetPlatform]. /// * `deviceVariant`, see [WindowVariant] and [WindowConfigData]. +/// * `themedDeviceVariant`, light and dark copies of `deviceVariant`. /// /// Configure those variables in the [testExecutable] function inside the /// `flutter_test_config.dart` file. @@ -28,6 +97,7 @@ class AdaptiveTestConfiguration { /// /// Eg [TargetPlatform.linux], [TargetPlatform.macOS], /// [TargetPlatform.windows]. + // ignore: use_setters_to_change_properties void setEnforcedTestPlatform(TargetPlatform enforcedTestPlatform) { _enforcedTestPlatform = enforcedTestPlatform; } @@ -42,11 +112,63 @@ class AdaptiveTestConfiguration { /// /// Setting [failTestOnWrongPlatform] to false will skip the test instead of /// failing it. + // ignore: use_setters_to_change_properties void setFailTestOnWrongPlatform(bool failTestOnWrongPlatform) { _failTestOnWrongPlatform = failTestOnWrongPlatform; } + SkipGoldenAssertion? _skipGoldenAssertion; + + SkipGoldenAssertion? get skipGoldenAssertion => _skipGoldenAssertion; + + /// Skips every adaptive test whenever [callback] returns true. + /// + /// Evaluated when tests are declared. Defaults to never skipping. + // ignore: use_setters_to_change_properties + void setSkipGoldenAssertion(SkipGoldenAssertion? callback) { + _skipGoldenAssertion = callback; + } + + bool _applyThemeModeToPlatformBrightness = false; + + bool get applyThemeModeToPlatformBrightness => + _applyThemeModeToPlatformBrightness; + + /// When true, `testAdaptiveWidgets` sets the platform brightness from + /// [WindowConfigData.themeMode], so apps using [ThemeMode.system] render + /// dark on dark devices. + /// + /// Defaults to false to keep existing goldens unchanged. + /// `testAdaptiveThemedWidgets` always applies it. + // ignore: use_setters_to_change_properties + void setApplyThemeModeToPlatformBrightness(bool value) { + _applyThemeModeToPlatformBrightness = value; + } + + GoldenFileNameFactory _goldenFileNameFactory = GoldenFileNameFactories.flat; + + GoldenFileNameFactory get goldenFileNameFactory => _goldenFileNameFactory; + + /// Overrides how `expectGolden` names golden files when no `path` is given. + /// + /// See [GoldenFileNameFactories]. + // ignore: use_setters_to_change_properties + void setGoldenFileNameFactory(GoldenFileNameFactory factory) { + _goldenFileNameFactory = factory; + } + + WindowConfigDescriber _describeValue = _defaultDescribe; + + WindowConfigDescriber get describeValue => _describeValue; + + /// Overrides how a variant is described in test names. + // ignore: use_setters_to_change_properties + void setCustomDescribeValue(WindowConfigDescriber describer) { + _describeValue = describer; + } + WindowVariant? _deviceVariant; + WindowVariant? _themedDeviceVariant; WindowVariant get deviceVariant { final scopedDeviceVariant = _deviceVariant; @@ -63,10 +185,49 @@ See: https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html return scopedDeviceVariant; } + /// Light and dark copies of every device of [deviceVariant], used by + /// `testAdaptiveThemedWidgets`. + WindowVariant get themedDeviceVariant => + _themedDeviceVariant ??= WindowVariant({ + for (final config in deviceVariant.windowConfigs) ...[ + config.light(), + config.dark(), + ], + }); + /// Set the devices variant on which you want your test to run. /// - /// Eg [iPhone8], [iPhone13], [iPhone16],[iPhone16Dark], [iPadPro], [desktop], [pixel5], [pixel9]. + /// Eg [iPhone8], [iPhone13], [iPhone16], [iPhone16Dark], [iPadPro], + /// [desktop], [pixel5], [pixel9]. void setDeviceVariants(Set deviceConfigs) { _deviceVariant = WindowVariant(deviceConfigs); + _themedDeviceVariant = null; + } + + /// Set the devices variant, run once per device and per locale. + /// + /// The locale is applied to the test platform dispatcher, and appended to + /// golden file names and test descriptions. + void setLocalizedDeviceVariants( + Set deviceConfigs, + Iterable locales, + ) { + setDeviceVariants({ + for (final config in deviceConfigs) + for (final locale in locales) config.withLocale(locale), + }); + } + + /// Restores every setting to its default value. Useful in tests. + @visibleForTesting + void reset() { + _enforcedTestPlatform = null; + _failTestOnWrongPlatform = true; + _skipGoldenAssertion = null; + _applyThemeModeToPlatformBrightness = false; + _goldenFileNameFactory = GoldenFileNameFactories.flat; + _describeValue = _defaultDescribe; + _deviceVariant = null; + _themedDeviceVariant = null; } } diff --git a/lib/src/helpers/await_images.dart b/lib/src/helpers/await_images.dart index 8cfdcda..9bb0ed7 100644 --- a/lib/src/helpers/await_images.dart +++ b/lib/src/helpers/await_images.dart @@ -9,7 +9,35 @@ import 'package:flutter_test/flutter_test.dart'; /// e.g. [awaitImages]; extension AwaitImages on WidgetTester { /// Pauses test until images are ready to be rendered. - Future awaitImages() async { + /// + /// Images that only appear once other images are loaded (e.g. after a + /// placeholder) are awaited too: the lookup is repeated while new images + /// show up, at most [maxPasses] times. + Future awaitImages({int maxPasses = 3}) async { + final awaited = {}; + for (var pass = 0; pass < maxPasses; pass++) { + final elements = _imageElements(); + if (pass > 0 && elements.every(awaited.contains)) { + return; + } + awaited.addAll(elements); + await _awaitImagesOnce(); + } + } + + List _imageElements() { + try { + return [ + ...find.byType(Image, skipOffstage: false).evaluate(), + ...find.byType(FadeInImage, skipOffstage: false).evaluate(), + ...find.byType(DecoratedBox, skipOffstage: false).evaluate(), + ]; + } catch (_) { + return const []; + } + } + + Future _awaitImagesOnce() async { await runAsync(() async { for (final element in find.byType(Image, skipOffstage: false).evaluate().toList()) { diff --git a/lib/src/helpers/fonts_loader.dart b/lib/src/helpers/fonts_loader.dart index a743bce..03545a0 100644 --- a/lib/src/helpers/fonts_loader.dart +++ b/lib/src/helpers/fonts_loader.dart @@ -50,9 +50,9 @@ Future _loadFontsFromManifest( FontLoader _createFontLoader(String fontFamily, List<_FontType> fontTypes) { final fontLoader = FontLoader(fontFamily); - fontTypes.forEach( - (fontType) => fontLoader.addFont(rootBundle.load(fontType.asset)), - ); + for (final fontType in fontTypes) { + fontLoader.addFont(rootBundle.load(fontType.asset)); + } return fontLoader; } diff --git a/lib/src/helpers/goldens_difference.dart b/lib/src/helpers/goldens_difference.dart index 8b5f500..19824e6 100644 --- a/lib/src/helpers/goldens_difference.dart +++ b/lib/src/helpers/goldens_difference.dart @@ -36,7 +36,10 @@ void setupFileComparatorWithThreshold([ /// exceeded, marks the test as a failure. class LocalFileComparatorWithThreshold extends LocalFileComparator { LocalFileComparatorWithThreshold(super.testFile, this.threshold) - : assert(threshold >= 0 && threshold <= 1); + : assert( + threshold >= 0 && threshold <= 1, + 'threshold must be between 0 and 1', + ); /// Threshold above which tests will be marked as failing. /// Ranges from 0 to 1, both inclusive. diff --git a/lib/src/helpers/skip_test_extension.dart b/lib/src/helpers/skip_test_extension.dart index 6deb121..e583084 100644 --- a/lib/src/helpers/skip_test_extension.dart +++ b/lib/src/helpers/skip_test_extension.dart @@ -1,5 +1,5 @@ -import 'package:adaptive_test/adaptive_test.dart'; -import 'package:adaptive_test/src/helpers/target_platform_extension.dart'; +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; +import 'package:adaptive_test_plus/src/helpers/target_platform_extension.dart'; /// Extension on [AdaptiveTestConfiguration] to determine if a test should be /// skipped based on the [AdaptiveTestConfiguration.enforcedTestPlatform] and @@ -9,11 +9,18 @@ extension ShouldSkipAdaptiveTest on AdaptiveTestConfiguration { /// runtime platform does not match the enforced platform, the test will be /// skipped if [AdaptiveTestConfiguration.failTestOnWrongPlatform] is false. /// - /// This extension is used to determine if a test should be skipped based on the - /// [AdaptiveTestConfiguration.enforcedTestPlatform] and + /// This extension is used to determine if a test should be skipped based on + /// the [AdaptiveTestConfiguration.enforcedTestPlatform] and /// [AdaptiveTestConfiguration.failTestOnWrongPlatform] values. + /// + /// Tests are always skipped when + /// [AdaptiveTestConfiguration.skipGoldenAssertion] returns true. bool get shouldSkipTest { final configuration = AdaptiveTestConfiguration.instance; + if (configuration.skipGoldenAssertion?.call() ?? false) { + return true; + } + final enforcedTestPlatform = configuration.enforcedTestPlatform; if (enforcedTestPlatform != null && diff --git a/lib/src/helpers/target_platform_extension.dart b/lib/src/helpers/target_platform_extension.dart index fbc72d9..7f1df6e 100644 --- a/lib/src/helpers/target_platform_extension.dart +++ b/lib/src/helpers/target_platform_extension.dart @@ -2,7 +2,6 @@ import 'dart:developer'; import 'dart:io'; import 'package:flutter/foundation.dart'; -import 'package:meta/meta.dart'; @internal extension IsRuntimePlatform on TargetPlatform { @@ -13,7 +12,9 @@ extension IsRuntimePlatform on TargetPlatform { TargetPlatform.windows: return; - default: + case TargetPlatform.android || + TargetPlatform.fuchsia || + TargetPlatform.iOS: log('Tests are intended to be runned on linux, macOS or windows' ' platform. But you are running them on $name'); } diff --git a/pubspec.yaml b/pubspec.yaml index 6fca261..052b41a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,24 +1,31 @@ -name: adaptive_test +name: adaptive_test_plus description: >- - A Flutter package to generate adaptive golden files during widget tests. -version: 0.10.4 -homepage: https://github.com/bamlab/adaptive_test -repository: https://github.com/bamlab/adaptive_test + Adaptive golden tests for Flutter: devices, light/dark themes and locales. + A maintained, drop-in compatible continuation of adaptive_test. +issue_tracker: https://github.com/monawebapp/adaptive_test_plus/issues +topics: + - testing + - golden + - widget-test + - screenshot +version: 0.11.0 +homepage: https://github.com/monawebapp/adaptive_test_plus +repository: https://github.com/monawebapp/adaptive_test_plus environment: sdk: '>=3.0.5 <4.0.0' flutter: '>=1.17.0' dependencies: - cupertino_icons: ^1.0.5 - equatable: ^2.0.5 + cupertino_icons: '>=1.0.5 <3.0.0' + equatable: '>=2.0.5 <4.0.0' file: ^7.0.0 flutter: sdk: flutter flutter_test: sdk: flutter meta: ^1.8.0 - package_config: ^2.1.0 + package_config: '>=2.1.0 <4.0.0' path: ^1.8.2 platform: ^3.1.0 recase: ^4.0.0 diff --git a/test/adaptive_test_test.dart b/test/adaptive_test_test.dart deleted file mode 100644 index 73c34cf..0000000 --- a/test/adaptive_test_test.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; - -void main() { - test('true isTrue', () { - expect(true, isTrue); - }); -} diff --git a/test/adaptive_test_widgets_test.dart b/test/adaptive_test_widgets_test.dart new file mode 100644 index 0000000..68afd1d --- /dev/null +++ b/test/adaptive_test_widgets_test.dart @@ -0,0 +1,46 @@ +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + final configuration = AdaptiveTestConfiguration.instance + ..setLocalizedDeviceVariants( + {iPhone8, desktop}, + const [Locale('en'), Locale('ar')], + ); + + testAdaptiveWidgets( + 'applies size and locale', + (tester, variant) async { + final view = tester.view; + expect(view.physicalSize, variant.physicalSize); + expect(view.devicePixelRatio, variant.pixelDensity); + expect(tester.platformDispatcher.locale, variant.locale); + expect(tester.platformDispatcher.platformBrightness, Brightness.light); + }, + ); + + testAdaptiveThemedWidgets( + 'applies platform brightness', + (tester, variant) async { + final expected = variant.themeMode == ThemeMode.dark + ? Brightness.dark + : Brightness.light; + + expect(tester.platformDispatcher.platformBrightness, expected); + expect(tester.platformDispatcher.locale, variant.locale); + }, + ); + + testAdaptiveWidgets( + 'variantOverride is respected', + (tester, variant) async { + expect(variant.name, 'pixel_9'); + }, + variantOverride: WindowVariant({pixel9}), + ); + + test('themed variant has light and dark copies of each locale', () { + expect(configuration.themedDeviceVariant.windowConfigs, hasLength(8)); + }); +} diff --git a/test/configuration_test.dart b/test/configuration_test.dart new file mode 100644 index 0000000..0fee960 --- /dev/null +++ b/test/configuration_test.dart @@ -0,0 +1,135 @@ +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +class _MyWidget {} + +void main() { + final configuration = AdaptiveTestConfiguration.instance; + + tearDown(configuration.reset); + + group('device variants', () { + test('throws when not set', () { + expect(() => configuration.deviceVariant, throwsException); + expect(() => configuration.themedDeviceVariant, throwsException); + }); + + test('themed variant contains light and dark copies', () { + configuration.setDeviceVariants({iPhone8, pixel9}); + + expect( + configuration.themedDeviceVariant.windowConfigs.map((e) => e.name), + ['iPhone_8_light', 'iPhone_8_dark', 'pixel_9_light', 'pixel_9_dark'], + ); + }); + + test('themed variant follows setDeviceVariants', () { + configuration.setDeviceVariants({iPhone8}); + expect(configuration.themedDeviceVariant.windowConfigs, hasLength(2)); + + configuration.setDeviceVariants({iPhone8, desktop}); + expect(configuration.themedDeviceVariant.windowConfigs, hasLength(4)); + }); + + test('localized variants combine devices and locales', () { + configuration.setLocalizedDeviceVariants( + {iPhone8, desktop}, + const [Locale('en'), Locale('ar')], + ); + + final variant = configuration.deviceVariant; + expect(variant.windowConfigs, hasLength(4)); + expect( + variant.windowConfigs.map(variant.describeValue), + ['iPhone_8-en', 'iPhone_8-ar', 'desktop-en', 'desktop-ar'], + ); + expect(configuration.themedDeviceVariant.windowConfigs, hasLength(8)); + }); + }); + + group('describeValue', () { + test('defaults to the device name', () { + configuration.setDeviceVariants({iPhone8}); + + expect(configuration.deviceVariant.describeValue(iPhone8), 'iPhone_8'); + }); + + test('can be customized', () { + configuration + ..setDeviceVariants({iPhone8}) + ..setCustomDescribeValue((config) => 'custom ${config.name}'); + + expect( + configuration.deviceVariant.describeValue(iPhone8), + 'custom iPhone_8', + ); + }); + }); + + group('golden file names', () { + test('flat factory matches adaptive_test paths', () { + expect( + GoldenFileNameFactories.flat(iPhone8, _MyWidget, null), + 'preview/iPhone_8-my_widget.png', + ); + expect( + GoldenFileNameFactories.flat(iPhone8, _MyWidget, 'withKeyboard'), + 'preview/iPhone_8-my_widget_with_keyboard.png', + ); + }); + + test('flat factory appends theme and locale for derived variants', () { + expect( + GoldenFileNameFactories.flat( + iPhone8.dark().withLocale(const Locale('pt', 'BR')), + _MyWidget, + 'home', + ), + 'preview/iPhone_8_dark-my_widget_home-pt_BR.png', + ); + }); + + test('nested factory', () { + expect( + GoldenFileNameFactories.nested(iPhone8, _MyWidget, null), + 'golden/my_widget/iPhone_8.png', + ); + expect( + GoldenFileNameFactories.nested( + iPhone8.light().withLocale(const Locale('ar')), + _MyWidget, + 'with keyboard', + ), + 'golden/my_widget/with_keyboard/ar/iPhone_8_light.png', + ); + }); + + test('default factory is flat and can be replaced', () { + expect( + configuration.goldenFileNameFactory(iPhone8, _MyWidget, null), + GoldenFileNameFactories.flat(iPhone8, _MyWidget, null), + ); + + configuration.setGoldenFileNameFactory(GoldenFileNameFactories.nested); + expect( + configuration.goldenFileNameFactory(iPhone8, _MyWidget, null), + 'golden/my_widget/iPhone_8.png', + ); + }); + }); + + group('skip', () { + test('does not skip by default', () { + expect(configuration.shouldSkipTest, isFalse); + }); + + test('skipGoldenAssertion skips tests', () { + configuration.setSkipGoldenAssertion(() => true); + expect(configuration.shouldSkipTest, isTrue); + + configuration.setSkipGoldenAssertion(() => false); + expect(configuration.shouldSkipTest, isFalse); + }); + }); +} diff --git a/test/window_config_data_test.dart b/test/window_config_data_test.dart new file mode 100644 index 0000000..f38fa2e --- /dev/null +++ b/test/window_config_data_test.dart @@ -0,0 +1,60 @@ +import 'package:adaptive_test_plus/adaptive_test_plus.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + final device = WindowConfigData( + 'device', + size: const Size(390, 844), + pixelDensity: 3, + safeAreaPadding: const EdgeInsets.only(top: 47, bottom: 34), + keyboardSize: const Size(390, 302), + borderRadius: BorderRadius.circular(48), + notchSize: const Size(154, 32), + targetPlatform: TargetPlatform.iOS, + keyboardName: 'keyboard.png', + ); + + group('WindowConfigData', () { + test('keeps upstream defaults', () { + expect(device.themeMode, ThemeMode.light); + expect(device.locale, isNull); + expect(device.physicalSize, const Size(390, 844) * 3); + expect(device.padding, const ViewPaddingImpl(top: 47, bottom: 34) * 3); + expect(device.viewInsets, const ViewPaddingImpl(bottom: 302) * 3); + }); + + test('identical configs are equal', () { + expect(device.copyWith(), device); + expect({device, device.copyWith()}, hasLength(1)); + }); + + test('light and dark suffix the name and set the theme mode', () { + final light = device.light(); + final dark = device.dark(); + + expect(light.name, 'device_light'); + expect(light.themeMode, ThemeMode.light); + expect(dark.name, 'device_dark'); + expect(dark.themeMode, ThemeMode.dark); + expect(dark.size, device.size); + expect(dark.padding, device.padding); + expect(dark.viewInsets, device.viewInsets); + expect(dark.keyboardName, device.keyboardName); + }); + + test('theme suffix is not duplicated', () { + expect(device.dark().dark().name, 'device_dark'); + expect(iPhone16Dark.dark().name, iPhone16Dark.name); + }); + + test('withLocale keeps the name', () { + final localized = device.withLocale(const Locale('ar')); + + expect(localized.name, 'device'); + expect(localized.locale, const Locale('ar')); + expect(localized, isNot(device)); + expect(localized.dark().locale, const Locale('ar')); + }); + }); +}