From 3bf2ee5f5ec0bf5d03e0dd877d0b3d5b26518298 Mon Sep 17 00:00:00 2001 From: Valentin REVERSAT Date: Sun, 5 Apr 2026 23:48:11 +0200 Subject: [PATCH] WIP --- AGENTS.md | 178 ++++ devtools_options.yaml | 5 + lib/const.dart | 1 + lib/gen/assets.gen.dart | 35 +- lib/gen/fonts.gen.dart | 3 +- lib/l10n/app_en.arb | 4 + lib/l10n/app_fr.arb | 4 + lib/l10n/app_localizations.dart | 24 + lib/l10n/app_localizations_en.dart | 16 + lib/l10n/app_localizations_fr.dart | 16 + lib/models/game/game_type.dart | 1 - lib/models/iap/purchase/purchase.dart | 2 +- lib/models/players/belote_players.dart | 2 +- lib/models/players/tarot_players.dart | 2 +- .../score/misc/belote_contract_type.dart | 2 +- lib/models/score/misc/belote_team_enum.dart | 2 +- lib/models/score/misc/card_color.dart | 2 +- lib/models/score/misc/tarot_chelem.dart | 2 +- lib/models/score/misc/tarot_contract.dart | 2 +- lib/models/score/misc/tarot_handful.dart | 2 +- lib/models/score/misc/tarot_perk.dart | 2 +- lib/services/auth/auth_service.dart | 2 +- lib/services/storage_service.dart | 26 + lib/styles/text_style.dart | 19 +- lib/styles/theme/theme_service.dart | 179 +++- .../dialogs/edit_phone_number_dialog.dart | 61 ++ lib/views/dialogs/notes_dialog.dart | 2 +- .../player_color_explanation_dialog.dart | 2 +- .../add_round/widget/screen_title_widget.dart | 2 +- .../tarot_game/contract_tarot_widget.dart | 2 +- .../team_game/contract_belote_widget.dart | 2 +- .../register/edit_phone_number_screen.dart | 2 +- lib/views/screens/settings_screen.dart | 625 ++++++++----- lib/views/screens/splash_screen.dart | 2 +- lib/views/screens/user_screen.dart | 849 +++++++++++------- lib/views/widgets/belote_round_widget.dart | 2 +- linux/flutter/CMakeLists.txt | 2 +- linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + pubspec.lock | 8 + pubspec.yaml | 1 + test/units/helper/algolia_helper_test.dart | 6 +- test/units/mocks/fake_belote_game.dart | 18 +- test/units/mocks/fake_belote_score.dart | 5 +- .../mocks/fake_belote_score_service.dart | 23 +- test/units/mocks/fake_game.dart | 16 +- test/units/mocks/fake_game_service.dart | 20 +- test/units/mocks/fake_game_setting.dart | 5 +- test/units/mocks/fake_purchase.dart | 17 +- test/units/players/belote_players_test.dart | 97 +- .../players/carg_player_object_test.dart | 59 +- test/units/players/player_test.dart | 18 +- test/units/players/tarot_players_test.dart | 88 +- .../repositories/base_repository_test.dart | 103 ++- .../base_repository_test.mocks.dart | 57 +- .../coinche_belote_game_repository_test.dart | 273 +++--- ...che_belote_game_repository_test.mocks.dart | 57 +- .../contree_belote_game_repository_test.dart | 273 +++--- ...ree_belote_game_repository_test.mocks.dart | 57 +- .../french_belote_game_repository_test.dart | 281 +++--- ...nch_belote_game_repository_test.mocks.dart | 57 +- .../tarot/tarot_game_repository_test.dart | 276 +++--- .../tarot_game_repository_test.mocks.dart | 57 +- .../repositories/iap_repository_test.dart | 180 ++-- .../iap_repository_test.mocks.dart | 57 +- .../player/player_repository_test.dart | 99 +- .../player/player_repository_test.mocks.dart | 57 +- .../coinche_belote_score_repository_test.dart | 118 ++- ...he_belote_score_repository_test.mocks.dart | 57 +- .../contree_belote_score_repository_test.dart | 118 ++- ...ee_belote_score_repository_test.mocks.dart | 57 +- .../french_belote_score_repository_test.dart | 118 ++- ...ch_belote_score_repository_test.mocks.dart | 57 +- .../tarot/tarot_score_repository_test.dart | 94 +- .../tarot_score_repository_test.mocks.dart | 57 +- .../team/team_repository_test.dart | 287 +++--- .../team/team_repository_test.mocks.dart | 57 +- .../round/coinche_belote_round_test.dart | 12 +- .../round/contree_belote_round_test.dart | 200 +++-- .../units/round/french_belote_round_test.dart | 41 +- test/units/round/tarot_round_test.dart | 45 +- test/units/score/belote_score_test.dart | 7 +- test/units/score/tarot_score_test.dart | 194 ++-- .../abstract_belote_game_service_test.dart | 118 ++- ...stract_belote_game_service_test.mocks.dart | 10 +- .../game/abstract_game_service_test.dart | 104 ++- .../abstract_game_service_test.mocks.dart | 10 +- .../coinche_belote_game_service_test.dart | 40 +- ...oinche_belote_game_service_test.mocks.dart | 10 +- .../contree_belote_game_service_test.dart | 40 +- ...ontree_belote_game_service_test.mocks.dart | 10 +- .../french_belote_game_service_test.dart | 40 +- ...french_belote_game_service_test.mocks.dart | 10 +- .../game/tarot/tarot_game_service_test.dart | 104 ++- .../tarot/tarot_game_service_test.mocks.dart | 10 +- .../services/player/player_service_test.dart | 136 +-- .../player/player_service_test.mocks.dart | 10 +- .../round/abstract_round_service_test.dart | 12 +- .../abstract_round_service_test.mocks.dart | 1 + .../abstract_belote_round_service_test.dart | 28 +- ...tract_belote_round_service_test.mocks.dart | 1 + .../round/tarot/tarot_round_service_test.dart | 56 +- .../tarot/tarot_round_service_test.mocks.dart | 1 + .../score/abstract_score_service_test.dart | 65 +- .../abstract_score_service_test.mocks.dart | 10 +- .../coinche_belote_score_service_test.dart | 23 +- ...inche_belote_score_service_test.mocks.dart | 10 +- .../contree_belote_score_service_test.dart | 23 +- ...ntree_belote_score_service_test.mocks.dart | 10 +- .../french_belote_score_service_test.dart | 23 +- ...rench_belote_score_service_test.mocks.dart | 10 +- .../services/team/team_service_test.dart | 342 ++++--- .../team/team_service_test.mocks.dart | 10 +- .../services/theme/theme_service_test.dart | 59 ++ .../theme/theme_service_test.mocks.dart | 83 ++ test/widgets/ad_banner_widget_test.dart | 8 +- test/widgets/ad_banner_widget_test.mocks.dart | 1 + test/widgets/belote_widget_test.dart | 211 +++-- test/widgets/belote_widget_test.mocks.dart | 1 + .../card_color_picker_widget_test.dart | 12 +- .../widgets/contract_coinche_widget_test.dart | 21 +- .../widgets/contract_contree_widget_test.dart | 21 +- test/widgets/game_info_dialog_test.dart | 32 +- test/widgets/game_title_widget_test.dart | 73 +- test/widgets/localized_testable_widget.dart | 22 +- .../player_color_explanation_dialog_test.dart | 55 +- ...r_color_explanation_dialog_test.mocks.dart | 1 + test/widgets/player_info_dialog_test.dart | 353 ++++++-- .../player_info_dialog_test.mocks.dart | 1 + test/widgets/player_list_screen_test.dart | 153 ++-- .../player_list_screen_test.mocks.dart | 1 + test/widgets/register_screen_test.mocks.dart | 463 ++++------ test/widgets/settings_screen_test.dart | 200 +++-- test/widgets/settings_screen_test.mocks.dart | 16 + test/widgets/taker_team_widget_test.dart | 8 +- test/widgets/tarot_widget_test.dart | 79 +- test/widgets/tarot_widget_test.mocks.dart | 1 + test/widgets/team_stat_dialog_test.dart | 35 +- test/widgets/team_stat_dialog_test.mocks.dart | 1 + test/widgets/team_widget_test.dart | 48 +- test/widgets/team_widget_test.mocks.dart | 1 + .../trick_points_belote_widget_test.dart | 28 +- .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 144 files changed, 5438 insertions(+), 3706 deletions(-) create mode 100644 AGENTS.md create mode 100644 devtools_options.yaml create mode 100644 lib/views/dialogs/edit_phone_number_dialog.dart create mode 100644 test/units/services/theme/theme_service_test.dart create mode 100644 test/units/services/theme/theme_service_test.mocks.dart diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..b8b4c51b --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,178 @@ +# Project Overview +Mobile app for tracking French card games (Belote, Coinche, Tarot). Built with **Flutter** and **Firebase** for backend services, **Algolia** for player search/indexing. + +## Tech Stack +- **Frontend**: Flutter (Dart) +- **Backend**: Firebase (Auth, Firestore, Functions) +- **Search**: Algolia (player index) +- **Tooling**: Android Studio/Emulator, Firebase CLI, npm + +## Setup & Commands + +### Prerequisites +- Flutter SDK ([install guide](https://flutter.dev/docs/get-started/install)) +- Android emulator or physical device +- Firebase account + project +- Algolia account + +### Setup +```bash +git clone https://github.com/vareversat/carg.git +cd carg +``` + +### Firebase +1. Create a Firebase project at [Firebase Console](https://console.firebase.google.com/). +2. Download `google-services.json` and place it in `android/app/`. +3. Deploy Firebase Functions: + ```bash + cd functions + npm install -g firebase-tools + firebase deploy --only functions + ``` + +### Algolia +1. Create an Algolia project and an index named `player-dev`. +2. Add `assets/config/algolia.json`: + ```json + { + "app_id": "YOUR_APP_ID", + "api_key": "YOUR_API_KEY" + } + ``` + +### Run +```bash +flutter run +``` + +## Project Structure +- `lib/`: Flutter app source +- `functions/`: Firebase Cloud Functions +- `android/`: Android-specific config +- `assets/config/`: Algolia/Firebase configs + +## Code Style & Conventions +- Follow [Flutter style guide](https://flutter.dev/docs/development/tools/formatting). +- Use `dart format` before committing. +- Firebase Functions: ES6, Prettier for formatting. + +## Testing +- **Flutter tests**: Run with `flutter test`. +- **Firebase Functions**: Test locally with `firebase emulators:start`. + +## Development Environment +- Required: Flutter SDK, Android Studio, Node.js (for Firebase Functions). +- Env files: Never commit `google-services.json` or `algolia.json`. + +## Security +- **Never commit**: `google-services.json`, `algolia.json`, or any API keys. +- Use Firebase Rules to restrict Firestore access. + +## Git & PR Workflow +- Branch naming: `feature/`, `fix/`, `chore/`. +- PRs: Require approval, link to issues, and pass CI checks. + +## Important Context +- [README.md](README.md): User-facing docs. +- [Firebase Docs](https://firebase.google.com/docs): Backend reference. +- [Algolia Docs](https://www.algolia.com/doc/): Search setup. + +## Agent Behavior Guidelines +- **Minimal changes**: Prefer targeted fixes over refactors. +- **Sync tests**: Update tests for any logic changes. +- **Avoid secrets**: Use placeholder values in PRs. +- **Be concise**: Do not make a large conclusion every time you are making a change. + +--- +## Flutter Development Expert + +### Role +You are an expert in **Flutter mobile app development** for a French card games tracking app (Belote, Coinche, Tarot). You help users: +- Write clean, efficient Dart code for Flutter apps +- Debug common Flutter issues (state management, widgets, performance) +- Suggest best practices for architecture (BLoC, Provider, Riverpod) +- Generate UI/UX designs in Flutter +- Integrate Firebase (Auth, Firestore, Functions) and Algolia for search +- Optimize app performance and reduce bundle size +- Provide step-by-step guides for common Flutter tasks + +### Context +- You are building a **cross-platform mobile app** for Android and iOS. +- You are using **Flutter 3.19+** and **Dart 3.3+**. +- You want to follow modern Flutter best practices (null safety, responsive design, clean architecture). +- You are open to using popular packages like `flutter_bloc`, `go_router`, `shared_preferences`, `firebase_auth`, `cloud_firestore`, `algolia`. +- The app should be **performant, maintainable, and scalable**. +- Firebase is used for backend services (Auth, Firestore, Functions). +- Algolia is used for player search/indexing. + +### Constraints +- Avoid using deprecated packages or APIs. +- Always suggest alternatives if a package is outdated or no longer maintained. +- Provide code examples in Dart, with comments explaining key parts. +- If the user asks for a complex feature, break it down into smaller, manageable steps. +- Always ask clarifying questions if the request is ambiguous (e.g., "Is this for the Belote or Tarot game mode?"). +- **Never commit secrets** (e.g., API keys, `google-services.json`, `algolia.json`). +- Use Firebase Rules to restrict Firestore access. + +### Examples + +#### Example 1: Writing a Widget +**User:** "How do I create a dynamic list of card games in Flutter?" +**You:** +```dart +// Use a ListView.builder for lazy loading +ListView.builder( + itemCount: games.length, + itemBuilder: (context, index) { + return Card( + child: ListTile( + title: Text(games[index].name), + subtitle: Text(games[index].description), + onTap: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => GameDetailScreen(game: games[index]), + ), + ), + ), + ); + }, +) +``` +- Explain why `ListView.builder` is better than `ListView` for large datasets. +- Mention how to manage the `games` list (e.g., using a BLoC or Firestore stream). + +--- +#### Example 2: Debugging a Common Error +**User:** "Why is my Flutter app crashing with 'Null is not a subtype of String' in the Algolia search?" +**You:** +1. Ask for the stack trace or relevant code snippet. +2. Explain that this error usually occurs when a variable expected to be non-null is null. +3. Suggest using null checks (`??`, `?.`, or `!`) or error handling in the code. +4. Recommend using Algolia’s Flutter package with proper null safety. + +--- +### Resources +- [Flutter Docs](https://docs.flutter.dev/) +- [Dart API Reference](https://api.flutter.dev/) +- [Pub.dev](https://pub.dev/) (for package suggestions) +- [Firebase Docs](https://firebase.google.com/docs) +- [Algolia Flutter Docs](https://www.algolia.com/doc/guides/building-search-ui/getting-started/flutter/) +- [Flutter YouTube Channel](https://www.youtube.com/c/flutterdev) + +### Response Style +- Be **concise but thorough**. +- Use bullet points for lists or step-by-step instructions. +- Highlight key code snippets with ```dart ```. +- If the user asks for a feature, always ask clarifying questions (e.g., "Is this for the Belote or Tarot game mode?"). +- If the user provides code, review it and suggest improvements. +- **Never expose secrets** (e.g., API keys, `google-services.json`, `algolia.json`). +- **Be direct**: Only use verbs and actions. No explanations, no fluff. +- **Examples**: + - Instead of: *"Use a ListView.builder for lazy loading"* + → Write: *"Use ListView.builder. Lazy load."* + - Instead of: *"Explain why ListView.builder is better than ListView for large datasets"* + → Write: *"ListView.builder better than ListView for large datasets. Explain why."* +- **Never**: Start with "Let me help you" or "Here’s how you do it." +- **Always**: Start with a verb (e.g., "Write", "Debug", "Use", "Check"). \ No newline at end of file diff --git a/devtools_options.yaml b/devtools_options.yaml new file mode 100644 index 00000000..599931d5 --- /dev/null +++ b/devtools_options.yaml @@ -0,0 +1,5 @@ +description: This file stores settings for Dart & Flutter DevTools. +documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states +extensions: + - provider: true + - shared_preferences: true diff --git a/lib/const.dart b/lib/const.dart index 7498944b..e2075bc5 100644 --- a/lib/const.dart +++ b/lib/const.dart @@ -53,4 +53,5 @@ class Const { /// Local storage static const String storageThemeKey = 'THEME'; static const String storageContrastKey = 'CONTRAST'; + static const String storageDynamicColorsKey = 'DYNAMIC_COLORS'; } diff --git a/lib/gen/assets.gen.dart b/lib/gen/assets.gen.dart index f46987f2..20ea9a03 100644 --- a/lib/gen/assets.gen.dart +++ b/lib/gen/assets.gen.dart @@ -1,3 +1,5 @@ +// dart format width=80 + /// GENERATED CODE - DO NOT MODIFY BY HAND /// ***************************************************** /// FlutterGen @@ -5,7 +7,7 @@ // coverage:ignore-file // ignore_for_file: type=lint -// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use +// ignore_for_file: deprecated_member_use,directives_ordering,implicit_dynamic_list_literal,unnecessary_import import 'package:flutter/widgets.dart'; @@ -50,12 +52,18 @@ class Assets { } class AssetGenImage { - const AssetGenImage(this._assetName, {this.size, this.flavors = const {}}); + const AssetGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + this.animation, + }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -110,11 +118,30 @@ class AssetGenImage { ); } - ImageProvider provider({AssetBundle? bundle, String? package}) { - return AssetImage(_assetName, bundle: bundle, package: package); + ImageProvider provider({ + AssetBundle? bundle, + String? package, + }) { + return AssetImage( + _assetName, + bundle: bundle, + package: package, + ); } String get path => _assetName; String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/lib/gen/fonts.gen.dart b/lib/gen/fonts.gen.dart index 16938623..bde78c55 100644 --- a/lib/gen/fonts.gen.dart +++ b/lib/gen/fonts.gen.dart @@ -1,3 +1,4 @@ +// dart format width=80 /// GENERATED CODE - DO NOT MODIFY BY HAND /// ***************************************************** /// FlutterGen @@ -5,7 +6,7 @@ // coverage:ignore-file // ignore_for_file: type=lint -// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use +// ignore_for_file: deprecated_member_use,directives_ordering,implicit_dynamic_list_literal,unnecessary_import class FontFamily { FontFamily._(); diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 74f19c49..68ac32eb 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -207,6 +207,10 @@ "unableAppInfo": "Unable to get application information", "unableToOpen": "Unable to open the web page", "us": "Us", + "useDynamicColors": "Use device colors", + "dynamicColorsEnabled": "Dynamic colors enabled - using system theme", + "dynamicColorsDisabled": "Dynamic colors disabled - using app theme", + "dynamicColorsNote": "Note: Colors are extracted from your device's wallpaper and system settings", "useMyGravatar": "Use my Gravatar", "username": "Username", "confirm": "Confirm", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index ffd62206..afbce41d 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -207,6 +207,10 @@ "unableAppInfo": "mpossible d'obtenir les informations de l'application", "unableToOpen": "Impossible d'ouvrir la page ", "us": "Nous", + "useDynamicColors": "Utiliser les couleurs du système", + "dynamicColorsEnabled": "Couleurs dynamiques activées - utilisation du thème système", + "dynamicColorsDisabled": "Couleurs dynamiques désactivées - utilisation du thème de l'application", + "dynamicColorsNote": "Note : Les couleurs sont extraites de votre fond d'écran et des paramètres système", "useMyGravatar": "Utiliser mon Gravatar", "username": "Nom d'utilisateur", "confirm": "Confirmer", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 45c8aa1f..285c119c 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -1118,6 +1118,30 @@ abstract class AppLocalizations { /// **'Us'** String get us; + /// No description provided for @useDynamicColors. + /// + /// In en, this message translates to: + /// **'Use device colors'** + String get useDynamicColors; + + /// No description provided for @dynamicColorsEnabled. + /// + /// In en, this message translates to: + /// **'Dynamic colors enabled - using system theme'** + String get dynamicColorsEnabled; + + /// No description provided for @dynamicColorsDisabled. + /// + /// In en, this message translates to: + /// **'Dynamic colors disabled - using app theme'** + String get dynamicColorsDisabled; + + /// No description provided for @dynamicColorsNote. + /// + /// In en, this message translates to: + /// **'Note: Colors are extracted from your device\'s wallpaper and system settings'** + String get dynamicColorsNote; + /// No description provided for @useMyGravatar. /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index ad963f48..f0c76d53 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -1,5 +1,6 @@ // ignore: unused_import import 'package:intl/intl.dart' as intl; + import 'app_localizations.dart'; // ignore_for_file: type=lint @@ -585,6 +586,21 @@ class AppLocalizationsEn extends AppLocalizations { @override String get us => 'Us'; + @override + String get useDynamicColors => 'Use device colors'; + + @override + String get dynamicColorsEnabled => + 'Dynamic colors enabled - using system theme'; + + @override + String get dynamicColorsDisabled => + 'Dynamic colors disabled - using app theme'; + + @override + String get dynamicColorsNote => + 'Note: Colors are extracted from your device\'s wallpaper and system settings'; + @override String get useMyGravatar => 'Use my Gravatar'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 9c3be67c..ee08eeb3 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -1,5 +1,6 @@ // ignore: unused_import import 'package:intl/intl.dart' as intl; + import 'app_localizations.dart'; // ignore_for_file: type=lint @@ -589,6 +590,21 @@ class AppLocalizationsFr extends AppLocalizations { @override String get us => 'Nous'; + @override + String get useDynamicColors => 'Utiliser les couleurs du système'; + + @override + String get dynamicColorsEnabled => + 'Couleurs dynamiques activées - utilisation du thème système'; + + @override + String get dynamicColorsDisabled => + 'Couleurs dynamiques désactivées - utilisation du thème de l\'application'; + + @override + String get dynamicColorsNote => + 'Note : Les couleurs sont extraites de votre fond d\'écran et des paramètres système'; + @override String get useMyGravatar => 'Utiliser mon Gravatar'; diff --git a/lib/models/game/game_type.dart b/lib/models/game/game_type.dart index 448cd4a8..add468cf 100644 --- a/lib/models/game/game_type.dart +++ b/lib/models/game/game_type.dart @@ -1,6 +1,5 @@ // ignore_for_file: constant_identifier_names import 'package:carg/l10n/app_localizations.dart'; - import 'package:flutter/material.dart'; enum GameType { COINCHE, BELOTE, TAROT, CONTREE, UNDEFINE } diff --git a/lib/models/iap/purchase/purchase.dart b/lib/models/iap/purchase/purchase.dart index c762fe0a..c770b68e 100644 --- a/lib/models/iap/purchase/purchase.dart +++ b/lib/models/iap/purchase/purchase.dart @@ -1,6 +1,6 @@ import 'package:carg/models/carg_object.dart'; -import 'package:carg/models/iap/product/product_type_enum.dart'; import 'package:carg/models/iap/iap_source_enum.dart'; +import 'package:carg/models/iap/product/product_type_enum.dart'; abstract class Purchase extends CargObject { final IAPSourceEnum iapSource; diff --git a/lib/models/players/belote_players.dart b/lib/models/players/belote_players.dart index 21313dc7..5416e610 100644 --- a/lib/models/players/belote_players.dart +++ b/lib/models/players/belote_players.dart @@ -1,7 +1,7 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/player.dart'; import 'package:carg/models/players/players.dart'; import 'package:flutter/widgets.dart'; -import 'package:carg/l10n/app_localizations.dart'; class BelotePlayers extends Players { String? us; diff --git a/lib/models/players/tarot_players.dart b/lib/models/players/tarot_players.dart index 513fbb06..67a9d109 100644 --- a/lib/models/players/tarot_players.dart +++ b/lib/models/players/tarot_players.dart @@ -1,7 +1,7 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/player.dart'; import 'package:carg/models/players/players.dart'; import 'package:flutter/widgets.dart'; -import 'package:carg/l10n/app_localizations.dart'; class TarotPlayers extends Players { TarotPlayers({super.playerList}); diff --git a/lib/models/score/misc/belote_contract_type.dart b/lib/models/score/misc/belote_contract_type.dart index b959a1e0..2bff9bf9 100644 --- a/lib/models/score/misc/belote_contract_type.dart +++ b/lib/models/score/misc/belote_contract_type.dart @@ -1,6 +1,6 @@ // ignore_for_file: constant_identifier_names -import 'package:flutter/widgets.dart'; import 'package:carg/l10n/app_localizations.dart'; +import 'package:flutter/widgets.dart'; enum BeloteContractType { NORMAL, CAPOT, GENERALE, FAILED_GENERALE } diff --git a/lib/models/score/misc/belote_team_enum.dart b/lib/models/score/misc/belote_team_enum.dart index d14f625a..5e7714ae 100644 --- a/lib/models/score/misc/belote_team_enum.dart +++ b/lib/models/score/misc/belote_team_enum.dart @@ -1,7 +1,7 @@ // ignore_for_file: constant_identifier_names -import 'package:flutter/material.dart'; import 'package:carg/l10n/app_localizations.dart'; +import 'package:flutter/material.dart'; enum BeloteTeamEnum { US, THEM } diff --git a/lib/models/score/misc/card_color.dart b/lib/models/score/misc/card_color.dart index dba2232c..4e61d213 100644 --- a/lib/models/score/misc/card_color.dart +++ b/lib/models/score/misc/card_color.dart @@ -1,6 +1,6 @@ // ignore_for_file: constant_identifier_names -import 'package:flutter/material.dart'; import 'package:carg/l10n/app_localizations.dart'; +import 'package:flutter/material.dart'; enum CardColor { HEART, DIAMOND, CLUB, SPADE, ALL_TRUMP, NO_TRUMP } diff --git a/lib/models/score/misc/tarot_chelem.dart b/lib/models/score/misc/tarot_chelem.dart index ec31800f..2fff9854 100644 --- a/lib/models/score/misc/tarot_chelem.dart +++ b/lib/models/score/misc/tarot_chelem.dart @@ -1,7 +1,7 @@ // ignore_for_file: constant_identifier_names -import 'package:flutter/widgets.dart'; import 'package:carg/l10n/app_localizations.dart'; +import 'package:flutter/widgets.dart'; enum TarotChelem { PASSED, ANNOUNCED_AND_PASSED, FAILED } diff --git a/lib/models/score/misc/tarot_contract.dart b/lib/models/score/misc/tarot_contract.dart index e1d903ad..2c55288d 100644 --- a/lib/models/score/misc/tarot_contract.dart +++ b/lib/models/score/misc/tarot_contract.dart @@ -1,7 +1,7 @@ // ignore_for_file: constant_identifier_names -import 'package:flutter/widgets.dart'; import 'package:carg/l10n/app_localizations.dart'; +import 'package:flutter/widgets.dart'; enum TarotContract { PETITE, GARDE_AVEC_CHIEN, GARDE_SANS_CHIEN, GARDE_CONTRE } diff --git a/lib/models/score/misc/tarot_handful.dart b/lib/models/score/misc/tarot_handful.dart index 48ea99c1..98d430f9 100644 --- a/lib/models/score/misc/tarot_handful.dart +++ b/lib/models/score/misc/tarot_handful.dart @@ -1,6 +1,6 @@ // ignore_for_file: constant_identifier_names -import 'package:flutter/widgets.dart'; import 'package:carg/l10n/app_localizations.dart'; +import 'package:flutter/widgets.dart'; enum TarotHandful { SIMPLE, DOUBLE, TRIPLE } diff --git a/lib/models/score/misc/tarot_perk.dart b/lib/models/score/misc/tarot_perk.dart index 76f26a84..3ab635e9 100644 --- a/lib/models/score/misc/tarot_perk.dart +++ b/lib/models/score/misc/tarot_perk.dart @@ -1,6 +1,6 @@ // ignore_for_file: constant_identifier_names -import 'package:flutter/widgets.dart'; import 'package:carg/l10n/app_localizations.dart'; +import 'package:flutter/widgets.dart'; enum TarotBonus { SMALL_TO_THE_END, HANDFUL, CHELEM } diff --git a/lib/services/auth/auth_service.dart b/lib/services/auth/auth_service.dart index ff752144..d1441034 100644 --- a/lib/services/auth/auth_service.dart +++ b/lib/services/auth/auth_service.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'package:carg/const.dart'; import 'package:carg/exceptions/custom_exception.dart'; import 'package:carg/helpers/custom_route.dart'; +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/player.dart'; import 'package:carg/repositories/impl/iap_repository.dart'; import 'package:carg/services/impl/player_service.dart'; @@ -16,7 +17,6 @@ import 'package:carg/views/screens/register/welcome_screen.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:carg/l10n/app_localizations.dart'; import 'package:google_sign_in/google_sign_in.dart'; class AuthService with ChangeNotifier { diff --git a/lib/services/storage_service.dart b/lib/services/storage_service.dart index 105d82e6..61fb1575 100644 --- a/lib/services/storage_service.dart +++ b/lib/services/storage_service.dart @@ -60,4 +60,30 @@ class StorageService { return value; } } + + Future saveDynamicColors(bool value) async { + developer.log( + '{${Const.storageDynamicColorsKey}: $value}', + name: 'storage-service.on.saveDynamicColors', + ); + + return await sharedPreferences.setBool( + Const.storageDynamicColorsKey, + value, + ); + } + + bool? readDynamicColors() { + final boolValue = sharedPreferences.getBool(Const.storageDynamicColorsKey); + if (boolValue == null) { + return null; + } else { + developer.log( + '{${Const.storageDynamicColorsKey}: $boolValue}', + name: 'storage-service.on.readDynamicColors', + ); + + return boolValue; + } + } } diff --git a/lib/styles/text_style.dart b/lib/styles/text_style.dart index 0901c07e..13ecc96f 100644 --- a/lib/styles/text_style.dart +++ b/lib/styles/text_style.dart @@ -9,26 +9,25 @@ class CustomTextStyle { ); } - static TextStyle dialogHeaderStyle(BuildContext context) { - return TextStyle( + static TextStyle? dialogHeaderStyle(BuildContext context) { + return Theme.of(context).textTheme.bodyLarge?.copyWith( fontSize: 30, - fontWeight: FontWeight.bold, color: Theme.of(context).colorScheme.onPrimary, + fontWeight: FontWeight.bold, ); } - static TextStyle screenHeadLine1(BuildContext context) { - return TextStyle( - fontSize: 35, - fontWeight: FontWeight.bold, + static TextStyle? screenHeadLine1(BuildContext context) { + return Theme.of(context).textTheme.headlineLarge?.copyWith( color: Theme.of(context).colorScheme.onPrimary, + fontWeight: FontWeight.bold, ); } - static TextStyle screenHeadLine2(BuildContext context) { - return TextStyle( - fontSize: 28, + static TextStyle? screenHeadLine2(BuildContext context) { + return Theme.of(context).textTheme.headlineMedium?.copyWith( color: Theme.of(context).colorScheme.onPrimary, + fontWeight: FontWeight.bold, ); } diff --git a/lib/styles/theme/theme_service.dart b/lib/styles/theme/theme_service.dart index a774adb5..7a21d99e 100644 --- a/lib/styles/theme/theme_service.dart +++ b/lib/styles/theme/theme_service.dart @@ -1,6 +1,7 @@ import 'package:carg/services/storage_service.dart'; import 'package:carg/styles/app_color_scheme.dart'; import 'package:carg/styles/theme/enums.dart'; +import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; @@ -8,22 +9,31 @@ class ThemeService with ChangeNotifier { final StorageService storageService; late CargMaterialTheme _cargMaterialTheme; - late ThemeData _currentThemeData; + ThemeData? _currentThemeData; late ThemeValue _currentThemeValue; late ContrastValue _currentContrastValue; + late bool _useDynamicColors; ThemeService(BuildContext context, this.storageService) { TextTheme textTheme = createTextTheme(context); _currentThemeValue = storageService.readTheme() ?? ThemeValue.system; _currentContrastValue = storageService.readContrast() ?? ContrastValue.none; + _useDynamicColors = storageService.readDynamicColors() ?? false; _cargMaterialTheme = CargMaterialTheme(textTheme); + + // If dynamic colors are enabled, load them immediately + if (_useDynamicColors) { + _loadDynamicColors(); + } + getCurrentThemeData(); } CargMaterialTheme get cargMaterialTheme => _cargMaterialTheme; - ThemeData get currentThemeData => _currentThemeData; + ThemeData get currentThemeData => + _currentThemeData ?? (_currentThemeData = _getFallbackTheme()); ThemeValue get currentThemeValue => _currentThemeValue; @@ -38,7 +48,15 @@ class ThemeService with ChangeNotifier { set currentThemeValue(ThemeValue value) { _currentThemeValue = value; storageService.saveTheme(value); - notifyListeners(); + + // If dynamic colors are enabled, reload them with the new theme brightness + if (_useDynamicColors) { + _loadDynamicColors(); + } else { + // Update to use the new static theme + _currentThemeData = null; + notifyListeners(); + } } set currentThemeData(ThemeData value) { @@ -46,11 +64,41 @@ class ThemeService with ChangeNotifier { notifyListeners(); } + bool get useDynamicColors => _useDynamicColors; + + set useDynamicColors(bool value) { + _useDynamicColors = value; + storageService.saveDynamicColors(value); + + // If enabling dynamic colors, load them asynchronously + if (value) { + _loadDynamicColors(); + } else { + // If disabling, reset to static theme + _currentThemeData = null; + notifyListeners(); + } + } + + Future _loadDynamicColors() async { + try { + final dynamicColors = await DynamicColorPlugin.getCorePalette(); + if (dynamicColors != null) { + _currentThemeData = _buildThemeFromCorePalette(dynamicColors); + notifyListeners(); + } + } catch (e) { + debugPrint('Dynamic color generation failed: $e'); + _currentThemeData = null; + notifyListeners(); + } + } + bool showContrastPicker() { return _currentThemeValue != ThemeValue.system; } - ThemeData getCurrentThemeData() { + ThemeData _getFallbackTheme() { if (_currentThemeValue == ThemeValue.light) { if (_currentContrastValue == ContrastValue.none) { return _cargMaterialTheme.light(); @@ -70,6 +118,129 @@ class ThemeService with ChangeNotifier { } } + ThemeData getCurrentThemeData() { + // If dynamic colors are enabled and we have a cached dynamic theme, use it + if (_useDynamicColors && _currentThemeData != null) { + return _currentThemeData!; + } + + // Fall back to static theme + return _getFallbackTheme(); + } + + /// Build theme from real device core palette + ThemeData _buildThemeFromCorePalette(dynamic corePalette) { + // Determine the brightness based on user preference + final brightness = _getBrightnessForDynamicTheme(); + final isDark = brightness == Brightness.dark; + + // Create base color scheme from seed + final colorScheme = ColorScheme.fromSeed( + seedColor: Color(corePalette.primary.get(50)), + brightness: brightness, + primary: Color(corePalette.primary.get(50)), + secondary: Color(corePalette.secondary.get(50)), + tertiary: Color(corePalette.tertiary.get(50)), + error: Color(corePalette.error.get(50)), + outline: Color(corePalette.neutral.get(50)), + surface: isDark + ? Color(corePalette.neutral.get(10)) + : Color(corePalette.neutral.get(98)), + onSurface: isDark + ? Color(corePalette.neutral.get(90)) + : Color(corePalette.neutral.get(10)), + ); + + debugPrint( + 'Generated ColorScheme from real device: ${colorScheme.toString()}', + ); + + return ThemeData( + colorScheme: colorScheme, + useMaterial3: true, + textTheme: _cargMaterialTheme.textTheme.copyWith( + bodyLarge: _cargMaterialTheme.textTheme.bodyLarge?.copyWith( + color: colorScheme.onSurface, + ), + bodyMedium: _cargMaterialTheme.textTheme.bodyMedium?.copyWith( + color: colorScheme.onSurface, + ), + bodySmall: _cargMaterialTheme.textTheme.bodySmall?.copyWith( + color: colorScheme.onSurface, + ), + titleLarge: _cargMaterialTheme.textTheme.titleLarge?.copyWith( + color: colorScheme.onSurface, + ), + titleMedium: _cargMaterialTheme.textTheme.titleMedium?.copyWith( + color: colorScheme.onSurface, + ), + titleSmall: _cargMaterialTheme.textTheme.titleSmall?.copyWith( + color: colorScheme.onSurface, + ), + headlineLarge: _cargMaterialTheme.textTheme.headlineLarge?.copyWith( + color: colorScheme.onSurface, + ), + headlineMedium: _cargMaterialTheme.textTheme.headlineMedium?.copyWith( + color: colorScheme.onSurface, + ), + headlineSmall: _cargMaterialTheme.textTheme.headlineSmall?.copyWith( + color: colorScheme.onSurface, + ), + labelLarge: _cargMaterialTheme.textTheme.labelLarge?.copyWith( + color: colorScheme.onSurface, + ), + labelMedium: _cargMaterialTheme.textTheme.labelMedium?.copyWith( + color: colorScheme.onSurface, + ), + labelSmall: _cargMaterialTheme.textTheme.labelSmall?.copyWith( + color: colorScheme.onSurface, + ), + ), + scaffoldBackgroundColor: colorScheme.surface, + appBarTheme: AppBarTheme( + backgroundColor: colorScheme.surface, + foregroundColor: colorScheme.onSurface, + titleTextStyle: TextStyle(color: colorScheme.onSurface), + iconTheme: IconThemeData(color: colorScheme.onSurface), + ), + cardTheme: CardThemeData( + color: colorScheme.surfaceContainerHighest, + margin: EdgeInsets.zero, + ), + iconTheme: IconThemeData(color: colorScheme.onSurface), + dialogTheme: DialogThemeData( + backgroundColor: colorScheme.surface, + titleTextStyle: TextStyle(color: colorScheme.onSurface), + contentTextStyle: TextStyle(color: colorScheme.onSurface), + ), + bottomNavigationBarTheme: BottomNavigationBarThemeData( + backgroundColor: colorScheme.surface, + selectedItemColor: colorScheme.primary, + unselectedItemColor: colorScheme.onSurface.withValues(alpha: .6), + ), + ); + } + + /// Determine the appropriate brightness for dynamic themes + Brightness _getBrightnessForDynamicTheme() { + // If contrast is enabled, use high contrast version of the selected theme + if (_currentContrastValue != ContrastValue.none) { + return _currentThemeValue == ThemeValue.dark + ? Brightness.dark + : Brightness.light; + } + + // Respect user's theme preference + switch (_currentThemeValue) { + case ThemeValue.light: + return Brightness.light; + case ThemeValue.dark: + return Brightness.dark; + case ThemeValue.system: + return SchedulerBinding.instance.platformDispatcher.platformBrightness; + } + } + ThemeData _getCorrectThemeForSystem() { var brightness = SchedulerBinding.instance.platformDispatcher.platformBrightness; diff --git a/lib/views/dialogs/edit_phone_number_dialog.dart b/lib/views/dialogs/edit_phone_number_dialog.dart new file mode 100644 index 00000000..0f8d459b --- /dev/null +++ b/lib/views/dialogs/edit_phone_number_dialog.dart @@ -0,0 +1,61 @@ +import 'package:carg/l10n/app_localizations.dart'; +import 'package:carg/services/auth/auth_service.dart'; +import 'package:carg/views/widgets/register/register_phone_widget.dart'; +import 'package:flutter/material.dart'; + +class EditPhoneNumberDialog extends StatelessWidget { + const EditPhoneNumberDialog({super.key}); + + @override + Widget build(BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 500), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + _buildHeader(context), + const Divider(height: 1), + Padding( + padding: const EdgeInsets.all(16), + child: RegisterPhoneWidget( + credentialVerificationType: CredentialVerificationType.EDIT, + ), + ), + ], + ), + ), + ); + } + + Widget _buildHeader(BuildContext context) { + return Padding( + padding: const EdgeInsets.all(16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + AppLocalizations.of(context)!.newPhoneNumber, + style: Theme.of( + context, + ).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold), + ), + IconButton( + icon: const Icon(Icons.close), + onPressed: () => Navigator.of(context).pop(), + tooltip: MaterialLocalizations.of(context).closeButtonTooltip, + ), + ], + ), + ); + } +} + +/// Show the edit phone number dialog +Future showEditPhoneNumberDialog(BuildContext context) async { + await showDialog( + context: context, + builder: (context) => const EditPhoneNumberDialog(), + ); +} diff --git a/lib/views/dialogs/notes_dialog.dart b/lib/views/dialogs/notes_dialog.dart index 89659e56..93859169 100644 --- a/lib/views/dialogs/notes_dialog.dart +++ b/lib/views/dialogs/notes_dialog.dart @@ -1,9 +1,9 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/game/game.dart'; import 'package:carg/services/game/abstract_game_service.dart'; import 'package:carg/styles/properties.dart'; import 'package:carg/styles/text_style.dart'; import 'package:flutter/material.dart'; -import 'package:carg/l10n/app_localizations.dart'; class NotesDialog extends StatefulWidget { final Game game; diff --git a/lib/views/dialogs/player_color_explanation_dialog.dart b/lib/views/dialogs/player_color_explanation_dialog.dart index c6dc1d19..11687503 100644 --- a/lib/views/dialogs/player_color_explanation_dialog.dart +++ b/lib/views/dialogs/player_color_explanation_dialog.dart @@ -33,7 +33,7 @@ class PlayerColorExplanationDialog extends StatelessWidget { overflow: TextOverflow.ellipsis, style: CustomTextStyle.dialogHeaderStyle( context, - ).copyWith(color: Theme.of(context).colorScheme.primary), + )?.copyWith(color: Theme.of(context).colorScheme.primary), ), ), content: ListBody( diff --git a/lib/views/screens/add_round/widget/screen_title_widget.dart b/lib/views/screens/add_round/widget/screen_title_widget.dart index b4510056..47e0c686 100644 --- a/lib/views/screens/add_round/widget/screen_title_widget.dart +++ b/lib/views/screens/add_round/widget/screen_title_widget.dart @@ -1,6 +1,6 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/styles/text_style.dart'; import 'package:flutter/material.dart'; -import 'package:carg/l10n/app_localizations.dart'; class ScreenTitleWidget extends StatelessWidget { const ScreenTitleWidget({super.key}); diff --git a/lib/views/screens/add_round/widget/tarot_game/contract_tarot_widget.dart b/lib/views/screens/add_round/widget/tarot_game/contract_tarot_widget.dart index f50f74c5..0b631b97 100644 --- a/lib/views/screens/add_round/widget/tarot_game/contract_tarot_widget.dart +++ b/lib/views/screens/add_round/widget/tarot_game/contract_tarot_widget.dart @@ -1,8 +1,8 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/score/misc/tarot_contract.dart'; import 'package:carg/models/score/round/tarot_round.dart'; import 'package:carg/views/screens/add_round/widget/section_title_widget.dart'; import 'package:flutter/material.dart'; -import 'package:carg/l10n/app_localizations.dart'; import 'package:provider/provider.dart'; class ContractTarotWidget extends StatelessWidget { diff --git a/lib/views/screens/add_round/widget/team_game/contract_belote_widget.dart b/lib/views/screens/add_round/widget/team_game/contract_belote_widget.dart index a15d86aa..5aec9693 100644 --- a/lib/views/screens/add_round/widget/team_game/contract_belote_widget.dart +++ b/lib/views/screens/add_round/widget/team_game/contract_belote_widget.dart @@ -1,8 +1,8 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/score/round/french_belote_round.dart'; import 'package:carg/views/screens/add_round/widget/section_title_widget.dart'; import 'package:carg/views/screens/add_round/widget/team_game/card_color_picker_widget.dart'; import 'package:flutter/material.dart'; -import 'package:carg/l10n/app_localizations.dart'; import 'package:provider/provider.dart'; class ContractBeloteWidget extends StatelessWidget { diff --git a/lib/views/screens/register/edit_phone_number_screen.dart b/lib/views/screens/register/edit_phone_number_screen.dart index 8e010786..c0367eb8 100644 --- a/lib/views/screens/register/edit_phone_number_screen.dart +++ b/lib/views/screens/register/edit_phone_number_screen.dart @@ -1,9 +1,9 @@ import 'package:carg/const.dart'; +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/services/auth/auth_service.dart'; import 'package:carg/views/widgets/register/register_phone_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:carg/l10n/app_localizations.dart'; import 'package:flutter_svg/svg.dart'; class EditPhoneNumberScreen extends StatelessWidget { diff --git a/lib/views/screens/settings_screen.dart b/lib/views/screens/settings_screen.dart index 0bc538c4..c977feae 100644 --- a/lib/views/screens/settings_screen.dart +++ b/lib/views/screens/settings_screen.dart @@ -1,13 +1,13 @@ import 'package:carg/exceptions/custom_exception.dart'; -import 'package:carg/helpers/custom_route.dart'; import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/player.dart'; import 'package:carg/services/auth/auth_service.dart'; import 'package:carg/services/impl/player_service.dart'; import 'package:carg/styles/text_style.dart'; +import 'package:carg/styles/theme/theme_service.dart'; import 'package:carg/views/dialogs/carg_about_dialog.dart'; +import 'package:carg/views/dialogs/edit_phone_number_dialog.dart'; import 'package:carg/views/helpers/info_snackbar.dart'; -import 'package:carg/views/screens/register/edit_phone_number_screen.dart'; import 'package:carg/views/widgets/remove_ads_list_tile.dart'; import 'package:carg/views/widgets/theme_picker_widget.dart'; import 'package:flutter/material.dart'; @@ -83,234 +83,425 @@ class _SettingsScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ChangeNotifierProvider.value( - value: widget.player, - child: Consumer( - builder: (context, playerData, _) => Column( - children: [ - ListTile( - title: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - AppLocalizations.of(context)!.myProfile, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 30, - ), - ), - playerData.admin - ? ClipRRect( - key: const ValueKey('adminLabel'), - borderRadius: BorderRadius.circular(5.0), - child: Container( - color: Theme.of( - context, - ).colorScheme.secondaryContainer, - height: 30, - child: Center( - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 8.0, - ), - child: Text( - AppLocalizations.of(context)!.admin, - style: TextStyle( - fontWeight: FontWeight.bold, - color: Theme.of(context) - .colorScheme - .onSecondaryContainer, - fontSize: 15, - ), - overflow: TextOverflow.ellipsis, - ), - ), - ), - ), - ) - : const SizedBox(), - ], - ), - ), - ListTile( - title: TextFormField( - key: const ValueKey('usernameTextField'), - initialValue: playerData.userName, - autofillHints: const [AutofillHints.username], - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - ), - keyboardType: TextInputType.name, - decoration: InputDecoration( - labelStyle: const TextStyle( - fontWeight: FontWeight.normal, - ), - labelText: AppLocalizations.of(context)!.username, - ), - onFieldSubmitted: (value) async { - playerData.userName = value; - await _savePlayer(); - }, - ), - ), - ListTile( - selected: true, - leading: Container( - width: 60, - height: 60, - decoration: BoxDecoration( - shape: BoxShape.circle, - border: Border.all( - width: 2, - color: Theme.of(context).colorScheme.secondary, - ), - image: DecorationImage( - fit: BoxFit.fill, - image: NetworkImage(playerData.profilePicture), - ), - ), - ), - title: TextFormField( - key: const ValueKey('imageURLTextField'), - controller: _profilePictureController, - enabled: !playerData.useGravatarProfilePicture, - autofillHints: !playerData.useGravatarProfilePicture - ? [AutofillHints.url] - : null, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20, - ), - onChanged: (value) { - playerData.profilePicture = value; - }, - keyboardType: TextInputType.visiblePassword, - decoration: InputDecoration( - labelStyle: const TextStyle( - fontWeight: FontWeight.normal, - ), - labelText: AppLocalizations.of( - context, - )!.profilePicture, - ), - onFieldSubmitted: (value) async { - await _savePlayer(); - }, - ), - ), - SwitchListTile( - key: const ValueKey('gravatarSwitchTile'), - title: Text( - AppLocalizations.of(context)!.useMyGravatar, - style: const TextStyle(fontSize: 20), - ), - onChanged: (bool value) async => - await _onSwitchTileChanged(value), - value: playerData.useGravatarProfilePicture, - ), - ListTile( - title: Text( - AppLocalizations.of(context)!.appTheme, - style: const TextStyle(fontSize: 20), - ), - ), - ThemePickerWidget(), - ], - ), - ), - ), - const SizedBox(height: 15), - ListTile( - title: Text( - AppLocalizations.of(context)!.myAccount, - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30), - ), - ), - Column( + _buildProfileSection(), + const SizedBox(height: 24), + _buildAccountSection(), + const SizedBox(height: 24), + _buildMyAppSection(), + const SizedBox(height: 24), + _buildAppSection(), + const SizedBox(height: 32), + ], + ), + ), + ), + ); + } + + Widget _buildProfileSection() { + return ChangeNotifierProvider.value( + value: widget.player, + child: Consumer( + builder: (context, playerData, _) => Consumer( + builder: (context, themeService, _) => Card( + margin: const EdgeInsets.symmetric(horizontal: 16), + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - ListTile( - subtitle: Text( - Provider.of( - context, - listen: false, - ).getConnectedUserPhoneNumber() ?? - AppLocalizations.of(context)!.noPhoneNumberProvided, - key: const ValueKey('phoneText'), - style: const TextStyle( - fontSize: 15, - fontStyle: FontStyle.italic, - ), - ), - selected: true, - leading: const Icon(Icons.phone, size: 30), - onTap: () => Navigator.push( - context, - CustomRouteLeftToRight( - builder: (context) => const EditPhoneNumberScreen(), - ), - ), - title: Text( - AppLocalizations.of(context)!.changeMyPhoneNumber, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontSize: 25, - ), - ), + _buildSectionHeader( + context, + AppLocalizations.of(context)!.myProfile, + playerData.admin + ? AppLocalizations.of(context)!.admin + : null, ), + const SizedBox(height: 16), + _buildUsernameField(playerData), + const SizedBox(height: 20), + _buildProfilePictureSection(playerData), + const SizedBox(height: 20), + _buildGravatarSwitch(playerData), ], ), - Padding( - padding: const EdgeInsets.all(8.0), - child: Center( - child: TextButton( - onPressed: () async => await Provider.of( - context, - listen: false, - ).signOut(context), - child: Text( - AppLocalizations.of(context)!.signOut, - style: TextStyle( - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.error, - fontSize: 25, - ), - ), - ), - ), + ), + ), + ), + ), + ); + } + + Widget _buildDynamicColorsSwitch(ThemeService themeService) { + return Column( + children: [ + SwitchListTile( + title: Text( + AppLocalizations.of(context)!.useDynamicColors, + style: Theme.of(context).textTheme.titleMedium, + ), + subtitle: Text( + themeService.useDynamicColors + ? AppLocalizations.of(context)!.dynamicColorsEnabled + : AppLocalizations.of(context)!.dynamicColorsDisabled, + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + color: themeService.useDynamicColors + ? Theme.of(context).colorScheme.primary + : Theme.of(context).colorScheme.outline, + ), + ), + activeThumbColor: Theme.of(context).colorScheme.primary, + contentPadding: EdgeInsets.zero, + onChanged: (bool value) { + themeService.useDynamicColors = value; + }, + value: themeService.useDynamicColors, + ), + if (themeService.useDynamicColors) ...[ + const SizedBox(height: 8), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Text( + AppLocalizations.of(context)!.dynamicColorsNote, + style: Theme.of(context).textTheme.bodySmall?.copyWith( + color: Theme.of(context).colorScheme.outline, + fontStyle: FontStyle.italic, ), - const RemoveAdsListTile(key: ValueKey('removeAdsListTile')), - ListTile( - key: const ValueKey('aboutButton'), - subtitle: Text( - AppLocalizations.of(context)!.informationAboutTheApp, + ), + ), + ], + ], + ); + } + + Widget _buildSectionHeader( + BuildContext context, + String title, + String? badgeText, + ) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + title, + style: Theme.of( + context, + ).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold), + ), + if (badgeText != null) _buildAdminBadge(context, badgeText), + ], + ); + } + + Widget _buildAdminBadge(BuildContext context, String text) { + return Container( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.secondaryContainer, + borderRadius: BorderRadius.circular(20), + ), + child: Text( + text, + style: Theme.of(context).textTheme.labelLarge?.copyWith( + color: Theme.of(context).colorScheme.onSecondaryContainer, + fontWeight: FontWeight.bold, + ), + ), + ); + } + + Widget _buildUsernameField(Player playerData) { + return TextFormField( + key: const ValueKey('usernameTextField'), + initialValue: playerData.userName, + autofillHints: const [AutofillHints.username], + style: Theme.of( + context, + ).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold), + keyboardType: TextInputType.name, + decoration: InputDecoration( + labelText: AppLocalizations.of(context)!.username, + border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)), + prefixIcon: const Icon(Icons.person), + ), + onFieldSubmitted: (value) async { + playerData.userName = value; + await _savePlayer(); + }, + ); + } + + Widget _buildProfilePictureSection(Player playerData) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + AppLocalizations.of(context)!.profilePicture, + style: Theme.of( + context, + ).textTheme.titleSmall?.copyWith(fontWeight: FontWeight.bold), + ), + const SizedBox(height: 8), + Row( + children: [ + Container( + width: 60, + height: 60, + decoration: BoxDecoration( + shape: BoxShape.circle, + border: Border.all( + width: 2, + color: Theme.of(context).colorScheme.primary, ), - selected: true, - leading: const Icon(Icons.info_outline, size: 30), - onTap: () async => await showGeneralDialog( - transitionDuration: const Duration(milliseconds: 300), - context: context, - pageBuilder: - ( - BuildContext context, - Animation animation, - Animation secondaryAnimation, - ) { - return CargAboutDialog(); - }, + image: DecorationImage( + fit: BoxFit.cover, + image: NetworkImage(playerData.profilePicture), ), - title: Text( - AppLocalizations.of(context)!.about, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontSize: 25, + ), + ), + const SizedBox(width: 16), + Expanded( + child: TextFormField( + key: const ValueKey('imageURLTextField'), + controller: _profilePictureController, + enabled: !playerData.useGravatarProfilePicture, + autofillHints: !playerData.useGravatarProfilePicture + ? [AutofillHints.url] + : null, + style: Theme.of(context).textTheme.bodyLarge, + onChanged: (value) { + playerData.profilePicture = value; + }, + keyboardType: TextInputType.url, + decoration: InputDecoration( + hintText: AppLocalizations.of(context)!.profilePicture, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), ), + contentPadding: const EdgeInsets.symmetric(horizontal: 12), ), + onFieldSubmitted: (value) async { + await _savePlayer(); + }, ), - ], + ), + ], + ), + ], + ); + } + + Widget _buildGravatarSwitch(Player playerData) { + return SwitchListTile( + key: const ValueKey('gravatarSwitchTile'), + title: Text( + AppLocalizations.of(context)!.useMyGravatar, + style: Theme.of(context).textTheme.titleMedium, + ), + activeThumbColor: Theme.of(context).colorScheme.primary, + contentPadding: EdgeInsets.zero, + onChanged: (bool value) async => await _onSwitchTileChanged(value), + value: playerData.useGravatarProfilePicture, + ); + } + + Widget _buildAccountSection() { + return Card( + margin: const EdgeInsets.symmetric(horizontal: 16), + elevation: 2, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildSectionHeader( + context, + AppLocalizations.of(context)!.myAccount, + null, + ), + const SizedBox(height: 16), + _buildPhoneNumberTile(), + const SizedBox(height: 20), + _buildSignOutButton(), + ], + ), + ), + ); + } + + Widget _buildPhoneNumberTile() { + final phoneNumber = Provider.of( + context, + listen: false, + ).getConnectedUserPhoneNumber(); + + return ListTile( + contentPadding: EdgeInsets.zero, + leading: Container( + width: 48, + height: 48, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.primaryContainer, + borderRadius: BorderRadius.circular(12), + ), + child: Icon( + Icons.phone, + color: Theme.of(context).colorScheme.onPrimaryContainer, + ), + ), + title: Text( + AppLocalizations.of(context)!.changeMyPhoneNumber, + style: Theme.of(context).textTheme.titleMedium, + ), + subtitle: Text( + phoneNumber ?? AppLocalizations.of(context)!.noPhoneNumberProvided, + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + fontStyle: FontStyle.italic, + color: Theme.of(context).colorScheme.outline, + ), + ), + trailing: const Icon(Icons.chevron_right), + onTap: () => showEditPhoneNumberDialog(context), + ); + } + + Widget _buildSignOutButton() { + return Center( + child: ElevatedButton.icon( + style: ElevatedButton.styleFrom( + backgroundColor: Theme.of(context).colorScheme.errorContainer, + foregroundColor: Theme.of(context).colorScheme.onErrorContainer, + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), + ), + onPressed: () async => await Provider.of( + context, + listen: false, + ).signOut(context), + icon: const Icon(Icons.logout), + label: Text( + AppLocalizations.of(context)!.signOut, + style: Theme.of( + context, + ).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold), + ), + ), + ); + } + + Widget _buildMyAppSection() { + return ChangeNotifierProvider.value( + value: widget.player, + child: Consumer( + builder: (context, playerData, _) => Consumer( + builder: (context, themeService, _) => Card( + margin: const EdgeInsets.symmetric(horizontal: 16), + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildSectionHeader( + context, + AppLocalizations.of(context)!.settings, + null, + ), + const SizedBox(height: 16), + Text( + AppLocalizations.of(context)!.appTheme, + style: Theme.of(context).textTheme.titleMedium?.copyWith( + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 8), + ThemePickerWidget(), + const SizedBox(height: 16), + _buildDynamicColorsSwitch(themeService), + const SizedBox(height: 20), + const RemoveAdsListTile(key: ValueKey('removeAdsListTile')), + ], + ), + ), ), ), ), ); } + + Widget _buildAppSection() { + return Card( + margin: const EdgeInsets.symmetric(horizontal: 16), + elevation: 2, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildSectionHeader( + context, + AppLocalizations.of(context)!.about, + null, + ), + const SizedBox(height: 16), + _buildAboutTile(), + ], + ), + ), + ); + } + + Widget _buildAboutTile() { + return ListTile( + contentPadding: EdgeInsets.zero, + leading: Container( + width: 48, + height: 48, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.primaryContainer, + borderRadius: BorderRadius.circular(12), + ), + child: Icon( + Icons.info_outline, + color: Theme.of(context).colorScheme.onPrimaryContainer, + ), + ), + title: Text( + AppLocalizations.of(context)!.about, + style: Theme.of(context).textTheme.titleMedium, + ), + subtitle: Text( + AppLocalizations.of(context)!.informationAboutTheApp, + style: Theme.of(context).textTheme.bodyMedium, + ), + trailing: const Icon(Icons.chevron_right), + onTap: () async => await showGeneralDialog( + transitionDuration: const Duration(milliseconds: 300), + context: context, + pageBuilder: + ( + BuildContext context, + Animation animation, + Animation secondaryAnimation, + ) { + return CargAboutDialog(); + }, + transitionBuilder: (context, animation, secondaryAnimation, child) { + return FadeTransition( + opacity: CurvedAnimation(parent: animation, curve: Curves.easeOut), + child: child, + ); + }, + ), + ); + } } diff --git a/lib/views/screens/splash_screen.dart b/lib/views/screens/splash_screen.dart index 4724fc59..0ab649d6 100644 --- a/lib/views/screens/splash_screen.dart +++ b/lib/views/screens/splash_screen.dart @@ -1,7 +1,7 @@ import 'package:carg/const.dart'; +import 'package:carg/l10n/app_localizations.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:carg/l10n/app_localizations.dart'; import 'package:flutter_svg/svg.dart'; class SplashScreen extends StatelessWidget { diff --git a/lib/views/screens/user_screen.dart b/lib/views/screens/user_screen.dart index c055567a..73ec24f0 100644 --- a/lib/views/screens/user_screen.dart +++ b/lib/views/screens/user_screen.dart @@ -6,14 +6,22 @@ import 'package:carg/models/player.dart'; import 'package:carg/services/auth/auth_service.dart'; import 'package:carg/services/impl/player_service.dart'; import 'package:carg/styles/properties.dart'; -import 'package:carg/styles/text_style.dart'; import 'package:carg/views/screens/settings_screen.dart'; import 'package:carg/views/widgets/error_message_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; -import 'package:syncfusion_flutter_charts/charts.dart'; -import 'package:syncfusion_flutter_gauges/gauges.dart'; +import 'package:syncfusion_flutter_charts/charts.dart' hide CornerStyle; +import 'package:syncfusion_flutter_gauges/gauges.dart' + show + SfRadialGauge, + RadialAxis, + GaugeAnnotation, + GaugePointer, + GaugeSizeUnit, + AxisLineStyle, + RangePointer, + CornerStyle; class UserScreen extends StatefulWidget { static const routeName = '/user'; @@ -32,6 +40,8 @@ class _UserScreenState extends State Player? _player; final _playerService = PlayerService(); late Animation _opacityAnimation; + late Animation _fadeAnimation; + late Animation _scaleAnimation; late AnimationController _animationController; Future _showSettingsScreen() async { @@ -58,15 +68,30 @@ class _UserScreenState extends State void initState() { _animationController = AnimationController( vsync: this, - duration: const Duration(milliseconds: 1100), + duration: const Duration(milliseconds: 800), ); _opacityAnimation = Tween( - begin: const Offset(0.0, -1.0), + begin: const Offset(0.0, -0.5), end: const Offset(0.0, 0.0), ).animate( - CurvedAnimation(parent: _animationController, curve: Curves.ease), + CurvedAnimation( + parent: _animationController, + curve: Curves.easeInOut, + ), ); + _fadeAnimation = Tween(begin: 0.0, end: 1.0).animate( + CurvedAnimation( + parent: _animationController, + curve: const Interval(0.1, 0.6, curve: Curves.easeInOut), + ), + ); + _scaleAnimation = Tween(begin: 0.9, end: 1.0).animate( + CurvedAnimation( + parent: _animationController, + curve: const Interval(0.3, 0.9, curve: Curves.easeOutBack), + ), + ); _animationController.forward(); super.initState(); } @@ -80,6 +105,7 @@ class _UserScreenState extends State @override Widget build(BuildContext context) { return Scaffold( + extendBodyBehindAppBar: true, body: FutureBuilder( future: _playerService .getPlayerOfUser( @@ -94,181 +120,289 @@ class _UserScreenState extends State ), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return CustomScrollView( - slivers: [ - SliverAppBar( - backgroundColor: Theme.of(context).colorScheme.primary, - automaticallyImplyLeading: false, - forceElevated: true, - expandedHeight: 200, - collapsedHeight: 140, - title: _AppBarTitle(onPressEdit: _showSettingsScreen), - flexibleSpace: const FlexibleSpaceBar( - centerTitle: true, - title: Text(''), - ), - ), - ], - ); + return _buildLoadingView(context); } if (snapshot.connectionState == ConnectionState.none || snapshot.data == null) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - ErrorMessageWidget( - message: - _errorMessage ?? - AppLocalizations.of(context)!.youDontHaveAnyPlayer, - ), - ElevatedButton.icon( - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all( - Theme.of(context).colorScheme.onPrimary, - ), - foregroundColor: WidgetStateProperty.all( - Theme.of(context).colorScheme.primary, - ), - shape: WidgetStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - CustomProperties.borderRadius, - ), - ), - ), - ), - onPressed: () async => _signOut(), - label: Text( - AppLocalizations.of(context)!.connection, - style: const TextStyle(fontSize: 14), - ), - icon: const Icon(Icons.arrow_back), - ), - ], - ); + return _buildErrorView(context); } if (snapshot.data == null) { - return Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - AppLocalizations.of(context)!.noPlayerYet, - style: const TextStyle(fontSize: 18), - ), - ], - ), - ); + return _buildNoPlayerView(context); } + _player = snapshot.data; - return ChangeNotifierProvider.value( - value: _player!, - child: Consumer( - builder: (context, player, _) => CustomScrollView( - slivers: [ - SliverAppBar( - shape: const ContinuousRectangleBorder( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular( - CustomProperties.borderRadius * 5, - ), - bottomRight: Radius.circular( - CustomProperties.borderRadius * 5, - ), + return _buildUserProfileView(context, _player!); + }, + ), + ); + } + + Widget _buildLoadingView(BuildContext context) { + return CustomScrollView( + slivers: [ + SliverAppBar( + backgroundColor: Theme.of(context).colorScheme.primary, + automaticallyImplyLeading: false, + forceElevated: true, + expandedHeight: 250, + collapsedHeight: 140, + flexibleSpace: FlexibleSpaceBar( + centerTitle: true, + title: Text( + AppLocalizations.of(context)!.loading, + style: Theme.of(context).textTheme.titleLarge?.copyWith( + color: Theme.of(context).colorScheme.onPrimary, + ), + ), + ), + ), + ], + ); + } + + Widget _buildErrorView(BuildContext context) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ErrorMessageWidget( + message: + _errorMessage ?? + AppLocalizations.of(context)!.youDontHaveAnyPlayer, + ), + const SizedBox(height: 20), + ElevatedButton.icon( + style: ElevatedButton.styleFrom( + backgroundColor: Theme.of(context).colorScheme.primary, + foregroundColor: Theme.of(context).colorScheme.onPrimary, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular( + CustomProperties.borderRadius, + ), + ), + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), + ), + onPressed: () async => _signOut(), + label: Text( + AppLocalizations.of(context)!.connection, + style: const TextStyle(fontSize: 16), + ), + icon: const Icon(Icons.arrow_back), + ), + ], + ), + ); + } + + Widget _buildNoPlayerView(BuildContext context) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.person_off, + size: 64, + color: Theme.of(context).colorScheme.outline, + ), + const SizedBox(height: 16), + Text( + AppLocalizations.of(context)!.noPlayerYet, + style: Theme.of(context).textTheme.titleMedium, + ), + ], + ), + ); + } + + Widget _buildUserProfileView(BuildContext context, Player player) { + return ChangeNotifierProvider.value( + value: player, + child: Consumer( + builder: (context, player, _) => RefreshIndicator( + onRefresh: () async { + setState(() {}); + }, + child: CustomScrollView( + slivers: [ + _buildProfileHeader(context, player), + SliverToBoxAdapter( + child: Column( + children: [ + if (player.gameStatsList!.isNotEmpty) ...[ + const SizedBox(height: 24), + _buildOverallStatsCard(context, player), + const SizedBox(height: 24), + _buildSectionHeader( + context, + AppLocalizations.of(context)!.winPercentage, ), - ), - backgroundColor: Theme.of(context).colorScheme.primary, - automaticallyImplyLeading: false, - floating: true, - pinned: true, - forceElevated: true, - expandedHeight: 200, - collapsedHeight: 140, - title: _AppBarTitle(onPressEdit: _showSettingsScreen), - flexibleSpace: FlexibleSpaceBar( - centerTitle: true, - title: _PlayerUsernameAndProfilePictureWidget( - player: _player, - animation: _opacityAnimation, + const SizedBox(height: 16), + _buildWinPercentageCharts(context, player), + const SizedBox(height: 24), + _buildSectionHeader( + context, + AppLocalizations.of(context)!.gameDistribution, ), - ), - ), - SliverList( - delegate: SliverChildListDelegate([ - _player!.gameStatsList!.isNotEmpty - ? Column( - children: [ - Padding( - padding: const EdgeInsets.symmetric( - vertical: 15, - ), - child: Text( - '-- ${AppLocalizations.of(context)!.winPercentage} --', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith(fontStyle: FontStyle.italic), - ), - ), - _WonPlayedWidget(player: _player), - Padding( - padding: const EdgeInsets.symmetric( - vertical: 30, - ), - child: Wrap( - runSpacing: 20, - spacing: 80, - alignment: WrapAlignment.spaceEvenly, - children: _player!.gameStatsList! - .map( - (stat) => ConstrainedBox( - constraints: const BoxConstraints( - maxWidth: 160, - maxHeight: 160, - ), - child: _StatGauge(gameStats: stat), - ), - ) - .toList() - .cast(), - ), - ), - Padding( - padding: const EdgeInsets.symmetric( - vertical: 15, - ), - child: Text( - '-- ${AppLocalizations.of(context)!.gameDistribution} --', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith(fontStyle: FontStyle.italic), - ), - ), - _StatCircularChart( - gameStatsList: _player!.gameStatsList, - ), - ], - ) - : Center( - child: Padding( - padding: const EdgeInsets.all(30), - child: Text( - AppLocalizations.of(context)!.noStatisticYet, - style: const TextStyle( - fontSize: 25, - fontStyle: FontStyle.italic, - ), - ), - ), - ), - ]), - ), - ], + const SizedBox(height: 16), + _buildGameDistributionChart(context, player), + const SizedBox(height: 32), + ] else ...[ + const SizedBox(height: 24), + _buildNoStatsView(context), + ], + ], + ), ), + ], + ), + ), + ), + ); + } + + Widget _buildProfileHeader(BuildContext context, Player player) { + return SliverAppBar( + shape: const ContinuousRectangleBorder( + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(CustomProperties.borderRadius), + bottomRight: Radius.circular(CustomProperties.borderRadius), + ), + ), + backgroundColor: Theme.of(context).colorScheme.primary, + automaticallyImplyLeading: false, + floating: true, + pinned: true, + forceElevated: true, + expandedHeight: 250, + collapsedHeight: 140, + flexibleSpace: FlexibleSpaceBar( + centerTitle: true, + title: _PlayerUsernameAndProfilePictureWidget( + player: player, + animation: _opacityAnimation, + ), + ), + actions: [ + IconButton( + icon: Icon( + Icons.settings, + color: Theme.of(context).colorScheme.onPrimary, + ), + onPressed: _showSettingsScreen, + tooltip: AppLocalizations.of(context)!.settings, + ), + ], + ); + } + + Widget _buildOverallStatsCard(BuildContext context, Player player) { + return FadeTransition( + opacity: _fadeAnimation, + child: Card( + margin: const EdgeInsets.symmetric(horizontal: 16), + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(CustomProperties.borderRadius), + ), + child: Padding( + padding: const EdgeInsets.all(20), + child: _WonPlayedWidget(player: player), + ), + ), + ); + } + + Widget _buildSectionHeader(BuildContext context, String title) { + return FadeTransition( + opacity: _fadeAnimation, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Text( + title, + style: Theme.of(context).textTheme.titleMedium?.copyWith( + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), + ), + ); + } + + Widget _buildWinPercentageCharts(BuildContext context, Player player) { + return SlideTransition( + position: + Tween( + begin: const Offset(1.0, 0.0), + end: const Offset(0.0, 0.0), + ).animate( + CurvedAnimation( + parent: _animationController, + curve: const Interval(0.3, 0.9, curve: Curves.easeOut), ), - ); - }, + ), + child: SizedBox( + height: 220, + child: ListView( + scrollDirection: Axis.horizontal, + padding: const EdgeInsets.symmetric(horizontal: 16), + children: player.gameStatsList! + .map( + (stat) => Padding( + padding: const EdgeInsets.only(right: 12), + child: SizedBox( + width: 180, + child: _StatGauge(gameStats: stat), + ), + ), + ) + .toList(), + ), + ), + ); + } + + Widget _buildGameDistributionChart(BuildContext context, Player player) { + return ScaleTransition( + scale: _scaleAnimation, + child: Card( + margin: const EdgeInsets.symmetric(horizontal: 16), + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(CustomProperties.borderRadius), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: SizedBox( + height: 300, + child: _StatCircularChart(gameStatsList: player.gameStatsList), + ), + ), + ), + ); + } + + Widget _buildNoStatsView(BuildContext context) { + return Center( + child: Padding( + padding: const EdgeInsets.all(30), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.analytics_outlined, + size: 64, + color: Theme.of(context).colorScheme.outline, + ), + const SizedBox(height: 16), + Text( + AppLocalizations.of(context)!.noStatisticYet, + style: Theme.of( + context, + ).textTheme.titleMedium?.copyWith(fontStyle: FontStyle.italic), + textAlign: TextAlign.center, + ), + ], + ), ), ); } @@ -281,57 +415,75 @@ class _StatGauge extends StatelessWidget { @override Widget build(BuildContext context) { - return InkWell( - child: SfRadialGauge( - title: GaugeTitle( - text: gameStats!.gameType.name, - textStyle: Theme.of( - context, - ).textTheme.bodyMedium!.copyWith(fontWeight: FontWeight.bold), - ), - axes: [ - RadialAxis( - annotations: [ - GaugeAnnotation( - axisValue: 50, - positionFactor: 0, - widget: Text( - '${gameStats!.winPercentage().toString()}%', - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 22, + return Card( + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(CustomProperties.borderRadius), + ), + child: Padding( + padding: const EdgeInsets.all(15), + child: Column( + children: [ + Text( + gameStats!.gameType.name, + style: Theme.of( + context, + ).textTheme.titleSmall?.copyWith(fontWeight: FontWeight.bold), + ), + Expanded( + child: SfRadialGauge( + axes: [ + RadialAxis( + radiusFactor: 0.9, + annotations: [ + GaugeAnnotation( + angle: 90, + positionFactor: 0, + widget: Text( + '${gameStats!.winPercentage().toString()}%', + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 20, + ), + ), + ), + GaugeAnnotation( + angle: 90, + positionFactor: 0.2, + widget: Text( + '${gameStats!.wonGames} - ${gameStats!.playedGames}', + style: const TextStyle(fontSize: 11), + ), + ), + ], + startAngle: 140, + endAngle: 140 + 260, + minimum: 0, + maximum: 100, + showLabels: false, + showTicks: false, + axisLineStyle: AxisLineStyle( + thickness: 0.2, + color: Theme.of(context).colorScheme.outline, + thicknessUnit: GaugeSizeUnit.factor, + cornerStyle: CornerStyle.bothCurve, + ), + pointers: [ + RangePointer( + value: gameStats!.winPercentage().toDouble(), + width: 0.2, + sizeUnit: GaugeSizeUnit.factor, + color: Theme.of(context).colorScheme.primary, + cornerStyle: CornerStyle.bothCurve, + ), + ], ), - ), - ), - GaugeAnnotation( - axisValue: 50, - positionFactor: 0.3, - widget: Text( - '${gameStats!.wonGames} | ${gameStats!.playedGames}', - style: const TextStyle(fontSize: 15), - ), - ), - ], - startAngle: 270, - endAngle: 270, - interval: 10, - showLabels: false, - showTicks: false, - ranges: [ - GaugeRange( - startValue: 0, - endValue: gameStats!.winPercentage(), - color: Theme.of(context).colorScheme.primaryContainer, - ), - GaugeRange( - startValue: gameStats!.winPercentage(), - endValue: 100, - color: Theme.of(context).colorScheme.inverseSurface, + ], + enableLoadingAnimation: true, ), - ], - ), - ], - enableLoadingAnimation: true, + ), + ], + ), ), ); } @@ -344,30 +496,51 @@ class _StatCircularChart extends StatelessWidget { @override Widget build(BuildContext context) { - return SfCircularChart( - tooltipBehavior: TooltipBehavior( - enable: true, - color: Theme.of(context).colorScheme.primary, - ), - series: [ - DoughnutSeries( - radius: '60%', - innerRadius: '20%', - dataSource: gameStatsList!, - xValueMapper: (GameStats data, _) => data.gameType.name, - yValueMapper: (GameStats data, _) => data.playedGames, + return SizedBox( + height: 300, + child: SfCircularChart( + tooltipBehavior: TooltipBehavior(enable: true, borderWidth: 1), + series: [ + DoughnutSeries( + radius: '100%', + innerRadius: '60%', + dataSource: gameStatsList!, + xValueMapper: (GameStats data, _) => data.gameType.name, + yValueMapper: (GameStats data, _) => data.playedGames, + pointColorMapper: (GameStats data, _) => + _getColorForGameType(context, data.gameType), + dataLabelSettings: DataLabelSettings( + isVisible: true, + labelPosition: ChartDataLabelPosition.inside, + ), + ), + ], + legend: Legend( + iconHeight: 16, + iconWidth: 16, + position: LegendPosition.left, + isVisible: true, + overflowMode: LegendItemOverflowMode.wrap, ), - ], - legend: Legend( - iconHeight: 20, - iconWidth: 20, - textStyle: Theme.of(context).textTheme.bodyMedium!, - position: LegendPosition.right, - isVisible: true, - toggleSeriesVisibility: true, ), ); } + + Color _getColorForGameType(BuildContext context, GameType gameType) { + final colors = Theme.of(context).colorScheme; + switch (gameType) { + case GameType.COINCHE: + return colors.primary; + case GameType.BELOTE: + return colors.secondary; + case GameType.TAROT: + return colors.tertiary; + case GameType.CONTREE: + return colors.error; + default: + return colors.outline; + } + } } class _PlayerUsernameAndProfilePictureWidget extends StatelessWidget { @@ -379,39 +552,70 @@ class _PlayerUsernameAndProfilePictureWidget extends StatelessWidget { required this.animation, }); + String? _getProfilePicture(Player player) { + try { + final profilePic = player.profilePicture; + if (profilePic.isNotEmpty) { + return profilePic; + } + return Player.defaultProfilePicture; + } catch (e) { + return Player.defaultProfilePicture; + } + } + @override Widget build(BuildContext context) { + if (player == null) { + return const SizedBox.shrink(); + } + return Column( mainAxisAlignment: MainAxisAlignment.end, children: [ - Flexible( - child: Padding( - padding: const EdgeInsets.only(bottom: 6.0), - child: SlideTransition( - position: animation, - child: Container( - width: 80, - height: 80, - decoration: BoxDecoration( - shape: BoxShape.circle, - border: Border.all( - width: 2, - color: Theme.of(context).colorScheme.onPrimary, - ), - image: DecorationImage( - fit: BoxFit.fill, - image: NetworkImage(player!.profilePicture), - ), - ), + SlideTransition( + position: animation, + child: Container( + width: 96, + height: 96, + decoration: BoxDecoration( + shape: BoxShape.circle, + border: Border.all( + width: 3, + color: Theme.of(context).colorScheme.surface, ), + boxShadow: [ + BoxShadow( + color: Theme.of( + context, + ).colorScheme.shadow.withValues(alpha: .3), + blurRadius: 10, + spreadRadius: 2, + ), + BoxShadow( + color: Theme.of( + context, + ).colorScheme.shadow.withValues(alpha: .1), + blurRadius: 20, + spreadRadius: 5, + ), + ], + image: _getProfilePicture(player!) != null + ? DecorationImage( + fit: BoxFit.cover, + image: NetworkImage(_getProfilePicture(player!)!), + ) + : null, ), ), ), + const SizedBox(height: 12), Text( - player!.userName, + player!.userName.toString(), overflow: TextOverflow.ellipsis, - style: Theme.of(context).textTheme.titleLarge?.copyWith( + style: Theme.of(context).textTheme.headlineSmall?.copyWith( color: Theme.of(context).colorScheme.onPrimary, + fontWeight: FontWeight.bold, ), textAlign: TextAlign.center, ), @@ -420,44 +624,6 @@ class _PlayerUsernameAndProfilePictureWidget extends StatelessWidget { } } -class _AppBarTitle extends StatelessWidget { - final Function onPressEdit; - - const _AppBarTitle({required this.onPressEdit}); - - @override - Widget build(BuildContext context) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - AppLocalizations.of(context)!.profileTitle, - style: CustomTextStyle.screenHeadLine1(context), - ), - FilledButton( - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all( - Theme.of(context).colorScheme.onPrimary, - ), - foregroundColor: WidgetStateProperty.all( - Theme.of(context).colorScheme.primary, - ), - shape: WidgetStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular( - CustomProperties.borderRadius, - ), - ), - ), - ), - onPressed: () async => await onPressEdit(), - child: const Icon(Icons.settings, size: 20), - ), - ], - ); - } -} - class _WonPlayedWidget extends StatelessWidget { final Player? player; @@ -466,64 +632,61 @@ class _WonPlayedWidget extends StatelessWidget { @override Widget build(BuildContext context) { return Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Flexible( - child: Column( - children: [ - const Icon(FontAwesomeIcons.trophy, size: 20), - Padding( - padding: const EdgeInsets.all(5.0), - child: Text( - player!.totalWonGames().toString(), - style: const TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ), - Text( - AppLocalizations.of(context)!.victories, - style: const TextStyle(fontSize: 20), - ), - ], - ), + _buildStatColumn( + context, + FontAwesomeIcons.trophy, + player!.totalWonGames().toString(), + AppLocalizations.of(context)!.victories, ), Container( decoration: BoxDecoration( border: Border( bottom: BorderSide( - color: Theme.of(context).colorScheme.onSurface, - width: 6, + color: Theme.of(context).colorScheme.primary, + width: 3, ), ), ), + padding: const EdgeInsets.symmetric(horizontal: 16), child: Text( - '${player!.totalWinPercentage()} %', - style: const TextStyle(fontSize: 35, fontWeight: FontWeight.bold), + '${player!.totalWinPercentage()}%', + style: Theme.of(context).textTheme.headlineMedium?.copyWith( + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), ), ), - Flexible( - child: Column( - children: [ - const Icon(Icons.videogame_asset, size: 20), - Padding( - padding: const EdgeInsets.all(5.0), - child: Text( - player!.totalPlayedGames().toString(), - style: const TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - ), - ), - ), - Text( - AppLocalizations.of(context)!.games, - style: const TextStyle(fontSize: 20), - ), - ], - ), + _buildStatColumn( + context, + Icons.videogame_asset, + player!.totalPlayedGames().toString(), + AppLocalizations.of(context)!.games, + ), + ], + ); + } + + Widget _buildStatColumn( + BuildContext context, + IconData icon, + String value, + String label, + ) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(icon, size: 24, color: Theme.of(context).colorScheme.primary), + const SizedBox(height: 8), + Text( + value, + style: Theme.of( + context, + ).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold), ), + const SizedBox(height: 4), + Text(label, style: Theme.of(context).textTheme.bodySmall), ], ); } diff --git a/lib/views/widgets/belote_round_widget.dart b/lib/views/widgets/belote_round_widget.dart index 3e18d53a..04d75b65 100644 --- a/lib/views/widgets/belote_round_widget.dart +++ b/lib/views/widgets/belote_round_widget.dart @@ -1,7 +1,7 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/score/french_belote_score.dart'; import 'package:carg/services/impl/score/french_belote_score_service.dart'; import 'package:flutter/material.dart'; -import 'package:carg/l10n/app_localizations.dart'; class BeloteRoundWidget extends StatefulWidget { final String beloteGameId; diff --git a/linux/flutter/CMakeLists.txt b/linux/flutter/CMakeLists.txt index a1da1b9e..6dc97055 100644 --- a/linux/flutter/CMakeLists.txt +++ b/linux/flutter/CMakeLists.txt @@ -82,7 +82,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" - linux-x64 ${CMAKE_BUILD_TYPE} + ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 38dd0bc6..075ecba3 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,10 +6,14 @@ #include "generated_plugin_registrant.h" +#include #include #include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) dynamic_color_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin"); + dynamic_color_plugin_register_with_registrar(dynamic_color_registrar); g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin"); flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 65240e99..6fd458b2 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + dynamic_color flutter_secure_storage_linux url_launcher_linux ) diff --git a/pubspec.lock b/pubspec.lock index 7b16c2dc..6c69e3b4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -241,6 +241,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + dynamic_color: + dependency: "direct main" + description: + name: dynamic_color + sha256: "43a5a6679649a7731ab860334a5812f2067c2d9ce6452cf069c5e0c25336c17c" + url: "https://pub.dev" + source: hosted + version: "1.8.1" enum_to_string: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 2d28e48a..a5c598bf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: flutter_libphonenumber: ^2.2.1 font_awesome_flutter: ^10.0.0 google_fonts: ^6.0.0 + dynamic_color: ^1.8.1 http: ^1.1.2 intl: ^0.20.2 in_app_purchase: ^3.0.7 diff --git a/test/units/helper/algolia_helper_test.dart b/test/units/helper/algolia_helper_test.dart index d131c7df..3757df55 100644 --- a/test/units/helper/algolia_helper_test.dart +++ b/test/units/helper/algolia_helper_test.dart @@ -55,8 +55,10 @@ void main() async { TestWidgetsFlutterBinding.ensureInitialized(); var helper = await AlgoliaHelper.create(); var filter = helper.getAlgoliaFilter(false, 'player_id', null); - expect(filter, - '(owned_by:player_id OR owned:false) AND NOT testing:true'); + expect( + filter, + '(owned_by:player_id OR owned:false) AND NOT testing:true', + ); }); }); }); diff --git a/test/units/mocks/fake_belote_game.dart b/test/units/mocks/fake_belote_game.dart index a4820ee5..babfc85c 100644 --- a/test/units/mocks/fake_belote_game.dart +++ b/test/units/mocks/fake_belote_game.dart @@ -3,11 +3,15 @@ import 'package:carg/models/game/setting/belote_game_setting.dart'; import 'package:carg/models/players/belote_players.dart'; class FakeBeloteGame extends Belote { - FakeBeloteGame(String? id, DateTime startingDate, BelotePlayers players, - BeloteGameSetting settings) - : super( - players: players, - id: id, - startingDate: startingDate, - settings: settings); + FakeBeloteGame( + String? id, + DateTime startingDate, + BelotePlayers players, + BeloteGameSetting settings, + ) : super( + players: players, + id: id, + startingDate: startingDate, + settings: settings, + ); } diff --git a/test/units/mocks/fake_belote_score.dart b/test/units/mocks/fake_belote_score.dart index 2315bf82..b9c12073 100644 --- a/test/units/mocks/fake_belote_score.dart +++ b/test/units/mocks/fake_belote_score.dart @@ -1,5 +1,8 @@ import 'package:carg/models/score/belote_score.dart'; class FakeBeloteScore extends BeloteScore { - FakeBeloteScore({required super.usTotalPoints, required super.themTotalPoints}); + FakeBeloteScore({ + required super.usTotalPoints, + required super.themTotalPoints, + }); } diff --git a/test/units/mocks/fake_belote_score_service.dart b/test/units/mocks/fake_belote_score_service.dart index 8b5c458c..e24539a8 100644 --- a/test/units/mocks/fake_belote_score_service.dart +++ b/test/units/mocks/fake_belote_score_service.dart @@ -8,18 +8,20 @@ import 'package:carg/services/game/abstract_belote_game_service.dart'; import 'fake_belote_game.dart'; class FakeBeloteGameService extends AbstractBeloteGameService { - FakeBeloteGameService( - {required super.beloteScoreService, - required super.beloteGameRepository, - required super.teamService}); + FakeBeloteGameService({ + required super.beloteScoreService, + required super.beloteGameRepository, + required super.teamService, + }); @override Future> generateNewGame( - Team us, - Team them, - List? playerListForOrder, - DateTime? startingDate, - BeloteGameSetting settings) async { + Team us, + Team them, + List? playerListForOrder, + DateTime? startingDate, + BeloteGameSetting settings, + ) async { try { var belote = FakeBeloteGame( null, @@ -31,7 +33,8 @@ class FakeBeloteGameService extends AbstractBeloteGameService { return belote; } on Exception catch (e) { throw ServiceException( - 'Error while generating a new game : ${e.toString()}'); + 'Error while generating a new game : ${e.toString()}', + ); } } } diff --git a/test/units/mocks/fake_game.dart b/test/units/mocks/fake_game.dart index f86a05a0..044fce67 100644 --- a/test/units/mocks/fake_game.dart +++ b/test/units/mocks/fake_game.dart @@ -4,10 +4,14 @@ import 'package:carg/models/players/players.dart'; class FakeGame extends Game { FakeGame( - String? id, DateTime startingDate, Players players, GameSetting settings) - : super( - players: players, - id: id, - startingDate: startingDate, - settings: settings); + String? id, + DateTime startingDate, + Players players, + GameSetting settings, + ) : super( + players: players, + id: id, + startingDate: startingDate, + settings: settings, + ); } diff --git a/test/units/mocks/fake_game_service.dart b/test/units/mocks/fake_game_service.dart index 64c38c28..f8cec86f 100644 --- a/test/units/mocks/fake_game_service.dart +++ b/test/units/mocks/fake_game_service.dart @@ -6,18 +6,20 @@ import 'package:carg/services/player/abstract_player_service.dart'; import 'package:carg/services/team/abstract_team_service.dart'; class FakeGameService extends AbstractGameService { - FakeGameService( - {required super.scoreService, - required super.gameRepository, - required AbstractPlayerService playerService, - required AbstractTeamService teamService}); + FakeGameService({ + required super.scoreService, + required super.gameRepository, + required AbstractPlayerService playerService, + required AbstractTeamService teamService, + }); @override Future> createGameWithPlayerList( - List playerListForOrder, - List playerListForTeam, - DateTime? startingDate, - GameSetting settings) { + List playerListForOrder, + List playerListForTeam, + DateTime? startingDate, + GameSetting settings, + ) { throw UnimplementedError(); } diff --git a/test/units/mocks/fake_game_setting.dart b/test/units/mocks/fake_game_setting.dart index a32410fb..b4088459 100644 --- a/test/units/mocks/fake_game_setting.dart +++ b/test/units/mocks/fake_game_setting.dart @@ -1,8 +1,5 @@ import 'package:carg/models/game/setting/game_setting.dart'; class FakeGameSetting extends GameSetting { - FakeGameSetting({ - required super.maxPoint, - required super.isInfinite, - }); + FakeGameSetting({required super.maxPoint, required super.isInfinite}); } diff --git a/test/units/mocks/fake_purchase.dart b/test/units/mocks/fake_purchase.dart index 095c6abb..a717890e 100644 --- a/test/units/mocks/fake_purchase.dart +++ b/test/units/mocks/fake_purchase.dart @@ -1,14 +1,15 @@ import 'package:carg/models/iap/purchase/purchase.dart'; class FakePurchase extends Purchase { - FakePurchase( - {super.id, - required super.iapSource, - required super.orderId, - required super.productId, - required super.userId, - required super.purchaseDate, - required super.type}); + FakePurchase({ + super.id, + required super.iapSource, + required super.orderId, + required super.productId, + required super.userId, + required super.purchaseDate, + required super.type, + }); @override bool isValid() { diff --git a/test/units/players/belote_players_test.dart b/test/units/players/belote_players_test.dart index 1688c33e..68d10aad 100644 --- a/test/units/players/belote_players_test.dart +++ b/test/units/players/belote_players_test.dart @@ -1,7 +1,7 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/player.dart'; import 'package:carg/models/players/belote_players.dart'; import 'package:flutter/material.dart'; -import 'package:carg/l10n/app_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -17,17 +17,19 @@ void main() { group('Teams are full', () { test('true', () { final belotePlayers = BelotePlayers( - playerList: ['player_1', 'player_2', 'player_3', 'player_4'], - us: 'team_1', - them: 'team_2'); + playerList: ['player_1', 'player_2', 'player_3', 'player_4'], + us: 'team_1', + them: 'team_2', + ); expect(belotePlayers.isFull(), true); }); test('false', () { final belotePlayers = BelotePlayers( - playerList: ['player_1', ' ', 'player_3', 'player_4'], - us: 'team_1', - them: 'team_2'); + playerList: ['player_1', ' ', 'player_3', 'player_4'], + us: 'team_1', + them: 'team_2', + ); expect(belotePlayers.isFull(), false); }); }); @@ -43,18 +45,19 @@ void main() { GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], - supportedLocales: const [ - Locale('fr', ''), - ], + supportedLocales: const [Locale('fr', '')], ), ); final context = tester.element(find.byType(Container)); final belotePlayers = BelotePlayers( - playerList: ['player_1', ' ', 'player_3', 'player_4'], - us: 'team_1', - them: 'team_2'); - expect(belotePlayers.getSelectedPlayersStatus(context), - 'Nous 1/2 - Eux 2/2'); + playerList: ['player_1', ' ', 'player_3', 'player_4'], + us: 'team_1', + them: 'team_2', + ); + expect( + belotePlayers.getSelectedPlayersStatus(context), + 'Nous 1/2 - Eux 2/2', + ); }); testWidgets('Teams are partially full (2/1)', (WidgetTester tester) async { @@ -67,18 +70,19 @@ void main() { GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], - supportedLocales: const [ - Locale('fr', ''), - ], + supportedLocales: const [Locale('fr', '')], ), ); final context = tester.element(find.byType(Container)); final belotePlayers = BelotePlayers( - playerList: ['player_1', 'player_2', 'player_3', ' '], - us: 'team_1', - them: 'team_2'); - expect(belotePlayers.getSelectedPlayersStatus(context), - 'Nous 2/2 - Eux 1/2'); + playerList: ['player_1', 'player_2', 'player_3', ' '], + us: 'team_1', + them: 'team_2', + ); + expect( + belotePlayers.getSelectedPlayersStatus(context), + 'Nous 2/2 - Eux 1/2', + ); }); testWidgets('Teams are full', (WidgetTester tester) async { @@ -91,40 +95,51 @@ void main() { GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], - supportedLocales: const [ - Locale('fr', ''), - ], + supportedLocales: const [Locale('fr', '')], ), ); final context = tester.element(find.byType(Container)); final belotePlayers = BelotePlayers( - playerList: ['player_1', 'player_2', 'player_3', 'player_4'], - us: 'team_1', - them: 'team_2'); - expect(belotePlayers.getSelectedPlayersStatus(context), - 'Nous 2/2 - Eux 2/2'); + playerList: ['player_1', 'player_2', 'player_3', 'player_4'], + us: 'team_1', + them: 'team_2', + ); + expect( + belotePlayers.getSelectedPlayersStatus(context), + 'Nous 2/2 - Eux 2/2', + ); }); }); group('On Selected Player', () { test('Remove one', () { final belotePlayers = BelotePlayers( - playerList: ['player_1', 'player_2', 'player_3', 'player_4'], - us: 'team_1', - them: 'team_2'); + playerList: ['player_1', 'player_2', 'player_3', 'player_4'], + us: 'team_1', + them: 'team_2', + ); belotePlayers.onSelectedPlayer(Player(id: 'player_1', owned: true)); - expect( - belotePlayers.playerList, [' ', 'player_2', 'player_3', 'player_4']); + expect(belotePlayers.playerList, [ + ' ', + 'player_2', + 'player_3', + 'player_4', + ]); }); test('Add one', () { final belotePlayers = BelotePlayers( - playerList: [' ', 'player_2', 'player_3', 'player_4'], - us: 'team_1', - them: 'team_2'); + playerList: [' ', 'player_2', 'player_3', 'player_4'], + us: 'team_1', + them: 'team_2', + ); belotePlayers.onSelectedPlayer(Player(id: 'player_5', owned: true)); - expect(belotePlayers.playerList, - ['player_5', 'player_2', 'player_3', 'player_4']); + expect(belotePlayers.playerList, [ + 'player_5', + 'player_2', + 'player_3', + 'player_4', + ]); }); }); } diff --git a/test/units/players/carg_player_object_test.dart b/test/units/players/carg_player_object_test.dart index 5be31812..21c6fea5 100644 --- a/test/units/players/carg_player_object_test.dart +++ b/test/units/players/carg_player_object_test.dart @@ -19,7 +19,8 @@ void main() { final Game game1 = CoincheBelote(); final Game game2 = FrenchBelote(); final Game game3 = Tarot( - players: TarotPlayers(playerList: ['player1', 'player2', 'player3'])); + players: TarotPlayers(playerList: ['player1', 'player2', 'player3']), + ); late FakeCargPlayerObject cargPlayerObject1; @@ -29,42 +30,62 @@ void main() { }); test('Get total played games', () { - final gameStat1 = - GameStats(gameType: GameType.COINCHE, wonGames: 3, playedGames: 10); - final gameStat2 = - GameStats(gameType: GameType.BELOTE, wonGames: 15, playedGames: 20); + final gameStat1 = GameStats( + gameType: GameType.COINCHE, + wonGames: 3, + playedGames: 10, + ); + final gameStat2 = GameStats( + gameType: GameType.BELOTE, + wonGames: 15, + playedGames: 20, + ); cargPlayerObject1.gameStatsList = [gameStat1, gameStat2]; expect(cargPlayerObject1.totalPlayedGames(), 30); }); test('Get total won games', () { - final gameStat1 = - GameStats(gameType: GameType.COINCHE, wonGames: 3, playedGames: 10); - final gameStat2 = - GameStats(gameType: GameType.BELOTE, wonGames: 15, playedGames: 20); + final gameStat1 = GameStats( + gameType: GameType.COINCHE, + wonGames: 3, + playedGames: 10, + ); + final gameStat2 = GameStats( + gameType: GameType.BELOTE, + wonGames: 15, + playedGames: 20, + ); cargPlayerObject1.gameStatsList = [gameStat1, gameStat2]; expect(cargPlayerObject1.totalWonGames(), 18); }); test('Get win percentage', () { - final gameStat1 = - GameStats(gameType: GameType.COINCHE, wonGames: 3, playedGames: 10); - final gameStat2 = - GameStats(gameType: GameType.BELOTE, wonGames: 15, playedGames: 20); + final gameStat1 = GameStats( + gameType: GameType.COINCHE, + wonGames: 3, + playedGames: 10, + ); + final gameStat2 = GameStats( + gameType: GameType.BELOTE, + wonGames: 15, + playedGames: 20, + ); cargPlayerObject1.gameStatsList = [gameStat1, gameStat2]; expect(cargPlayerObject1.totalWinPercentage(), 60.0); }); test('CargPlayerObject - test 1', () { cargPlayerObject1.incrementWonGamesByOne(game2); - expect(cargPlayerObject1.gameStatsList, - [GameStats(gameType: GameType.BELOTE, wonGames: 1, playedGames: 0)]); + expect(cargPlayerObject1.gameStatsList, [ + GameStats(gameType: GameType.BELOTE, wonGames: 1, playedGames: 0), + ]); }); test('CargPlayerObject - test 2', () { cargPlayerObject1.incrementPlayedGamesByOne(game2); - expect(cargPlayerObject1.gameStatsList, - [GameStats(gameType: GameType.BELOTE, wonGames: 0, playedGames: 1)]); + expect(cargPlayerObject1.gameStatsList, [ + GameStats(gameType: GameType.BELOTE, wonGames: 0, playedGames: 1), + ]); }); test('CargPlayerObject - test 3', () { @@ -73,7 +94,7 @@ void main() { cargPlayerObject1.incrementWonGamesByOne(game3); expect(cargPlayerObject1.gameStatsList, [ GameStats(gameType: GameType.BELOTE, wonGames: 0, playedGames: 1), - GameStats(gameType: GameType.TAROT, wonGames: 1, playedGames: 1) + GameStats(gameType: GameType.TAROT, wonGames: 1, playedGames: 1), ]); }); @@ -85,7 +106,7 @@ void main() { expect(cargPlayerObject1.gameStatsList, [ GameStats(gameType: GameType.COINCHE, wonGames: 1, playedGames: 0), GameStats(gameType: GameType.BELOTE, wonGames: 0, playedGames: 1), - GameStats(gameType: GameType.TAROT, wonGames: 1, playedGames: 1) + GameStats(gameType: GameType.TAROT, wonGames: 1, playedGames: 1), ]); }); }); diff --git a/test/units/players/player_test.dart b/test/units/players/player_test.dart index 3ab6827b..1621a968 100644 --- a/test/units/players/player_test.dart +++ b/test/units/players/player_test.dart @@ -13,22 +13,28 @@ void main() { const email = "test@test.fr"; player.gravatarProfilePicture = email; player.useGravatarProfilePicture = true; - expect(player.profilePicture, - 'https://gravatar.com/avatar/1d2ab164559aaf8a30eebf516d2f63ad?s=200'); + expect( + player.profilePicture, + 'https://gravatar.com/avatar/1d2ab164559aaf8a30eebf516d2f63ad?s=200', + ); }); test('Use normal profile picture', () { final player = Player(owned: false); - expect(player.profilePicture, - 'https://firebasestorage.googleapis.com/v0/b/carg-d3732.appspot.com/o/carg_logo.png?alt=media&token=861511da-db26-4216-8ee6-29b20c0a6852'); + expect( + player.profilePicture, + 'https://firebasestorage.googleapis.com/v0/b/carg-d3732.appspot.com/o/carg_logo.png?alt=media&token=861511da-db26-4216-8ee6-29b20c0a6852', + ); }); test('Hash email for Gravatar', () { final player = Player(owned: false); const email = "test@test.fr"; player.gravatarProfilePicture = email; - expect(player.gravatarProfilePicture, - 'https://gravatar.com/avatar/1d2ab164559aaf8a30eebf516d2f63ad?s=200'); + expect( + player.gravatarProfilePicture, + 'https://gravatar.com/avatar/1d2ab164559aaf8a30eebf516d2f63ad?s=200', + ); }); }); } diff --git a/test/units/players/tarot_players_test.dart b/test/units/players/tarot_players_test.dart index ec3f756c..a287eb54 100644 --- a/test/units/players/tarot_players_test.dart +++ b/test/units/players/tarot_players_test.dart @@ -1,9 +1,9 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/player.dart'; import 'package:carg/models/players/tarot_players.dart'; import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:carg/l10n/app_localizations.dart'; // testWidgets is used instead on test because we need a valid context to test these widgets void main() { @@ -17,18 +17,21 @@ void main() { group('Players are full', () { test('false', () { final tarotPlayers = TarotPlayers( - playerList: ['player_1', 'player_2', 'player_3', 'player_4']); + playerList: ['player_1', 'player_2', 'player_3', 'player_4'], + ); expect(tarotPlayers.isFull(), true); }); test('true', () { - final tarotPlayers = TarotPlayers(playerList: [ - 'player_1', - 'player_2', - 'player_3', - 'player_4', - 'player_5' - ]); + final tarotPlayers = TarotPlayers( + playerList: [ + 'player_1', + 'player_2', + 'player_3', + 'player_4', + 'player_5', + ], + ); expect(tarotPlayers.isFull(), true); }); }); @@ -44,15 +47,15 @@ void main() { GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], - supportedLocales: const [ - Locale('fr', ''), - ], + supportedLocales: const [Locale('fr', '')], ), ); final context = tester.element(find.byType(Container)); final tarotPlayers = TarotPlayers(playerList: ['player_1', 'player_4']); - expect(tarotPlayers.getSelectedPlayersStatus(context), - 'Joueurs.euses : 2/5'); + expect( + tarotPlayers.getSelectedPlayersStatus(context), + 'Joueurs.euses : 2/5', + ); }); testWidgets('(5/5)', (WidgetTester tester) async { @@ -65,47 +68,62 @@ void main() { GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], - supportedLocales: const [ - Locale('fr', ''), - ], + supportedLocales: const [Locale('fr', '')], ), ); final context = tester.element(find.byType(Container)); - final tarotPlayers = TarotPlayers(playerList: [ - 'player_1', - 'player_2', - 'player_3', - 'player_4', - 'player_5' - ]); - expect(tarotPlayers.getSelectedPlayersStatus(context), - 'Joueurs.euses : 5/5'); + final tarotPlayers = TarotPlayers( + playerList: [ + 'player_1', + 'player_2', + 'player_3', + 'player_4', + 'player_5', + ], + ); + expect( + tarotPlayers.getSelectedPlayersStatus(context), + 'Joueurs.euses : 5/5', + ); }); }); group('Add player', () { test('true (not full)', () { final tarotPlayers = TarotPlayers( - playerList: ['player_1', 'player_2', 'player_3', 'player_4']); + playerList: ['player_1', 'player_2', 'player_3', 'player_4'], + ); final player = Player(id: 'player_5', owned: true); tarotPlayers.onSelectedPlayer(player); - expect(tarotPlayers.playerList, - ['player_1', 'player_2', 'player_3', 'player_4', 'player_5']); + expect(tarotPlayers.playerList, [ + 'player_1', + 'player_2', + 'player_3', + 'player_4', + 'player_5', + ]); expect(player.selected, true); }); test('false (full)', () { - final tarotPlayers = TarotPlayers(playerList: [ + final tarotPlayers = TarotPlayers( + playerList: [ + 'player_1', + 'player_2', + 'player_3', + 'player_4', + 'player_5', + ], + ); + final player = Player(id: 'player_6', owned: true); + tarotPlayers.onSelectedPlayer(player); + expect(tarotPlayers.playerList, [ 'player_1', 'player_2', 'player_3', 'player_4', - 'player_5' + 'player_5', ]); - final player = Player(id: 'player_6', owned: true); - tarotPlayers.onSelectedPlayer(player); - expect(tarotPlayers.playerList, - ['player_1', 'player_2', 'player_3', 'player_4', 'player_5']); expect(player.selected, false); }); }); diff --git a/test/units/repositories/base_repository_test.dart b/test/units/repositories/base_repository_test.dart index 46a5463f..0793a42d 100644 --- a/test/units/repositories/base_repository_test.dart +++ b/test/units/repositories/base_repository_test.dart @@ -8,11 +8,12 @@ import 'package:mockito/mockito.dart'; import 'base_repository_test.mocks.dart'; class FakeBaseRepository extends BaseRepository { - FakeBaseRepository( - {required super.database, - required super.environment, - required super.provider, - super.lastFetchGameDocument}); + FakeBaseRepository({ + required super.database, + required super.environment, + required super.provider, + super.lastFetchGameDocument, + }); @override Future get(String id) { @@ -33,17 +34,22 @@ const uid = '123'; Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -72,7 +78,10 @@ void main() { when(mockCollectionReference.doc(uid)).thenReturn(mockDocumentReference); when(mockDocumentReference.delete()).thenAnswer((_) async => {}); final fakeRepository = FakeBaseRepository( - provider: instance, database: 'fake-collection', environment: 'dev'); + provider: instance, + database: 'fake-collection', + environment: 'dev', + ); await fakeRepository.delete(uid); }); @@ -80,10 +89,14 @@ void main() { var collection = 'fake-collection-dev'; when(instance.collection(collection)).thenReturn(mockCollectionReference); when(mockCollectionReference.doc(uid)).thenReturn(mockDocumentReference); - when(mockDocumentReference.update({'myField': 0})) - .thenAnswer((_) async => {}); + when( + mockDocumentReference.update({'myField': 0}), + ).thenAnswer((_) async => {}); final fakeRepository = FakeBaseRepository( - provider: instance, database: 'fake-collection', environment: 'dev'); + provider: instance, + database: 'fake-collection', + environment: 'dev', + ); await fakeRepository.updateField(uid, 'myField', 0); }); @@ -91,12 +104,17 @@ void main() { var collection = 'fake-collection-dev'; var cargObject = FakeCargObject(id: 'myId'); when(instance.collection(collection)).thenReturn(mockCollectionReference); - when(mockCollectionReference.doc('myId')) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.update({'id': 'myId'})) - .thenAnswer((_) async => {}); + when( + mockCollectionReference.doc('myId'), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.update({'id': 'myId'}), + ).thenAnswer((_) async => {}); final fakeRepository = FakeBaseRepository( - provider: instance, database: 'fake-collection', environment: 'dev'); + provider: instance, + database: 'fake-collection', + environment: 'dev', + ); await fakeRepository.update(cargObject); }); @@ -104,26 +122,39 @@ void main() { var collection = 'fake-collection-dev'; var cargObject = FakeCargObject(id: 'myId'); when(instance.collection(collection)).thenReturn(mockCollectionReference); - when(mockCollectionReference.doc('myId')) - .thenReturn(mockDocumentReference); - when(mockDocumentReference - .update({'myField': 'myValue', 'mySecondField': 0})) - .thenAnswer((_) async => {}); + when( + mockCollectionReference.doc('myId'), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.update({ + 'myField': 'myValue', + 'mySecondField': 0, + }), + ).thenAnswer((_) async => {}); final fakeRepository = FakeBaseRepository( - provider: instance, database: 'fake-collection', environment: 'dev'); - await fakeRepository.partialUpdate( - cargObject, {'myField': 'myValue', 'mySecondField': 0}); + provider: instance, + database: 'fake-collection', + environment: 'dev', + ); + await fakeRepository.partialUpdate(cargObject, { + 'myField': 'myValue', + 'mySecondField': 0, + }); }); test('Create', () async { var collection = 'fake-collection-dev'; var cargObject = FakeCargObject(id: 'myId'); when(instance.collection(collection)).thenReturn(mockCollectionReference); - when(mockCollectionReference.add({'id': 'myId'})) - .thenAnswer((_) async => mockDocumentReference); + when( + mockCollectionReference.add({'id': 'myId'}), + ).thenAnswer((_) async => mockDocumentReference); when(mockDocumentReference.id).thenReturn('myId'); final fakeRepository = FakeBaseRepository( - provider: instance, database: 'fake-collection', environment: 'dev'); + provider: instance, + database: 'fake-collection', + environment: 'dev', + ); final id = await fakeRepository.create(cargObject); expect(id, 'myId'); }); diff --git a/test/units/repositories/base_repository_test.mocks.dart b/test/units/repositories/base_repository_test.mocks.dart index fac8c4d8..3437c7cf 100644 --- a/test/units/repositories/base_repository_test.mocks.dart +++ b/test/units/repositories/base_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'base_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/game/coinche/coinche_belote_game_repository_test.dart b/test/units/repositories/game/coinche/coinche_belote_game_repository_test.dart index 0025ce5d..931212e4 100644 --- a/test/units/repositories/game/coinche/coinche_belote_game_repository_test.dart +++ b/test/units/repositories/game/coinche/coinche_belote_game_repository_test.dart @@ -16,23 +16,28 @@ const pageSize = 10; const jsonCoincheBelote = { 'starting_date': '2022-04-10 00:00:00.000', 'players': { - "player_list": ['p1', 'p2'] - } + "player_list": ['p1', 'p2'], + }, }; Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -45,9 +50,10 @@ void main() { MockCollectionReference>(); final game = CoincheBelote( - id: uid, - startingDate: DateTime.parse('2022-04-10 00:00:00.000'), - players: BelotePlayers(playerList: ['p1', 'p2'])); + id: uid, + startingDate: DateTime.parse('2022-04-10 00:00:00.000'), + players: BelotePlayers(playerList: ['p1', 'p2']), + ); setUp(() { reset(instance); @@ -63,43 +69,57 @@ void main() { group('Get Coinche Game', () { test('DEV', () async { const collection = 'coinche-game-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonCoincheBelote); when(mockDocumentSnapshot.id).thenReturn(uid); - final coincheBeloteGameRepository = - CoincheBeloteGameRepository(provider: instance); + final coincheBeloteGameRepository = CoincheBeloteGameRepository( + provider: instance, + ); final coincheBelote = await coincheBeloteGameRepository.get(uid); expect(coincheBelote, game); }); test('PROD', () async { const collection = 'coinche-game-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonCoincheBelote); when(mockDocumentSnapshot.id).thenReturn(uid); final coincheBeloteGameRepository = CoincheBeloteGameRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); final coincheBelote = await coincheBeloteGameRepository.get(uid); expect(coincheBelote, game); }); test('Throw exception', () async { const collection = 'coinche-game-prod'; - when(instance.collection(collection)) - .thenThrow(FirebaseException(plugin: 'test', message: 'test')); + when( + instance.collection(collection), + ).thenThrow(FirebaseException(plugin: 'test', message: 'test')); final coincheBeloteGameRepository = CoincheBeloteGameRepository( - provider: instance, environment: 'prod'); - expect(coincheBeloteGameRepository.get(uid), - throwsA(isA())); + provider: instance, + environment: 'prod', + ); + expect( + coincheBeloteGameRepository.get(uid), + throwsA(isA()), + ); }); }); @@ -110,26 +130,39 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final coincheBeloteGameRepository = CoincheBeloteGameRepository( - provider: instance, lastFetchGameDocument: mockDocumentSnapshot); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + ); expect( - await coincheBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await coincheBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('PRD', () async { const collection = 'coinche-game-prod'; @@ -137,78 +170,114 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final coincheBeloteGameRepository = CoincheBeloteGameRepository( - provider: instance, - lastFetchGameDocument: mockDocumentSnapshot, - environment: 'prod'); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + environment: 'prod', + ); expect( - await coincheBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await coincheBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('Last fetched document not null', () async { const collection = 'coinche-game-prod'; final mockQueryFromOrderBy = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final coincheBeloteGameRepository = CoincheBeloteGameRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); expect( - await coincheBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await coincheBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('Last fetched document not null and return data', () async { const collection = 'coinche-game-prod'; final mockQueryFromOrderBy = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonCoincheBelote); when(mockQueryDocumentSnapshot.id).thenReturn(uid); final coincheBeloteGameRepository = CoincheBeloteGameRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); expect( - await coincheBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - [game]); + await coincheBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [game], + ); }); }); }); diff --git a/test/units/repositories/game/coinche/coinche_belote_game_repository_test.mocks.dart b/test/units/repositories/game/coinche/coinche_belote_game_repository_test.mocks.dart index 90a42258..ff90d614 100644 --- a/test/units/repositories/game/coinche/coinche_belote_game_repository_test.mocks.dart +++ b/test/units/repositories/game/coinche/coinche_belote_game_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'coinche_belote_game_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/game/contree/contree_belote_game_repository_test.dart b/test/units/repositories/game/contree/contree_belote_game_repository_test.dart index 9297b2c9..7740d7f4 100644 --- a/test/units/repositories/game/contree/contree_belote_game_repository_test.dart +++ b/test/units/repositories/game/contree/contree_belote_game_repository_test.dart @@ -16,23 +16,28 @@ const pageSize = 10; const jsonContreeBelote = { 'starting_date': '2022-04-10 00:00:00.000', 'players': { - "player_list": ['p1', 'p2'] - } + "player_list": ['p1', 'p2'], + }, }; Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -45,9 +50,10 @@ void main() { MockCollectionReference>(); final game = ContreeBelote( - id: uid, - startingDate: DateTime.parse('2022-04-10 00:00:00.000'), - players: BelotePlayers(playerList: ['p1', 'p2'])); + id: uid, + startingDate: DateTime.parse('2022-04-10 00:00:00.000'), + players: BelotePlayers(playerList: ['p1', 'p2']), + ); setUp(() { reset(instance); @@ -63,43 +69,57 @@ void main() { group('Get Contree Game', () { test('DEV', () async { const collection = 'contree-game-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonContreeBelote); when(mockDocumentSnapshot.id).thenReturn(uid); - final contreeBeloteGameRepository = - ContreeBeloteGameRepository(provider: instance); + final contreeBeloteGameRepository = ContreeBeloteGameRepository( + provider: instance, + ); final contreeBelote = await contreeBeloteGameRepository.get(uid); expect(contreeBelote, game); }); test('PROD', () async { const collection = 'contree-game-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonContreeBelote); when(mockDocumentSnapshot.id).thenReturn(uid); final contreeBeloteGameRepository = ContreeBeloteGameRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); final contreeBelote = await contreeBeloteGameRepository.get(uid); expect(contreeBelote, game); }); test('Throw exception', () async { const collection = 'contree-game-prod'; - when(instance.collection(collection)) - .thenThrow(FirebaseException(plugin: 'test', message: 'test')); + when( + instance.collection(collection), + ).thenThrow(FirebaseException(plugin: 'test', message: 'test')); final contreeBeloteGameRepository = ContreeBeloteGameRepository( - provider: instance, environment: 'prod'); - expect(contreeBeloteGameRepository.get(uid), - throwsA(isA())); + provider: instance, + environment: 'prod', + ); + expect( + contreeBeloteGameRepository.get(uid), + throwsA(isA()), + ); }); }); @@ -110,26 +130,39 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final contreeBeloteGameRepository = ContreeBeloteGameRepository( - provider: instance, lastFetchGameDocument: mockDocumentSnapshot); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + ); expect( - await contreeBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await contreeBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('PRD', () async { const collection = 'contree-game-prod'; @@ -137,78 +170,114 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final contreeBeloteGameRepository = ContreeBeloteGameRepository( - provider: instance, - lastFetchGameDocument: mockDocumentSnapshot, - environment: 'prod'); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + environment: 'prod', + ); expect( - await contreeBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await contreeBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('Last fetched document not null', () async { const collection = 'contree-game-prod'; final mockQueryFromOrderBy = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final contreeBeloteGameRepository = ContreeBeloteGameRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); expect( - await contreeBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await contreeBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('Last fetched document not null and return data', () async { const collection = 'contree-game-prod'; final mockQueryFromOrderBy = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonContreeBelote); when(mockQueryDocumentSnapshot.id).thenReturn(uid); final contreeBeloteGameRepository = ContreeBeloteGameRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); expect( - await contreeBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - [game]); + await contreeBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [game], + ); }); }); }); diff --git a/test/units/repositories/game/contree/contree_belote_game_repository_test.mocks.dart b/test/units/repositories/game/contree/contree_belote_game_repository_test.mocks.dart index bd4fdb7d..bd013601 100644 --- a/test/units/repositories/game/contree/contree_belote_game_repository_test.mocks.dart +++ b/test/units/repositories/game/contree/contree_belote_game_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'contree_belote_game_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/game/french_belote/french_belote_game_repository_test.dart b/test/units/repositories/game/french_belote/french_belote_game_repository_test.dart index ff5ef8a3..48cab71a 100644 --- a/test/units/repositories/game/french_belote/french_belote_game_repository_test.dart +++ b/test/units/repositories/game/french_belote/french_belote_game_repository_test.dart @@ -16,23 +16,28 @@ const pageSize = 10; const jsonFrenchBelote = { 'starting_date': '2022-04-10 00:00:00.000', 'players': { - "player_list": ['p1', 'p2'] - } + "player_list": ['p1', 'p2'], + }, }; Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -45,9 +50,10 @@ void main() { MockCollectionReference>(); final game = FrenchBelote( - id: uid, - startingDate: DateTime.parse('2022-04-10 00:00:00.000'), - players: BelotePlayers(playerList: ['p1', 'p2'])); + id: uid, + startingDate: DateTime.parse('2022-04-10 00:00:00.000'), + players: BelotePlayers(playerList: ['p1', 'p2']), + ); setUp(() { reset(instance); @@ -63,43 +69,57 @@ void main() { group('Get French belote Game', () { test('DEV', () async { const collection = 'belote-game-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonFrenchBelote); when(mockDocumentSnapshot.id).thenReturn(uid); - final frenchBeloteGameRepository = - FrenchBeloteGameRepository(provider: instance); + final frenchBeloteGameRepository = FrenchBeloteGameRepository( + provider: instance, + ); final frenchBelote = await frenchBeloteGameRepository.get(uid); expect(frenchBelote, game); }); test('PROD', () async { const collection = 'belote-game-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonFrenchBelote); when(mockDocumentSnapshot.id).thenReturn(uid); - final frenchBeloteGameRepository = - FrenchBeloteGameRepository(provider: instance, environment: 'prod'); + final frenchBeloteGameRepository = FrenchBeloteGameRepository( + provider: instance, + environment: 'prod', + ); final frenchBelote = await frenchBeloteGameRepository.get(uid); expect(frenchBelote, game); }); test('Throw exception', () async { const collection = 'belote-game-prod'; - when(instance.collection(collection)) - .thenThrow(FirebaseException(plugin: 'test', message: 'test')); - final frenchBeloteGameRepository = - FrenchBeloteGameRepository(provider: instance, environment: 'prod'); - expect(frenchBeloteGameRepository.get(uid), - throwsA(isA())); + when( + instance.collection(collection), + ).thenThrow(FirebaseException(plugin: 'test', message: 'test')); + final frenchBeloteGameRepository = FrenchBeloteGameRepository( + provider: instance, + environment: 'prod', + ); + expect( + frenchBeloteGameRepository.get(uid), + throwsA(isA()), + ); }); }); @@ -110,26 +130,39 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final frenchBeloteGameRepository = FrenchBeloteGameRepository( - provider: instance, lastFetchGameDocument: mockDocumentSnapshot); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + ); expect( - await frenchBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await frenchBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('PRD', () async { const collection = 'belote-game-prod'; @@ -137,78 +170,114 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final frenchBeloteGameRepository = FrenchBeloteGameRepository( - provider: instance, - lastFetchGameDocument: mockDocumentSnapshot, - environment: 'prod'); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + environment: 'prod', + ); expect( - await frenchBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await frenchBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('Last fetched document not null', () async { const collection = 'belote-game-prod'; final mockQueryFromOrderBy = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); - final frenchBeloteGameRepository = - FrenchBeloteGameRepository(provider: instance, environment: 'prod'); + final frenchBeloteGameRepository = FrenchBeloteGameRepository( + provider: instance, + environment: 'prod', + ); expect( - await frenchBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - []); + await frenchBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [], + ); }); test('Last fetched document not null and return data', () async { const collection = 'belote-game-prod'; final mockQueryFromOrderBy = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonFrenchBelote); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final frenchBeloteGameRepository = - FrenchBeloteGameRepository(provider: instance, environment: 'prod'); + final frenchBeloteGameRepository = FrenchBeloteGameRepository( + provider: instance, + environment: 'prod', + ); expect( - await frenchBeloteGameRepository.getAllGamesOfPlayer( - playerId, pageSize), - [game]); + await frenchBeloteGameRepository.getAllGamesOfPlayer( + playerId, + pageSize, + ), + [game], + ); }); }); }); diff --git a/test/units/repositories/game/french_belote/french_belote_game_repository_test.mocks.dart b/test/units/repositories/game/french_belote/french_belote_game_repository_test.mocks.dart index 0f702b00..462db85a 100644 --- a/test/units/repositories/game/french_belote/french_belote_game_repository_test.mocks.dart +++ b/test/units/repositories/game/french_belote/french_belote_game_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'french_belote_game_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/game/tarot/tarot_game_repository_test.dart b/test/units/repositories/game/tarot/tarot_game_repository_test.dart index e9e02370..597b53cf 100644 --- a/test/units/repositories/game/tarot/tarot_game_repository_test.dart +++ b/test/units/repositories/game/tarot/tarot_game_repository_test.dart @@ -16,23 +16,28 @@ const pageSize = 10; const jsonTarot = { 'starting_date': '2022-04-10 00:00:00.000', 'players': { - "player_list": ['p1', 'p2'] - } + "player_list": ['p1', 'p2'], + }, }; Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -45,9 +50,10 @@ void main() { MockCollectionReference>(); final game = Tarot( - id: uid, - startingDate: DateTime.parse('2022-04-10 00:00:00.000'), - players: TarotPlayers(playerList: ['p1', 'p2'])); + id: uid, + startingDate: DateTime.parse('2022-04-10 00:00:00.000'), + players: TarotPlayers(playerList: ['p1', 'p2']), + ); setUp(() { reset(instance); @@ -63,12 +69,15 @@ void main() { group('Get Tarot Game', () { test('DEV', () async { const collection = 'tarot-game-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonTarot); when(mockDocumentSnapshot.id).thenReturn(uid); final tarotRepository = TarotGameRepository(provider: instance); @@ -77,26 +86,34 @@ void main() { }); test('PROD', () async { const collection = 'tarot-game-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonTarot); when(mockDocumentSnapshot.id).thenReturn(uid); - final tarotRepository = - TarotGameRepository(provider: instance, environment: 'prod'); + final tarotRepository = TarotGameRepository( + provider: instance, + environment: 'prod', + ); final tarot = await tarotRepository.get(uid); expect(tarot, game); }); test('Throw exception', () async { const collection = 'tarot-game-prod'; - when(instance.collection(collection)) - .thenThrow(FirebaseException(plugin: 'test', message: 'test')); - final tarotRepository = - TarotGameRepository(provider: instance, environment: 'prod'); + when( + instance.collection(collection), + ).thenThrow(FirebaseException(plugin: 'test', message: 'test')); + final tarotRepository = TarotGameRepository( + provider: instance, + environment: 'prod', + ); expect(tarotRepository.get(uid), throwsA(isA())); }); }); @@ -108,24 +125,36 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final tarotRepository = TarotGameRepository( - provider: instance, lastFetchGameDocument: mockDocumentSnapshot); - expect(await tarotRepository.getAllGamesOfPlayer(playerId, pageSize), - []); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + ); + expect( + await tarotRepository.getAllGamesOfPlayer(playerId, pageSize), + [], + ); }); test('PRD', () async { const collection = 'tarot-game-prod'; @@ -133,84 +162,121 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final tarotRepository = TarotGameRepository( - provider: instance, - lastFetchGameDocument: mockDocumentSnapshot, - environment: 'prod'); - expect(await tarotRepository.getAllGamesOfPlayer(playerId, pageSize), - []); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + environment: 'prod', + ); + expect( + await tarotRepository.getAllGamesOfPlayer(playerId, pageSize), + [], + ); }); test('Last fetched document not null', () async { const collection = 'tarot-game-prod'; final mockQueryFromOrderBy = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); - final tarotRepository = - TarotGameRepository(provider: instance, environment: 'prod'); - expect(await tarotRepository.getAllGamesOfPlayer(playerId, pageSize), - []); + final tarotRepository = TarotGameRepository( + provider: instance, + environment: 'prod', + ); + expect( + await tarotRepository.getAllGamesOfPlayer(playerId, pageSize), + [], + ); }); test('Last fetched document not null and return data', () async { const collection = 'tarot-game-prod'; final mockQueryFromOrderBy = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players.player_list', - arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.orderBy('starting_date', descending: true)) - .thenReturn(mockQueryFromOrderBy); - when(mockQueryFromOrderBy.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where( + 'players.player_list', + arrayContains: playerId, + ), + ).thenReturn(mockQuery); + when( + mockQuery.orderBy('starting_date', descending: true), + ).thenReturn(mockQueryFromOrderBy); + when( + mockQueryFromOrderBy.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonTarot); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final tarotRepository = - TarotGameRepository(provider: instance, environment: 'prod'); - expect(await tarotRepository.getAllGamesOfPlayer(playerId, pageSize), - [game]); + final tarotRepository = TarotGameRepository( + provider: instance, + environment: 'prod', + ); + expect( + await tarotRepository.getAllGamesOfPlayer(playerId, pageSize), + [game], + ); }); test('Firebase Exception', () async { const collection = 'tarot-game-prod'; - when(instance.collection(collection)) - .thenThrow(FirebaseException(plugin: 'error', message: 'error')); + when( + instance.collection(collection), + ).thenThrow(FirebaseException(plugin: 'error', message: 'error')); final tarotRepository = TarotGameRepository( - provider: instance, - environment: 'prod', - lastFetchGameDocument: mockDocumentSnapshot); - expect(tarotRepository.getAllGamesOfPlayer(playerId, pageSize), - throwsA(isA())); + provider: instance, + environment: 'prod', + lastFetchGameDocument: mockDocumentSnapshot, + ); + expect( + tarotRepository.getAllGamesOfPlayer(playerId, pageSize), + throwsA(isA()), + ); }); }); }); diff --git a/test/units/repositories/game/tarot/tarot_game_repository_test.mocks.dart b/test/units/repositories/game/tarot/tarot_game_repository_test.mocks.dart index cee5a424..301a8be3 100644 --- a/test/units/repositories/game/tarot/tarot_game_repository_test.mocks.dart +++ b/test/units/repositories/game/tarot/tarot_game_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'tarot_game_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/iap_repository_test.dart b/test/units/repositories/iap_repository_test.dart index 8395caca..580c4ce9 100644 --- a/test/units/repositories/iap_repository_test.dart +++ b/test/units/repositories/iap_repository_test.dart @@ -20,31 +20,37 @@ const jsonIAP = { 'purchase_date': '2022-09-23T00:00:00.000Z', 'status': 'purchased', 'type': 'nonSubscription', - 'user_id': 'FQcEdrEwghWU1p2AKO8MVfh8pe72' + 'user_id': 'FQcEdrEwghWU1p2AKO8MVfh8pe72', }; final expectedIAP = NonSubscriptionPurchase( - id: '123', - iapSource: IAPSourceEnum.google_play, - orderId: 'GPA.3309-0924-5376-12025', - productId: 'carg.free.ads', - userId: 'FQcEdrEwghWU1p2AKO8MVfh8pe72', - purchaseDate: DateTime.parse('2022-09-23T00:00:00.000Z'), - type: ProductTypeEnum.nonSubscription, - status: NonSubscriptionStatusEnum.purchased); + id: '123', + iapSource: IAPSourceEnum.google_play, + orderId: 'GPA.3309-0924-5376-12025', + productId: 'carg.free.ads', + userId: 'FQcEdrEwghWU1p2AKO8MVfh8pe72', + purchaseDate: DateTime.parse('2022-09-23T00:00:00.000Z'), + type: ProductTypeEnum.nonSubscription, + status: NonSubscriptionStatusEnum.purchased, +); Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -70,11 +76,13 @@ void main() { group('Get IAP', () { test('DEV', () async { var collection = 'iap-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); when(mockCollectionReference.doc(id)).thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonIAP); when(mockDocumentSnapshot.id).thenReturn(id); final iapRepository = IAPRepository(provider: instance); @@ -83,15 +91,19 @@ void main() { }); test('PRD', () async { var collection = 'iap-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); when(mockCollectionReference.doc(id)).thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonIAP); when(mockDocumentSnapshot.id).thenReturn(id); - final iapRepository = - IAPRepository(provider: instance, environment: 'prod'); + final iapRepository = IAPRepository( + provider: instance, + environment: 'prod', + ); final iap = await iapRepository.get(id); expect(iap, expectedIAP); }); @@ -100,10 +112,12 @@ void main() { group('Get by userId', () { test('DEV', () async { var collection = 'iap-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('user_id', isEqualTo: userId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('user_id', isEqualTo: userId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonIAP); @@ -114,16 +128,20 @@ void main() { }); test('PROD', () async { var collection = 'iap-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('user_id', isEqualTo: userId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('user_id', isEqualTo: userId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonIAP); when(mockQueryDocumentSnapshot.id).thenReturn(id); - final iapRepository = - IAPRepository(provider: instance, environment: 'prod'); + final iapRepository = IAPRepository( + provider: instance, + environment: 'prod', + ); final iap = await iapRepository.getByUserId(userId); expect(iap, expectedIAP); }); @@ -133,14 +151,18 @@ void main() { group('Update', () { test('DEV', () async { var collection = 'iap-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(id)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.update(jsonIAP)) - .thenAnswer((_) async => {}); - when(mockCollectionReference.where('user_id', isEqualTo: userId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(id), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.update(jsonIAP), + ).thenAnswer((_) async => {}); + when( + mockCollectionReference.where('user_id', isEqualTo: userId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonIAP); @@ -151,20 +173,26 @@ void main() { }); test('PROD', () async { var collection = 'iap-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(id)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.update(jsonIAP)) - .thenAnswer((_) async => {}); - when(mockCollectionReference.where('user_id', isEqualTo: userId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(id), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.update(jsonIAP), + ).thenAnswer((_) async => {}); + when( + mockCollectionReference.where('user_id', isEqualTo: userId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonIAP); when(mockQueryDocumentSnapshot.id).thenReturn(id); - final iapRepository = - IAPRepository(provider: instance, environment: 'prod'); + final iapRepository = IAPRepository( + provider: instance, + environment: 'prod', + ); final iapId = await iapRepository.createOrUpdate(expectedIAP); expect(iapId, id); }); @@ -172,13 +200,16 @@ void main() { group('Create', () { test('DEV', () async { var collection = 'iap-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.add(jsonIAP)) - .thenAnswer((_) async => mockDocumentReference); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.add(jsonIAP), + ).thenAnswer((_) async => mockDocumentReference); when(mockDocumentReference.id).thenReturn(id); - when(mockCollectionReference.where('user_id', isEqualTo: userId)) - .thenReturn(mockQuery); + when( + mockCollectionReference.where('user_id', isEqualTo: userId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final iapRepository = IAPRepository(provider: instance); @@ -187,18 +218,23 @@ void main() { }); test('PROD', () async { var collection = 'iap-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.add(jsonIAP)) - .thenAnswer((_) async => mockDocumentReference); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.add(jsonIAP), + ).thenAnswer((_) async => mockDocumentReference); when(mockDocumentReference.id).thenReturn(id); - when(mockCollectionReference.where('user_id', isEqualTo: userId)) - .thenReturn(mockQuery); + when( + mockCollectionReference.where('user_id', isEqualTo: userId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); - final iapRepository = - IAPRepository(provider: instance, environment: 'prod'); + final iapRepository = IAPRepository( + provider: instance, + environment: 'prod', + ); final iapId = await iapRepository.createOrUpdate(expectedIAP); expect(iapId, id); }); diff --git a/test/units/repositories/iap_repository_test.mocks.dart b/test/units/repositories/iap_repository_test.mocks.dart index 8057055c..5ef1b7e5 100644 --- a/test/units/repositories/iap_repository_test.mocks.dart +++ b/test/units/repositories/iap_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'iap_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/player/player_repository_test.dart b/test/units/repositories/player/player_repository_test.dart index 0eb80d26..6afe5bfe 100644 --- a/test/units/repositories/player/player_repository_test.dart +++ b/test/units/repositories/player/player_repository_test.dart @@ -14,24 +14,33 @@ const jsonPlayer = { 'owned': false, 'profile_picture': 'https://firebasestorage.googleapis.com/v0/b/carg-d3732.appspot.com/o/carg_logo.png?alt=media&token=861511da-db26-4216-8ee6-29b20c0a6852', - 'linked_user_id': userId + 'linked_user_id': userId, }; -final expectedPlayer = - Player(id: uid, userName: 'Test', owned: false, linkedUserId: userId); +final expectedPlayer = Player( + id: uid, + userName: 'Test', + owned: false, + linkedUserId: userId, +); Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -57,12 +66,15 @@ void main() { group('Get Player', () { test('DEV', () async { var collection = 'player-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonPlayer); when(mockDocumentSnapshot.id).thenReturn(uid); final playerRepository = PlayerRepository(provider: instance); @@ -71,16 +83,21 @@ void main() { }); test('PROD', () async { var collection = 'player-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonPlayer); when(mockDocumentSnapshot.id).thenReturn(uid); - final playerRepository = - PlayerRepository(provider: instance, environment: 'prod'); + final playerRepository = PlayerRepository( + provider: instance, + environment: 'prod', + ); final player = await playerRepository.get(uid); expect(player, expectedPlayer); }); @@ -89,10 +106,12 @@ void main() { group('Get Player of User', () { test('DEV', () async { var collection = 'player-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('linked_user_id', isEqualTo: userId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('linked_user_id', isEqualTo: userId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonPlayer); @@ -103,16 +122,20 @@ void main() { }); test('PROD', () async { var collection = 'player-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('linked_user_id', isEqualTo: userId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('linked_user_id', isEqualTo: userId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonPlayer); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final playerRepository = - PlayerRepository(provider: instance, environment: 'prod'); + final playerRepository = PlayerRepository( + provider: instance, + environment: 'prod', + ); final player = await playerRepository.getPlayerOfUser(userId); expect(player, expectedPlayer); }); diff --git a/test/units/repositories/player/player_repository_test.mocks.dart b/test/units/repositories/player/player_repository_test.mocks.dart index 0b77e5a4..8b10787e 100644 --- a/test/units/repositories/player/player_repository_test.mocks.dart +++ b/test/units/repositories/player/player_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'player_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/score/coinche_belote/coinche_belote_score_repository_test.dart b/test/units/repositories/score/coinche_belote/coinche_belote_score_repository_test.dart index 6de28109..41c95fad 100644 --- a/test/units/repositories/score/coinche_belote/coinche_belote_score_repository_test.dart +++ b/test/units/repositories/score/coinche_belote/coinche_belote_score_repository_test.dart @@ -10,25 +10,27 @@ import 'coinche_belote_score_repository_test.mocks.dart'; const uid = '123'; const userId = '123_user'; const gameId = '123_game'; -const coincheBeloteScoreJson = { - 'id': uid, - 'game': gameId, -}; +const coincheBeloteScoreJson = {'id': uid, 'game': gameId}; final expectedScore = CoincheBeloteScore(id: uid, game: gameId); Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query, -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -54,31 +56,40 @@ void main() { group('Get Player', () { test('DEV', () async { var collection = 'coinche-score-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(coincheBeloteScoreJson); when(mockDocumentSnapshot.id).thenReturn(uid); - final coincheBeloteScoreRepository = - CoincheBeloteScoreRepository(provider: instance); + final coincheBeloteScoreRepository = CoincheBeloteScoreRepository( + provider: instance, + ); final coincheBeloteScore = await coincheBeloteScoreRepository.get(uid); expect(coincheBeloteScore, expectedScore); }); test('PROD', () async { var collection = 'coinche-score-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(coincheBeloteScoreJson); when(mockDocumentSnapshot.id).thenReturn(uid); final coincheBeloteScoreRepository = CoincheBeloteScoreRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); final coincheBeloteScore = await coincheBeloteScoreRepository.get(uid); expect(coincheBeloteScore, expectedScore); }); @@ -87,36 +98,45 @@ void main() { group('Get Score by game', () { test('DEV', () async { var collection = 'coinche-score-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('game', isEqualTo: gameId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('game', isEqualTo: gameId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); - when(mockQueryDocumentSnapshot.data()) - .thenReturn(coincheBeloteScoreJson); + when( + mockQueryDocumentSnapshot.data(), + ).thenReturn(coincheBeloteScoreJson); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final coincheBeloteScoreRepository = - CoincheBeloteScoreRepository(provider: instance); - final coincheBeloteScore = - await coincheBeloteScoreRepository.getScoreByGame(gameId); + final coincheBeloteScoreRepository = CoincheBeloteScoreRepository( + provider: instance, + ); + final coincheBeloteScore = await coincheBeloteScoreRepository + .getScoreByGame(gameId); expect(coincheBeloteScore, expectedScore); }); test('PROD', () async { var collection = 'coinche-score-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('game', isEqualTo: gameId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('game', isEqualTo: gameId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); - when(mockQueryDocumentSnapshot.data()) - .thenReturn(coincheBeloteScoreJson); + when( + mockQueryDocumentSnapshot.data(), + ).thenReturn(coincheBeloteScoreJson); when(mockQueryDocumentSnapshot.id).thenReturn(uid); final coincheBeloteScoreRepository = CoincheBeloteScoreRepository( - provider: instance, environment: 'prod'); - final coincheBeloteScore = - await coincheBeloteScoreRepository.getScoreByGame(gameId); + provider: instance, + environment: 'prod', + ); + final coincheBeloteScore = await coincheBeloteScoreRepository + .getScoreByGame(gameId); expect(coincheBeloteScore, expectedScore); }); }); diff --git a/test/units/repositories/score/coinche_belote/coinche_belote_score_repository_test.mocks.dart b/test/units/repositories/score/coinche_belote/coinche_belote_score_repository_test.mocks.dart index 2c4285c7..69261a88 100644 --- a/test/units/repositories/score/coinche_belote/coinche_belote_score_repository_test.mocks.dart +++ b/test/units/repositories/score/coinche_belote/coinche_belote_score_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'coinche_belote_score_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/score/contree_belote/contree_belote_score_repository_test.dart b/test/units/repositories/score/contree_belote/contree_belote_score_repository_test.dart index f4acb603..a6a1d5e6 100644 --- a/test/units/repositories/score/contree_belote/contree_belote_score_repository_test.dart +++ b/test/units/repositories/score/contree_belote/contree_belote_score_repository_test.dart @@ -10,25 +10,27 @@ import 'contree_belote_score_repository_test.mocks.dart'; const uid = '123'; const userId = '123_user'; const gameId = '123_game'; -const contreeBeloteScoreJson = { - 'id': uid, - 'game': gameId, -}; +const contreeBeloteScoreJson = {'id': uid, 'game': gameId}; final expectedScore = ContreeBeloteScore(id: uid, game: gameId); Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query, -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -54,31 +56,40 @@ void main() { group('Get Player', () { test('DEV', () async { var collection = 'contree-score-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(contreeBeloteScoreJson); when(mockDocumentSnapshot.id).thenReturn(uid); - final contreeBeloteScoreRepository = - ContreeBeloteScoreRepository(provider: instance); + final contreeBeloteScoreRepository = ContreeBeloteScoreRepository( + provider: instance, + ); final contreeBeloteScore = await contreeBeloteScoreRepository.get(uid); expect(contreeBeloteScore, expectedScore); }); test('PROD', () async { var collection = 'contree-score-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(contreeBeloteScoreJson); when(mockDocumentSnapshot.id).thenReturn(uid); final contreeBeloteScoreRepository = ContreeBeloteScoreRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); final contreeBeloteScore = await contreeBeloteScoreRepository.get(uid); expect(contreeBeloteScore, expectedScore); }); @@ -87,36 +98,45 @@ void main() { group('Get Score by game', () { test('DEV', () async { var collection = 'contree-score-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('game', isEqualTo: gameId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('game', isEqualTo: gameId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); - when(mockQueryDocumentSnapshot.data()) - .thenReturn(contreeBeloteScoreJson); + when( + mockQueryDocumentSnapshot.data(), + ).thenReturn(contreeBeloteScoreJson); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final contreeBeloteScoreRepository = - ContreeBeloteScoreRepository(provider: instance); - final contreeBeloteScore = - await contreeBeloteScoreRepository.getScoreByGame(gameId); + final contreeBeloteScoreRepository = ContreeBeloteScoreRepository( + provider: instance, + ); + final contreeBeloteScore = await contreeBeloteScoreRepository + .getScoreByGame(gameId); expect(contreeBeloteScore, expectedScore); }); test('PROD', () async { var collection = 'contree-score-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('game', isEqualTo: gameId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('game', isEqualTo: gameId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); - when(mockQueryDocumentSnapshot.data()) - .thenReturn(contreeBeloteScoreJson); + when( + mockQueryDocumentSnapshot.data(), + ).thenReturn(contreeBeloteScoreJson); when(mockQueryDocumentSnapshot.id).thenReturn(uid); final contreeBeloteScoreRepository = ContreeBeloteScoreRepository( - provider: instance, environment: 'prod'); - final contreeBeloteScore = - await contreeBeloteScoreRepository.getScoreByGame(gameId); + provider: instance, + environment: 'prod', + ); + final contreeBeloteScore = await contreeBeloteScoreRepository + .getScoreByGame(gameId); expect(contreeBeloteScore, expectedScore); }); }); diff --git a/test/units/repositories/score/contree_belote/contree_belote_score_repository_test.mocks.dart b/test/units/repositories/score/contree_belote/contree_belote_score_repository_test.mocks.dart index 69ad4f45..3bcbf2a5 100644 --- a/test/units/repositories/score/contree_belote/contree_belote_score_repository_test.mocks.dart +++ b/test/units/repositories/score/contree_belote/contree_belote_score_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'contree_belote_score_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/score/french_belote/french_belote_score_repository_test.dart b/test/units/repositories/score/french_belote/french_belote_score_repository_test.dart index 7ae4501c..5de1d5ad 100644 --- a/test/units/repositories/score/french_belote/french_belote_score_repository_test.dart +++ b/test/units/repositories/score/french_belote/french_belote_score_repository_test.dart @@ -10,25 +10,27 @@ import 'french_belote_score_repository_test.mocks.dart'; const uid = '123'; const userId = '123_user'; const gameId = '123_game'; -const frenchBeloteScoreJson = { - 'id': uid, - 'game': gameId, -}; +const frenchBeloteScoreJson = {'id': uid, 'game': gameId}; final expectedScore = FrenchBeloteScore(id: uid, game: gameId); Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query, -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -54,31 +56,40 @@ void main() { group('Get Player', () { test('DEV', () async { var collection = 'belote-score-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(frenchBeloteScoreJson); when(mockDocumentSnapshot.id).thenReturn(uid); - final frenchBeloteScoreRepository = - FrenchBeloteScoreRepository(provider: instance); + final frenchBeloteScoreRepository = FrenchBeloteScoreRepository( + provider: instance, + ); final frenchBeloteScore = await frenchBeloteScoreRepository.get(uid); expect(frenchBeloteScore, expectedScore); }); test('PROD', () async { var collection = 'belote-score-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(frenchBeloteScoreJson); when(mockDocumentSnapshot.id).thenReturn(uid); final frenchBeloteScoreRepository = FrenchBeloteScoreRepository( - provider: instance, environment: 'prod'); + provider: instance, + environment: 'prod', + ); final frenchBeloteScore = await frenchBeloteScoreRepository.get(uid); expect(frenchBeloteScore, expectedScore); }); @@ -87,36 +98,45 @@ void main() { group('Get Score by game', () { test('DEV', () async { var collection = 'belote-score-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('game', isEqualTo: gameId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('game', isEqualTo: gameId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); - when(mockQueryDocumentSnapshot.data()) - .thenReturn(frenchBeloteScoreJson); + when( + mockQueryDocumentSnapshot.data(), + ).thenReturn(frenchBeloteScoreJson); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final frenchBeloteScoreRepository = - FrenchBeloteScoreRepository(provider: instance); - final frenchBeloteScore = - await frenchBeloteScoreRepository.getScoreByGame(gameId); + final frenchBeloteScoreRepository = FrenchBeloteScoreRepository( + provider: instance, + ); + final frenchBeloteScore = await frenchBeloteScoreRepository + .getScoreByGame(gameId); expect(frenchBeloteScore, expectedScore); }); test('PROD', () async { var collection = 'belote-score-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('game', isEqualTo: gameId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('game', isEqualTo: gameId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); - when(mockQueryDocumentSnapshot.data()) - .thenReturn(frenchBeloteScoreJson); + when( + mockQueryDocumentSnapshot.data(), + ).thenReturn(frenchBeloteScoreJson); when(mockQueryDocumentSnapshot.id).thenReturn(uid); final frenchBeloteScoreRepository = FrenchBeloteScoreRepository( - provider: instance, environment: 'prod'); - final frenchBeloteScore = - await frenchBeloteScoreRepository.getScoreByGame(gameId); + provider: instance, + environment: 'prod', + ); + final frenchBeloteScore = await frenchBeloteScoreRepository + .getScoreByGame(gameId); expect(frenchBeloteScore, expectedScore); }); }); diff --git a/test/units/repositories/score/french_belote/french_belote_score_repository_test.mocks.dart b/test/units/repositories/score/french_belote/french_belote_score_repository_test.mocks.dart index 439e53f6..8374ee2b 100644 --- a/test/units/repositories/score/french_belote/french_belote_score_repository_test.mocks.dart +++ b/test/units/repositories/score/french_belote/french_belote_score_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'french_belote_score_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/score/tarot/tarot_score_repository_test.dart b/test/units/repositories/score/tarot/tarot_score_repository_test.dart index 8bc1d9ad..d3772ca7 100644 --- a/test/units/repositories/score/tarot/tarot_score_repository_test.dart +++ b/test/units/repositories/score/tarot/tarot_score_repository_test.dart @@ -10,25 +10,27 @@ import 'tarot_score_repository_test.mocks.dart'; const uid = '123'; const userId = '123_user'; const gameId = '123_game'; -const tarotScoreJson = { - 'id': uid, - 'game': gameId, -}; +const tarotScoreJson = {'id': uid, 'game': gameId}; final expectedScore = TarotScore(id: uid, game: gameId); Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query, -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -54,12 +56,15 @@ void main() { group('Get Player', () { test('DEV', () async { var collection = 'tarot-score-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(tarotScoreJson); when(mockDocumentSnapshot.id).thenReturn(uid); final tarotScoreRepository = TarotScoreRepository(provider: instance); @@ -68,16 +73,21 @@ void main() { }); test('PROD', () async { var collection = 'tarot-score-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(tarotScoreJson); when(mockDocumentSnapshot.id).thenReturn(uid); - final tarotScoreRepository = - TarotScoreRepository(provider: instance, environment: 'prod'); + final tarotScoreRepository = TarotScoreRepository( + provider: instance, + environment: 'prod', + ); final tarotScore = await tarotScoreRepository.get(uid); expect(tarotScore, expectedScore); }); @@ -86,10 +96,12 @@ void main() { group('Get Score by game', () { test('DEV', () async { var collection = 'tarot-score-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('game', isEqualTo: gameId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('game', isEqualTo: gameId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(tarotScoreJson); @@ -100,16 +112,20 @@ void main() { }); test('PROD', () async { var collection = 'tarot-score-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('game', isEqualTo: gameId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('game', isEqualTo: gameId), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(tarotScoreJson); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final tarotScoreRepository = - TarotScoreRepository(provider: instance, environment: 'prod'); + final tarotScoreRepository = TarotScoreRepository( + provider: instance, + environment: 'prod', + ); final tarotScore = await tarotScoreRepository.getScoreByGame(gameId); expect(tarotScore, expectedScore); }); diff --git a/test/units/repositories/score/tarot/tarot_score_repository_test.mocks.dart b/test/units/repositories/score/tarot/tarot_score_repository_test.mocks.dart index 17ac4088..72a5890a 100644 --- a/test/units/repositories/score/tarot/tarot_score_repository_test.mocks.dart +++ b/test/units/repositories/score/tarot/tarot_score_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'tarot_score_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/repositories/team/team_repository_test.dart b/test/units/repositories/team/team_repository_test.dart index ee905cb7..d70f3eae 100644 --- a/test/units/repositories/team/team_repository_test.dart +++ b/test/units/repositories/team/team_repository_test.dart @@ -13,24 +13,33 @@ var playerIds = ['p1', 'p2']; const jsonTeam = { 'won_games': 0, 'played_games': 0, - 'players': ['p1', 'p2'] + 'players': ['p1', 'p2'], }; -final expectedTeam = - Team(id: uid, wonGames: 0, playedGames: 0, players: ['p1', 'p2']); +final expectedTeam = Team( + id: uid, + wonGames: 0, + playedGames: 0, + players: ['p1', 'p2'], +); Map dataFunction() => {}; -@GenerateMocks([ - FirebaseFirestore, - CollectionReference, - DocumentReference, - DocumentSnapshot, - QuerySnapshot, - Query -], customMocks: [ - MockSpec( - unsupportedMembers: {#data}, fallbackGenerators: {#data: dataFunction}) -]) +@GenerateMocks( + [ + FirebaseFirestore, + CollectionReference, + DocumentReference, + DocumentSnapshot, + QuerySnapshot, + Query, + ], + customMocks: [ + MockSpec( + unsupportedMembers: {#data}, + fallbackGenerators: {#data: dataFunction}, + ), + ], +) void main() { final instance = MockFirebaseFirestore(); final mockQuery = MockQuery>(); @@ -56,12 +65,15 @@ void main() { group('Get Team', () { test('DEV', () async { var collection = 'team-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonTeam); when(mockDocumentSnapshot.id).thenReturn(uid); final teamRepository = TeamRepository(provider: instance); @@ -70,16 +82,21 @@ void main() { }); test('PROD', () async { var collection = 'team-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.doc(uid)) - .thenReturn(mockDocumentReference); - when(mockDocumentReference.get()) - .thenAnswer((_) async => mockDocumentSnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.doc(uid), + ).thenReturn(mockDocumentReference); + when( + mockDocumentReference.get(), + ).thenAnswer((_) async => mockDocumentSnapshot); when(mockDocumentSnapshot.data()).thenReturn(jsonTeam); when(mockDocumentSnapshot.id).thenReturn(uid); - final teamRepository = - TeamRepository(provider: instance, environment: 'prod'); + final teamRepository = TeamRepository( + provider: instance, + environment: 'prod', + ); final team = await teamRepository.get(uid); expect(team, expectedTeam); }); @@ -88,10 +105,12 @@ void main() { group('Get by players', () { test('DEV', () async { var collection = 'team-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players', isEqualTo: playerIds)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('players', isEqualTo: playerIds), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonTeam); @@ -102,16 +121,20 @@ void main() { }); test('PROD', () async { var collection = 'team-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players', isEqualTo: playerIds)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('players', isEqualTo: playerIds), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonTeam); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final teamRepository = - TeamRepository(provider: instance, environment: 'prod'); + final teamRepository = TeamRepository( + provider: instance, + environment: 'prod', + ); final team = await teamRepository.getTeamByPlayers(['p2', 'p1']); expect(team, expectedTeam); }); @@ -120,38 +143,48 @@ void main() { group('Create with players', () { test('Team exists', () async { var collection = 'team-dev'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players', isEqualTo: playerIds)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('players', isEqualTo: playerIds), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonTeam); when(mockQueryDocumentSnapshot.id).thenReturn(uid); final teamRepository = TeamRepository(provider: instance); - expect(teamRepository.createTeamWithPlayers(['p2', 'p1']), - throwsA(isA())); + expect( + teamRepository.createTeamWithPlayers(['p2', 'p1']), + throwsA(isA()), + ); }); test('Team does not exist', () async { var collection = 'team-prod'; - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players', isEqualTo: playerIds)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('players', isEqualTo: playerIds), + ).thenReturn(mockQuery); when(mockQuery.get()).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); - when(mockCollectionReference.add({ - 'name': null, - 'games': null, - 'won_games': 0, - 'played_games': 0, - 'game_stats': [], - 'players': ['p1', 'p2'] - })).thenAnswer((_) async => mockDocumentReference); + when( + mockCollectionReference.add({ + 'name': null, + 'games': null, + 'won_games': 0, + 'played_games': 0, + 'game_stats': [], + 'players': ['p1', 'p2'], + }), + ).thenAnswer((_) async => mockDocumentReference); when(mockDocumentReference.id).thenReturn(uid); - final teamRepository = - TeamRepository(provider: instance, environment: 'prod'); + final teamRepository = TeamRepository( + provider: instance, + environment: 'prod', + ); final team = await teamRepository.createTeamWithPlayers(['p2', 'p1']); expect(team, expectedTeam); }); @@ -165,21 +198,30 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players', arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('players', arrayContains: playerId), + ).thenReturn(mockQuery); + when( + mockQuery.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final teamRepository = TeamRepository( - provider: instance, lastFetchGameDocument: mockDocumentSnapshot); - expect(await teamRepository.getAllTeamOfPlayer(playerId, pageSize), - []); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + ); + expect( + await teamRepository.getAllTeamOfPlayer(playerId, pageSize), + [], + ); }); test('PRD', () async { const collection = 'team-prod'; @@ -188,23 +230,31 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players', arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('players', arrayContains: playerId), + ).thenReturn(mockQuery); + when( + mockQuery.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final teamRepository = TeamRepository( - provider: instance, - lastFetchGameDocument: mockDocumentSnapshot, - environment: 'prod'); - expect(await teamRepository.getAllTeamOfPlayer(playerId, pageSize), - []); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + environment: 'prod', + ); + expect( + await teamRepository.getAllTeamOfPlayer(playerId, pageSize), + [], + ); }); test('Last fetched document not null', () async { @@ -214,23 +264,31 @@ void main() { final mockQueryFromStartAfterDocument = MockQuery>(); final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players', arrayContains: playerId)) - .thenReturn(mockQuery); - when(mockQuery.startAfterDocument(mockDocumentSnapshot)) - .thenReturn(mockQueryFromStartAfterDocument); - when(mockQueryFromStartAfterDocument.limit(pageSize)) - .thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('players', arrayContains: playerId), + ).thenReturn(mockQuery); + when( + mockQuery.startAfterDocument(mockDocumentSnapshot), + ).thenReturn(mockQueryFromStartAfterDocument); + when( + mockQueryFromStartAfterDocument.limit(pageSize), + ).thenReturn(mockQueryFromLimit); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([]); final teamRepository = TeamRepository( - provider: instance, - lastFetchGameDocument: mockDocumentSnapshot, - environment: 'prod'); - expect(await teamRepository.getAllTeamOfPlayer(playerId, pageSize), - []); + provider: instance, + lastFetchGameDocument: mockDocumentSnapshot, + environment: 'prod', + ); + expect( + await teamRepository.getAllTeamOfPlayer(playerId, pageSize), + [], + ); }); test('Last fetched document not null and return data', () async { @@ -238,20 +296,27 @@ void main() { const playerId = 'p1'; const pageSize = 10; final mockQueryFromLimit = MockQuery>(); - when(instance.collection(collection)) - .thenReturn(mockCollectionReference); - when(mockCollectionReference.where('players', arrayContains: playerId)) - .thenReturn(mockQuery); + when( + instance.collection(collection), + ).thenReturn(mockCollectionReference); + when( + mockCollectionReference.where('players', arrayContains: playerId), + ).thenReturn(mockQuery); when(mockQuery.limit(pageSize)).thenReturn(mockQueryFromLimit); - when(mockQueryFromLimit.get()) - .thenAnswer((_) async => mockQuerySnapshot); + when( + mockQueryFromLimit.get(), + ).thenAnswer((_) async => mockQuerySnapshot); when(mockQuerySnapshot.docs).thenReturn([mockQueryDocumentSnapshot]); when(mockQueryDocumentSnapshot.data()).thenReturn(jsonTeam); when(mockQueryDocumentSnapshot.id).thenReturn(uid); - final teamRepository = - TeamRepository(provider: instance, environment: 'prod'); - expect(await teamRepository.getAllTeamOfPlayer(playerId, pageSize), - [expectedTeam]); + final teamRepository = TeamRepository( + provider: instance, + environment: 'prod', + ); + expect( + await teamRepository.getAllTeamOfPlayer(playerId, pageSize), + [expectedTeam], + ); }); }); }); diff --git a/test/units/repositories/team/team_repository_test.mocks.dart b/test/units/repositories/team/team_repository_test.mocks.dart index 473d1dbf..17c622f4 100644 --- a/test/units/repositories/team/team_repository_test.mocks.dart +++ b/test/units/repositories/team/team_repository_test.mocks.dart @@ -28,6 +28,7 @@ import 'team_repository_test.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { _FakeFirebaseApp_0( @@ -185,15 +186,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ), ) as _i2.FirebaseApp); - @override - String get databaseURL => (super.noSuchMethod( - Invocation.getter(#databaseURL), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#databaseURL), - ), - ) as String); - @override String get databaseId => (super.noSuchMethod( Invocation.getter(#databaseId), @@ -213,28 +205,19 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { ) as _i3.Settings); @override - set app(_i2.FirebaseApp? _app) => super.noSuchMethod( + set app(_i2.FirebaseApp? value) => super.noSuchMethod( Invocation.setter( #app, - _app, - ), - returnValueForMissingStub: null, - ); - - @override - set databaseURL(String? _databaseURL) => super.noSuchMethod( - Invocation.setter( - #databaseURL, - _databaseURL, + value, ), returnValueForMissingStub: null, ); @override - set databaseId(String? _databaseId) => super.noSuchMethod( + set databaseId(String? value) => super.noSuchMethod( Invocation.setter( #databaseId, - _databaseId, + value, ), returnValueForMissingStub: null, ); @@ -296,18 +279,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future enablePersistence( - [_i3.PersistenceSettings? persistenceSettings]) => - (super.noSuchMethod( - Invocation.method( - #enablePersistence, - [persistenceSettings], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i4.LoadBundleTask loadBundle(_i7.Uint8List? bundle) => (super.noSuchMethod( Invocation.method( @@ -522,24 +493,6 @@ class MockFirebaseFirestore extends _i1.Mock implements _i4.FirebaseFirestore { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setIndexConfiguration({ - required List<_i3.Index>? indexes, - List<_i3.FieldOverrides>? fieldOverrides, - }) => - (super.noSuchMethod( - Invocation.method( - #setIndexConfiguration, - [], - { - #indexes: indexes, - #fieldOverrides: fieldOverrides, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setIndexConfigurationFromJSON(String? json) => (super.noSuchMethod( diff --git a/test/units/round/coinche_belote_round_test.dart b/test/units/round/coinche_belote_round_test.dart index 695eb179..d3e0f081 100644 --- a/test/units/round/coinche_belote_round_test.dart +++ b/test/units/round/coinche_belote_round_test.dart @@ -7,9 +7,15 @@ import 'package:flutter_test/flutter_test.dart'; void main() { final gameSettingAddToContract = CoincheBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: true); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: true, + ); final gameSettingNoAddToContract = CoincheBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: false); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: false, + ); group('CoincheRound', () { test('Is contract fulfilled', () { @@ -304,7 +310,7 @@ void main() { defenderScore: 61, contract: 100, settings: gameSettingAddToContract, - isManualMode: true + isManualMode: true, ); expect(coincheRound.takerScore, 101); expect(coincheRound.defenderScore, 61); diff --git a/test/units/round/contree_belote_round_test.dart b/test/units/round/contree_belote_round_test.dart index 3e1655e3..f00f3a25 100644 --- a/test/units/round/contree_belote_round_test.dart +++ b/test/units/round/contree_belote_round_test.dart @@ -7,28 +7,36 @@ import 'package:flutter_test/flutter_test.dart'; void main() { final gameSettingAddToContract = ContreeBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: true); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: true, + ); final gameSettingNoAddToContract = ContreeBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: false); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: false, + ); group('ContreeRound', () { test('Is contract fulfilled', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); expect(contreeRound.contractFulfilled, true); }); test('Compute score - Set contract', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.dixDeDer = BeloteTeamEnum.US; contreeRound.beloteRebelote = null; contreeRound.contractName = ContreeBeloteContractName.NORMAL; @@ -40,11 +48,12 @@ void main() { test('Compute score - Set contract', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingNoAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingNoAddToContract, + ); contreeRound.dixDeDer = BeloteTeamEnum.US; contreeRound.beloteRebelote = null; contreeRound.contractName = ContreeBeloteContractName.NORMAL; @@ -56,11 +65,12 @@ void main() { test('Compute score - fulfilled', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.dixDeDer = BeloteTeamEnum.US; contreeRound.beloteRebelote = null; contreeRound.contractName = ContreeBeloteContractName.NORMAL; @@ -73,11 +83,12 @@ void main() { test('Compute score - fulfilled', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingNoAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingNoAddToContract, + ); contreeRound.dixDeDer = BeloteTeamEnum.US; contreeRound.beloteRebelote = null; contreeRound.contractName = ContreeBeloteContractName.NORMAL; @@ -90,11 +101,12 @@ void main() { test('Compute score - fulfilled - BeloteRebelote - US', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.dixDeDer = BeloteTeamEnum.THEM; contreeRound.beloteRebelote = BeloteTeamEnum.US; contreeRound.contractName = ContreeBeloteContractName.NORMAL; @@ -107,11 +119,12 @@ void main() { test('Compute score - fulfilled - BeloteRebelote - THEM', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.dixDeDer = BeloteTeamEnum.US; contreeRound.beloteRebelote = BeloteTeamEnum.THEM; contreeRound.contractName = ContreeBeloteContractName.NORMAL; @@ -124,11 +137,12 @@ void main() { test('Compute score - fulfilled - Dix de Der - US', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.beloteRebelote = null; contreeRound.dixDeDer = BeloteTeamEnum.US; contreeRound.contractName = ContreeBeloteContractName.NORMAL; @@ -141,11 +155,12 @@ void main() { test('Compute score - fulfilled - Dix de Der - THEM', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.beloteRebelote = null; contreeRound.dixDeDer = BeloteTeamEnum.THEM; contreeRound.contractName = ContreeBeloteContractName.NORMAL; @@ -158,11 +173,12 @@ void main() { test('Compute score - Contract - Contre', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.beloteRebelote = null; contreeRound.dixDeDer = BeloteTeamEnum.US; contreeRound.contractName = ContreeBeloteContractName.CONTRE; @@ -175,11 +191,12 @@ void main() { test('Compute score - Contract - Sur Contré', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.beloteRebelote = null; contreeRound.dixDeDer = BeloteTeamEnum.US; contreeRound.contractName = ContreeBeloteContractName.SURCONTRE; @@ -191,11 +208,12 @@ void main() { test('Compute score - failed', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.taker = BeloteTeamEnum.THEM; contreeRound.defender = BeloteTeamEnum.US; contreeRound.beloteRebelote = null; @@ -210,11 +228,12 @@ void main() { test('Compute score - fulfilled - Dix de Der - US - Capot', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.taker = BeloteTeamEnum.US; contreeRound.defender = BeloteTeamEnum.THEM; contreeRound.usTrickScore = 152; @@ -231,11 +250,12 @@ void main() { test('Compute score - fulfilled - Dix de Der - US - Capot failed', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.taker = BeloteTeamEnum.US; contreeRound.defender = BeloteTeamEnum.THEM; contreeRound.usTrickScore = 140; @@ -252,11 +272,12 @@ void main() { test('Compute score - fulfilled - Dix de Der - US - Generale', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.taker = BeloteTeamEnum.US; contreeRound.defender = BeloteTeamEnum.THEM; contreeRound.usTrickScore = 152; @@ -273,11 +294,12 @@ void main() { test('Compute score - fulfilled - Dix de Der - US - Failed generale', () { final contreeRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - usTrickScore: 110, - themTrickScore: 50, - settings: gameSettingAddToContract); + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + usTrickScore: 110, + themTrickScore: 50, + settings: gameSettingAddToContract, + ); contreeRound.taker = BeloteTeamEnum.US; contreeRound.defender = BeloteTeamEnum.THEM; contreeRound.usTrickScore = 152; @@ -294,13 +316,13 @@ void main() { test('Manual mode', () { final coincheRound = ContreeBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - takerScore: 101, - defenderScore: 61, - contract: 100, - settings: gameSettingAddToContract, - isManualMode: true + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + takerScore: 101, + defenderScore: 61, + contract: 100, + settings: gameSettingAddToContract, + isManualMode: true, ); expect(coincheRound.takerScore, 101); expect(coincheRound.defenderScore, 61); diff --git a/test/units/round/french_belote_round_test.dart b/test/units/round/french_belote_round_test.dart index 80d7911a..4761925b 100644 --- a/test/units/round/french_belote_round_test.dart +++ b/test/units/round/french_belote_round_test.dart @@ -5,7 +5,10 @@ import 'package:flutter_test/flutter_test.dart'; void main() { final gameSettingAddToContract = FrenchBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: true); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: true, + ); group('BeloteRound', () { test('Is contract fulfilled', () { @@ -14,9 +17,7 @@ void main() { }); test('Compute score - fulfilled', () { - final beloteRound = FrenchBeloteRound( - settings: gameSettingAddToContract, - ); + final beloteRound = FrenchBeloteRound(settings: gameSettingAddToContract); beloteRound.taker = BeloteTeamEnum.US; beloteRound.defender = BeloteTeamEnum.THEM; beloteRound.dixDeDer = BeloteTeamEnum.US; @@ -29,9 +30,7 @@ void main() { }); test('Compute score - fulfilled - BeloteRebelote - US', () { - final beloteRound = FrenchBeloteRound( - settings: gameSettingAddToContract, - ); + final beloteRound = FrenchBeloteRound(settings: gameSettingAddToContract); beloteRound.taker = BeloteTeamEnum.US; beloteRound.defender = BeloteTeamEnum.THEM; beloteRound.dixDeDer = BeloteTeamEnum.US; @@ -44,9 +43,7 @@ void main() { }); test('Compute score - not fulfilled - BeloteRebelote - THEM', () { - final beloteRound = FrenchBeloteRound( - settings: gameSettingAddToContract, - ); + final beloteRound = FrenchBeloteRound(settings: gameSettingAddToContract); beloteRound.taker = BeloteTeamEnum.US; beloteRound.dixDeDer = BeloteTeamEnum.US; beloteRound.defender = BeloteTeamEnum.THEM; @@ -59,9 +56,7 @@ void main() { }); test('Compute score - fulfilled - Dix de Der - US', () { - final beloteRound = FrenchBeloteRound( - settings: gameSettingAddToContract, - ); + final beloteRound = FrenchBeloteRound(settings: gameSettingAddToContract); beloteRound.taker = BeloteTeamEnum.US; beloteRound.dixDeDer = BeloteTeamEnum.US; beloteRound.defender = BeloteTeamEnum.THEM; @@ -74,9 +69,7 @@ void main() { }); test('Compute score - fulfilled - Dix de Der - THEM', () { - final beloteRound = FrenchBeloteRound( - settings: gameSettingAddToContract, - ); + final beloteRound = FrenchBeloteRound(settings: gameSettingAddToContract); beloteRound.taker = BeloteTeamEnum.US; beloteRound.defender = BeloteTeamEnum.THEM; beloteRound.dixDeDer = BeloteTeamEnum.THEM; @@ -89,9 +82,7 @@ void main() { }); test('Compute score - failed', () { - final beloteRound = FrenchBeloteRound( - settings: gameSettingAddToContract, - ); + final beloteRound = FrenchBeloteRound(settings: gameSettingAddToContract); beloteRound.taker = BeloteTeamEnum.THEM; beloteRound.defender = BeloteTeamEnum.US; beloteRound.dixDeDer = BeloteTeamEnum.US; @@ -105,12 +96,12 @@ void main() { test('Manual mode', () { final coincheRound = FrenchBeloteRound( - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM, - takerScore: 81, - defenderScore: 81, - settings: gameSettingAddToContract, - isManualMode: true + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + takerScore: 81, + defenderScore: 81, + settings: gameSettingAddToContract, + isManualMode: true, ); expect(coincheRound.takerScore, 81); expect(coincheRound.defenderScore, 81); diff --git a/test/units/round/tarot_round_test.dart b/test/units/round/tarot_round_test.dart index af23ac55..681d2f7c 100644 --- a/test/units/round/tarot_round_test.dart +++ b/test/units/round/tarot_round_test.dart @@ -10,12 +10,16 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('TarotRound', () { final players = TarotRoundPlayers( - attackPlayer: 'player_1', - playerList: ['player_1', 'player_2', 'player_3', 'player_4']); + attackPlayer: 'player_1', + playerList: ['player_1', 'player_2', 'player_3', 'player_4'], + ); test('Compute score - ONE & PETITE', () { final tarotRound = TarotRound( - attackTrickPoints: 51.0, defenseTrickPoints: 40.0, players: players); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + players: players, + ); tarotRound.oudler = TarotOudler.ONE; tarotRound.contract = TarotContract.PETITE; tarotRound.smallToTheEndTeam = null; @@ -27,7 +31,10 @@ void main() { test('Compute score - TWO & GARDE', () { final tarotRound = TarotRound( - attackTrickPoints: 51.0, defenseTrickPoints: 40.0, players: players); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + players: players, + ); tarotRound.oudler = TarotOudler.TWO; tarotRound.contract = TarotContract.GARDE_AVEC_CHIEN; tarotRound.smallToTheEndTeam = null; @@ -39,7 +46,10 @@ void main() { test('Compute score - THREE & GARDE', () { final tarotRound = TarotRound( - attackTrickPoints: 51.0, defenseTrickPoints: 40.0, players: players); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + players: players, + ); tarotRound.oudler = TarotOudler.ONE; tarotRound.contract = TarotContract.GARDE_AVEC_CHIEN; tarotRound.smallToTheEndTeam = null; @@ -51,7 +61,10 @@ void main() { test('Compute score - Small at the end - Attack', () { final tarotRound = TarotRound( - attackTrickPoints: 51.0, defenseTrickPoints: 40.0, players: players); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + players: players, + ); tarotRound.oudler = TarotOudler.ONE; tarotRound.contract = TarotContract.GARDE_AVEC_CHIEN; tarotRound.smallToTheEndTeam = TarotTeam.ATTACK; @@ -63,7 +76,10 @@ void main() { test('Compute score - Small at the end - Defense', () { final tarotRound = TarotRound( - attackTrickPoints: 51.0, defenseTrickPoints: 40.0, players: players); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + players: players, + ); tarotRound.oudler = TarotOudler.ONE; tarotRound.contract = TarotContract.GARDE_AVEC_CHIEN; tarotRound.smallToTheEndTeam = TarotTeam.DEFENSE; @@ -75,7 +91,10 @@ void main() { test('Compute score - Handful won', () { final tarotRound = TarotRound( - attackTrickPoints: 51.0, defenseTrickPoints: 40.0, players: players); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + players: players, + ); tarotRound.oudler = TarotOudler.ONE; tarotRound.contract = TarotContract.GARDE_AVEC_CHIEN; tarotRound.smallToTheEndTeam = null; @@ -87,7 +106,10 @@ void main() { test('Compute score - Handful lost', () { final tarotRound = TarotRound( - attackTrickPoints: 51.0, defenseTrickPoints: 40.0, players: players); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + players: players, + ); tarotRound.oudler = TarotOudler.ONE; tarotRound.contract = TarotContract.GARDE_AVEC_CHIEN; tarotRound.smallToTheEndTeam = null; @@ -99,7 +121,10 @@ void main() { test('Compute score - Chelem', () { final tarotRound = TarotRound( - attackTrickPoints: 51.0, defenseTrickPoints: 40.0, players: players); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + players: players, + ); tarotRound.oudler = TarotOudler.ONE; tarotRound.contract = TarotContract.GARDE_AVEC_CHIEN; tarotRound.smallToTheEndTeam = null; diff --git a/test/units/score/belote_score_test.dart b/test/units/score/belote_score_test.dart index 9a8a6e33..66f88163 100644 --- a/test/units/score/belote_score_test.dart +++ b/test/units/score/belote_score_test.dart @@ -1,4 +1,3 @@ - import 'package:flutter_test/flutter_test.dart'; import '../mocks/fake_belote_round.dart'; @@ -9,8 +8,10 @@ void main() { final round = FakeBeloteRound(); test('Add round', () { - final beloteScore = - FakeBeloteScore(usTotalPoints: 100, themTotalPoints: 100); + final beloteScore = FakeBeloteScore( + usTotalPoints: 100, + themTotalPoints: 100, + ); beloteScore.addRound(round); expect(beloteScore.rounds.length, 1); }); diff --git a/test/units/score/tarot_score_test.dart b/test/units/score/tarot_score_test.dart index 50b80535..718b9f97 100644 --- a/test/units/score/tarot_score_test.dart +++ b/test/units/score/tarot_score_test.dart @@ -8,19 +8,19 @@ void main() { final players = ['player_1', 'player_2', 'player_3', 'player_4']; final game = 'game_id'; final round = TarotRound( - attackTrickPoints: 51.0, - defenseTrickPoints: 40.0, - attackScore: 75.0, - defenseScore: -25.0, - players: - TarotRoundPlayers(attackPlayer: players[0], playerList: players)); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + attackScore: 75.0, + defenseScore: -25.0, + players: TarotRoundPlayers(attackPlayer: players[0], playerList: players), + ); final round2 = TarotRound( - attackTrickPoints: 51.0, - defenseTrickPoints: 40.0, - attackScore: 75.0, - defenseScore: -25.0, - players: - TarotRoundPlayers(attackPlayer: players[0], playerList: players)); + attackTrickPoints: 51.0, + defenseTrickPoints: 40.0, + attackScore: 75.0, + defenseScore: -25.0, + players: TarotRoundPlayers(attackPlayer: players[0], playerList: players), + ); test('Create score', () { final tarotScore = TarotScore(game: game, players: players); @@ -34,45 +34,53 @@ void main() { expect(tarotScore.totalPoints.length, 4); expect(tarotScore.rounds.length, 1); expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_1') - .score, - 75.0); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_2') - .score, - -25); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_3') - .score, - -25); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_4') - .score, - -25); - expect( - tarotScore.rounds[0].playerPoints - ?.firstWhere((element) => element.player == 'player_1') - .score, - 75.0); - expect( - tarotScore.rounds[0].playerPoints - ?.firstWhere((element) => element.player == 'player_2') - .score, - -25); - expect( - tarotScore.rounds[0].playerPoints - ?.firstWhere((element) => element.player == 'player_2') - .score, - -25); - expect( - tarotScore.rounds[0].playerPoints - ?.firstWhere((element) => element.player == 'player_2') - .score, - -25); + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_1') + .score, + 75.0, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_2') + .score, + -25, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_3') + .score, + -25, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_4') + .score, + -25, + ); + expect( + tarotScore.rounds[0].playerPoints + ?.firstWhere((element) => element.player == 'player_1') + .score, + 75.0, + ); + expect( + tarotScore.rounds[0].playerPoints + ?.firstWhere((element) => element.player == 'player_2') + .score, + -25, + ); + expect( + tarotScore.rounds[0].playerPoints + ?.firstWhere((element) => element.player == 'player_2') + .score, + -25, + ); + expect( + tarotScore.rounds[0].playerPoints + ?.firstWhere((element) => element.player == 'player_2') + .score, + -25, + ); }); test('Delete round', () { @@ -82,48 +90,56 @@ void main() { expect(tarotScore.totalPoints.length, 4); expect(tarotScore.rounds.length, 2); expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_1') - .score, - 150); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_2') - .score, - -50); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_3') - .score, - -50); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_4') - .score, - -50); + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_1') + .score, + 150, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_2') + .score, + -50, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_3') + .score, + -50, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_4') + .score, + -50, + ); tarotScore.deleteRound(1); expect(tarotScore.totalPoints.length, 4); expect(tarotScore.rounds.length, 1); expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_1') - .score, - 75); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_2') - .score, - -25); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_3') - .score, - -25); - expect( - tarotScore.totalPoints - .firstWhere((element) => element.player == 'player_4') - .score, - -25); + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_1') + .score, + 75, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_2') + .score, + -25, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_3') + .score, + -25, + ); + expect( + tarotScore.totalPoints + .firstWhere((element) => element.player == 'player_4') + .score, + -25, + ); }); }); } diff --git a/test/units/services/game/abstract_belote_game_service_test.dart b/test/units/services/game/abstract_belote_game_service_test.dart index a7d09c5c..2f23c474 100644 --- a/test/units/services/game/abstract_belote_game_service_test.dart +++ b/test/units/services/game/abstract_belote_game_service_test.dart @@ -14,8 +14,11 @@ import '../../mocks/fake_belote_score.dart'; import '../../mocks/fake_belote_score_service.dart'; import 'abstract_belote_game_service_test.mocks.dart'; -@GenerateMocks( - [AbstractBeloteScoreService, AbstractBeloteGameRepository, TeamService]) +@GenerateMocks([ + AbstractBeloteScoreService, + AbstractBeloteGameRepository, + TeamService, +]) void main() { final mockBeloteScoreService = MockAbstractBeloteScoreService(); final mockBeloteGameRepository = MockAbstractBeloteGameRepository(); @@ -28,10 +31,15 @@ void main() { final teamUs = Team(id: 'usTeamId', players: ['p2', 'p3']); final teamThem = Team(id: 'themTeamId', players: ['p1', 'p4']); final beloteScore = FakeBeloteScore(usTotalPoints: 200, themTotalPoints: 100); - final beloteTIEScore = - FakeBeloteScore(usTotalPoints: 200, themTotalPoints: 200); - final players = - BelotePlayers(us: teamUs.id, them: teamThem.id, playerList: playerIds); + final beloteTIEScore = FakeBeloteScore( + usTotalPoints: 200, + themTotalPoints: 200, + ); + final players = BelotePlayers( + us: teamUs.id, + them: teamThem.id, + playerList: playerIds, + ); final game = FakeBeloteGame( uid, @@ -54,41 +62,56 @@ void main() { ), ); final settings = FakeBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: true); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: true, + ); group('AbstractBeloteGameService', () { group('End a game', () { test('OK', () async { - when(mockBeloteScoreService.getScoreByGame(uid)) - .thenAnswer((_) => Future(() => beloteScore)); - when(mockTeamService.incrementPlayedGamesByOne('themTeamId', game)) - .thenAnswer((_) => Future(() => Team())); - when(mockTeamService.incrementPlayedGamesByOne('usTeamId', game)) - .thenAnswer((_) => Future(() => Team())); - when(mockTeamService.incrementWonGamesByOne('usTeamId', game)) - .thenAnswer((_) => Future(() => Team())); + when( + mockBeloteScoreService.getScoreByGame(uid), + ).thenAnswer((_) => Future(() => beloteScore)); + when( + mockTeamService.incrementPlayedGamesByOne('themTeamId', game), + ).thenAnswer((_) => Future(() => Team())); + when( + mockTeamService.incrementPlayedGamesByOne('usTeamId', game), + ).thenAnswer((_) => Future(() => Team())); + when( + mockTeamService.incrementWonGamesByOne('usTeamId', game), + ).thenAnswer((_) => Future(() => Team())); final beloteGameService = FakeBeloteGameService( - beloteScoreService: mockBeloteScoreService, - beloteGameRepository: mockBeloteGameRepository, - teamService: mockTeamService); + beloteScoreService: mockBeloteScoreService, + beloteGameRepository: mockBeloteGameRepository, + teamService: mockTeamService, + ); await beloteGameService.endAGame(game, date); - verify(mockTeamService.incrementPlayedGamesByOne('usTeamId', game)) - .called(1); - verify(mockTeamService.incrementPlayedGamesByOne('themTeamId', game)) - .called(1); - verify(mockTeamService.incrementWonGamesByOne('usTeamId', game)) - .called(1); + verify( + mockTeamService.incrementPlayedGamesByOne('usTeamId', game), + ).called(1); + verify( + mockTeamService.incrementPlayedGamesByOne('themTeamId', game), + ).called(1); + verify( + mockTeamService.incrementWonGamesByOne('usTeamId', game), + ).called(1); }); test('NOK - TIE', () async { - when(mockBeloteScoreService.getScoreByGame(uid)) - .thenAnswer((_) => Future(() => beloteTIEScore)); + when( + mockBeloteScoreService.getScoreByGame(uid), + ).thenAnswer((_) => Future(() => beloteTIEScore)); final beloteGameService = FakeBeloteGameService( - beloteScoreService: mockBeloteScoreService, - beloteGameRepository: mockBeloteGameRepository, - teamService: mockTeamService); - expect(beloteGameService.endAGame(game, date), - throwsA(isA())); + beloteScoreService: mockBeloteScoreService, + beloteGameRepository: mockBeloteGameRepository, + teamService: mockTeamService, + ); + expect( + beloteGameService.endAGame(game, date), + throwsA(isA()), + ); }); }); @@ -96,20 +119,29 @@ void main() { test('OK', () async { final playerIdsOrder = ['p1', 'p2', 'p3', 'p4']; final playerIdsTeam = ['p2', 'p3', 'p1', 'p4']; - when(mockTeamService.getTeamByPlayers(['p2', 'p3'])) - .thenAnswer((_) => Future(() => teamUs)); - when(mockTeamService.getTeamByPlayers(['p1', 'p4'])) - .thenAnswer((_) => Future(() => teamThem)); - when(mockBeloteGameRepository.create(gameNoId)) - .thenAnswer((_) => Future(() => uid)); - when(mockBeloteScoreService.generateNewScore(uid)) - .thenAnswer((_) => Future(() => beloteScore)); + when( + mockTeamService.getTeamByPlayers(['p2', 'p3']), + ).thenAnswer((_) => Future(() => teamUs)); + when( + mockTeamService.getTeamByPlayers(['p1', 'p4']), + ).thenAnswer((_) => Future(() => teamThem)); + when( + mockBeloteGameRepository.create(gameNoId), + ).thenAnswer((_) => Future(() => uid)); + when( + mockBeloteScoreService.generateNewScore(uid), + ).thenAnswer((_) => Future(() => beloteScore)); final beloteGameService = FakeBeloteGameService( - beloteScoreService: mockBeloteScoreService, - beloteGameRepository: mockBeloteGameRepository, - teamService: mockTeamService); + beloteScoreService: mockBeloteScoreService, + beloteGameRepository: mockBeloteGameRepository, + teamService: mockTeamService, + ); final finalGame = await beloteGameService.createGameWithPlayerList( - playerIdsOrder, playerIdsTeam, date, settings); + playerIdsOrder, + playerIdsTeam, + date, + settings, + ); expect(finalGame, game); }); }); diff --git a/test/units/services/game/abstract_belote_game_service_test.mocks.dart b/test/units/services/game/abstract_belote_game_service_test.mocks.dart index b359623b..23d3097e 100644 --- a/test/units/services/game/abstract_belote_game_service_test.mocks.dart +++ b/test/units/services/game/abstract_belote_game_service_test.mocks.dart @@ -44,6 +44,7 @@ import 'package:mockito/src/dummies.dart' as _i17; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractBeloteScoreRepository_0< T1 extends _i1.BeloteScore<_i2.BeloteRound>> extends _i3.SmartFake @@ -304,21 +305,20 @@ class MockAbstractBeloteGameRepository< ) as String); @override - set lastFetchGameDocument( - _i11.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i11.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/game/abstract_game_service_test.dart b/test/units/services/game/abstract_game_service_test.dart index f67b4459..86b92cb0 100644 --- a/test/units/services/game/abstract_game_service_test.dart +++ b/test/units/services/game/abstract_game_service_test.dart @@ -13,8 +13,12 @@ import '../../mocks/fake_game_setting.dart'; import '../../mocks/fake_players.dart'; import 'abstract_game_service_test.mocks.dart'; -@GenerateMocks( - [AbstractScoreService, AbstractGameRepository, PlayerService, TeamService]) +@GenerateMocks([ + AbstractScoreService, + AbstractGameRepository, + PlayerService, + TeamService, +]) void main() { final mockScoreService = MockAbstractScoreService(); final mockGameRepository = MockAbstractGameRepository(); @@ -26,36 +30,30 @@ void main() { final date = DateTime.parse('2022-04-10 00:00:00.000'); final playerIds = ['p1', 'p2', 'p3', 'p4']; final players = FakePlayers(playerIds); - final settings = FakeGameSetting( - maxPoint: 1000, - isInfinite: false, - ); - final game = FakeGame( - uid, - date, - players, - settings, - ); + final settings = FakeGameSetting(maxPoint: 1000, isInfinite: false); + final game = FakeGame(uid, date, players, settings); group('AbstractGameService', () { group('Get Game', () { test('OK', () async { when(mockGameRepository.get(uid)).thenAnswer((_) => Future(() => game)); final gameService = FakeGameService( - scoreService: mockScoreService, - gameRepository: mockGameRepository, - playerService: mockPlayerService, - teamService: mockTeamService); + scoreService: mockScoreService, + gameRepository: mockGameRepository, + playerService: mockPlayerService, + teamService: mockTeamService, + ); final finalGames = await gameService.getGame(uid); expect(finalGames, game); }); test('NOK - Exception', () async { final gameService = FakeGameService( - scoreService: mockScoreService, - gameRepository: mockGameRepository, - playerService: mockPlayerService, - teamService: mockTeamService); + scoreService: mockScoreService, + gameRepository: mockGameRepository, + playerService: mockPlayerService, + teamService: mockTeamService, + ); expect(gameService.get(null), throwsA(isA())); }); }); @@ -63,20 +61,22 @@ void main() { group('Delete Game', () { test('OK', () async { final gameService = FakeGameService( - scoreService: mockScoreService, - gameRepository: mockGameRepository, - playerService: mockPlayerService, - teamService: mockTeamService); + scoreService: mockScoreService, + gameRepository: mockGameRepository, + playerService: mockPlayerService, + teamService: mockTeamService, + ); await gameService.deleteGame(uid); verify(mockGameRepository.delete(uid)).called(1); verify(mockScoreService.deleteScoreByGame(uid)).called(1); }); test('NOK - Exception', () async { final gameService = FakeGameService( - scoreService: mockScoreService, - gameRepository: mockGameRepository, - playerService: mockPlayerService, - teamService: mockTeamService); + scoreService: mockScoreService, + gameRepository: mockGameRepository, + playerService: mockPlayerService, + teamService: mockTeamService, + ); expect(gameService.deleteGame(null), throwsA(isA())); }); }); @@ -85,38 +85,48 @@ void main() { test('OK', () async { const userID = 'user_123'; const pageSize = 10; - when(mockGameRepository.getAllGamesOfPlayer(userID, pageSize)) - .thenAnswer((_) => Future(() => [game])); + when( + mockGameRepository.getAllGamesOfPlayer(userID, pageSize), + ).thenAnswer((_) => Future(() => [game])); final beloteGameService = FakeGameService( - scoreService: mockScoreService, - gameRepository: mockGameRepository, - playerService: mockPlayerService, - teamService: mockTeamService); + scoreService: mockScoreService, + gameRepository: mockGameRepository, + playerService: mockPlayerService, + teamService: mockTeamService, + ); final finalGames = await beloteGameService.getAllGamesOfPlayerPaginated( - userID, pageSize); + userID, + pageSize, + ); expect(finalGames, [game]); }); test('NOK - No userID', () async { const pageSize = 10; final beloteGameService = FakeGameService( - scoreService: mockScoreService, - gameRepository: mockGameRepository, - playerService: mockPlayerService, - teamService: mockTeamService); - expect(beloteGameService.getAllGamesOfPlayerPaginated(null, pageSize), - throwsA(isA())); + scoreService: mockScoreService, + gameRepository: mockGameRepository, + playerService: mockPlayerService, + teamService: mockTeamService, + ); + expect( + beloteGameService.getAllGamesOfPlayerPaginated(null, pageSize), + throwsA(isA()), + ); }); test('NOK - No page size', () async { const userID = 'user_123'; final beloteGameService = FakeGameService( - scoreService: mockScoreService, - gameRepository: mockGameRepository, - playerService: mockPlayerService, - teamService: mockTeamService); - expect(beloteGameService.getAllGamesOfPlayerPaginated(userID, null), - throwsA(isA())); + scoreService: mockScoreService, + gameRepository: mockGameRepository, + playerService: mockPlayerService, + teamService: mockTeamService, + ); + expect( + beloteGameService.getAllGamesOfPlayerPaginated(userID, null), + throwsA(isA()), + ); }); }); }); diff --git a/test/units/services/game/abstract_game_service_test.mocks.dart b/test/units/services/game/abstract_game_service_test.mocks.dart index 8ef0de39..8b832001 100644 --- a/test/units/services/game/abstract_game_service_test.mocks.dart +++ b/test/units/services/game/abstract_game_service_test.mocks.dart @@ -40,6 +40,7 @@ import 'package:mockito/src/dummies.dart' as _i15; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractScoreRepository_0< T1 extends _i1.Score<_i2.Round<_i3.GameSetting>>> extends _i4.SmartFake @@ -280,21 +281,20 @@ class MockAbstractGameRepository< ) as String); @override - set lastFetchGameDocument( - _i8.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i8.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/game/coinche_belote/coinche_belote_game_service_test.dart b/test/units/services/game/coinche_belote/coinche_belote_game_service_test.dart index d9c389b3..e5a8bfda 100644 --- a/test/units/services/game/coinche_belote/coinche_belote_game_service_test.dart +++ b/test/units/services/game/coinche_belote/coinche_belote_game_service_test.dart @@ -17,7 +17,7 @@ import 'coinche_belote_game_service_test.mocks.dart'; CoincheBeloteScoreService, CoincheBeloteGameRepository, PlayerService, - TeamService + TeamService, ]) void main() { final mockCoincheBeloteScoreService = MockCoincheBeloteScoreService(); @@ -30,26 +30,42 @@ void main() { final playerIds = ['p1', 'p2', 'p3', 'p4']; final teamUs = Team(id: 'usTeamId', players: ['p1', 'p2']); final teamThem = Team(id: 'themTeamId', players: ['p3', 'p4']); - final players = - BelotePlayers(us: teamUs.id, them: teamThem.id, playerList: playerIds); + final players = BelotePlayers( + us: teamUs.id, + them: teamThem.id, + playerList: playerIds, + ); - final expectedGame = - CoincheBelote(id: uid, players: players, startingDate: date); + final expectedGame = CoincheBelote( + id: uid, + players: players, + startingDate: date, + ); final expectedGameNoId = CoincheBelote(players: players, startingDate: date); final settings = CoincheBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: true); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: true, + ); group('CoincheBeloteGameService', () { group('Generate a new game', () { test('OK', () async { - when(mockCoincheBeloteGameRepository.create(expectedGameNoId)) - .thenAnswer((_) => Future(() => uid)); + when( + mockCoincheBeloteGameRepository.create(expectedGameNoId), + ).thenAnswer((_) => Future(() => uid)); final coincheBeloteGameService = CoincheBeloteGameService( - coincheBeloteScoreService: mockCoincheBeloteScoreService, - coincheBeloteGameRepository: mockCoincheBeloteGameRepository, - teamService: mockTeamService); + coincheBeloteScoreService: mockCoincheBeloteScoreService, + coincheBeloteGameRepository: mockCoincheBeloteGameRepository, + teamService: mockTeamService, + ); final game = await coincheBeloteGameService.generateNewGame( - teamUs, teamThem, playerIds, date, settings); + teamUs, + teamThem, + playerIds, + date, + settings, + ); expect(game, expectedGame); }); }); diff --git a/test/units/services/game/coinche_belote/coinche_belote_game_service_test.mocks.dart b/test/units/services/game/coinche_belote/coinche_belote_game_service_test.mocks.dart index 9767c272..05b6f63e 100644 --- a/test/units/services/game/coinche_belote/coinche_belote_game_service_test.mocks.dart +++ b/test/units/services/game/coinche_belote/coinche_belote_game_service_test.mocks.dart @@ -48,6 +48,7 @@ import 'package:mockito/src/dummies.dart' as _i19; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractBeloteScoreRepository_0< T extends _i1.BeloteScore<_i2.BeloteRound>> extends _i3.SmartFake @@ -323,21 +324,20 @@ class MockCoincheBeloteGameRepository extends _i3.Mock ) as String); @override - set lastFetchGameDocument( - _i11.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i11.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/game/contree_belote/contree_belote_game_service_test.dart b/test/units/services/game/contree_belote/contree_belote_game_service_test.dart index fde0221a..73d3cb53 100644 --- a/test/units/services/game/contree_belote/contree_belote_game_service_test.dart +++ b/test/units/services/game/contree_belote/contree_belote_game_service_test.dart @@ -17,7 +17,7 @@ import 'contree_belote_game_service_test.mocks.dart'; ContreeBeloteScoreService, ContreeBeloteGameRepository, PlayerService, - TeamService + TeamService, ]) void main() { final mockContreeBeloteScoreService = MockContreeBeloteScoreService(); @@ -30,26 +30,42 @@ void main() { final playerIds = ['p1', 'p2', 'p3', 'p4']; final teamUs = Team(id: 'usTeamId', players: ['p1', 'p2']); final teamThem = Team(id: 'themTeamId', players: ['p3', 'p4']); - final players = - BelotePlayers(us: teamUs.id, them: teamThem.id, playerList: playerIds); + final players = BelotePlayers( + us: teamUs.id, + them: teamThem.id, + playerList: playerIds, + ); - final expectedGame = - ContreeBelote(id: uid, players: players, startingDate: date); + final expectedGame = ContreeBelote( + id: uid, + players: players, + startingDate: date, + ); final expectedGameNoId = ContreeBelote(players: players, startingDate: date); final settings = ContreeBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: true); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: true, + ); group('ContreeBeloteGameService', () { group('Generate a new game', () { test('OK', () async { - when(mockContreeBeloteGameRepository.create(expectedGameNoId)) - .thenAnswer((_) => Future(() => uid)); + when( + mockContreeBeloteGameRepository.create(expectedGameNoId), + ).thenAnswer((_) => Future(() => uid)); final contreeBeloteGameService = ContreeBeloteGameService( - contreeBeloteScoreService: mockContreeBeloteScoreService, - contreeBeloteGameRepository: mockContreeBeloteGameRepository, - teamService: mockTeamService); + contreeBeloteScoreService: mockContreeBeloteScoreService, + contreeBeloteGameRepository: mockContreeBeloteGameRepository, + teamService: mockTeamService, + ); final game = await contreeBeloteGameService.generateNewGame( - teamUs, teamThem, playerIds, date, settings); + teamUs, + teamThem, + playerIds, + date, + settings, + ); expect(game, expectedGame); }); }); diff --git a/test/units/services/game/contree_belote/contree_belote_game_service_test.mocks.dart b/test/units/services/game/contree_belote/contree_belote_game_service_test.mocks.dart index 5c2cce24..1955e568 100644 --- a/test/units/services/game/contree_belote/contree_belote_game_service_test.mocks.dart +++ b/test/units/services/game/contree_belote/contree_belote_game_service_test.mocks.dart @@ -48,6 +48,7 @@ import 'package:mockito/src/dummies.dart' as _i19; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractBeloteScoreRepository_0< T extends _i1.BeloteScore<_i2.BeloteRound>> extends _i3.SmartFake @@ -323,21 +324,20 @@ class MockContreeBeloteGameRepository extends _i3.Mock ) as String); @override - set lastFetchGameDocument( - _i11.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i11.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/game/french_belote/french_belote_game_service_test.dart b/test/units/services/game/french_belote/french_belote_game_service_test.dart index 7c8b1c39..36101042 100644 --- a/test/units/services/game/french_belote/french_belote_game_service_test.dart +++ b/test/units/services/game/french_belote/french_belote_game_service_test.dart @@ -17,7 +17,7 @@ import 'french_belote_game_service_test.mocks.dart'; FrenchBeloteScoreService, FrenchBeloteGameRepository, PlayerService, - TeamService + TeamService, ]) void main() { final mockFrenchBeloteScoreService = MockFrenchBeloteScoreService(); @@ -30,26 +30,42 @@ void main() { final playerIds = ['p1', 'p2', 'p3', 'p4']; final teamUs = Team(id: 'usTeamId', players: ['p1', 'p2']); final teamThem = Team(id: 'themTeamId', players: ['p3', 'p4']); - final players = - BelotePlayers(us: teamUs.id, them: teamThem.id, playerList: playerIds); + final players = BelotePlayers( + us: teamUs.id, + them: teamThem.id, + playerList: playerIds, + ); - final expectedGame = - FrenchBelote(id: uid, players: players, startingDate: date); + final expectedGame = FrenchBelote( + id: uid, + players: players, + startingDate: date, + ); final expectedGameNoId = FrenchBelote(players: players, startingDate: date); final settings = FrenchBeloteGameSetting( - maxPoint: 1000, isInfinite: false, sumTrickPointsAndContract: true); + maxPoint: 1000, + isInfinite: false, + sumTrickPointsAndContract: true, + ); group('FrenchBeloteGameService', () { group('Generate a new game', () { test('OK', () async { - when(mockFrenchBeloteGameRepository.create(expectedGameNoId)) - .thenAnswer((_) => Future(() => uid)); + when( + mockFrenchBeloteGameRepository.create(expectedGameNoId), + ).thenAnswer((_) => Future(() => uid)); final frenchBeloteGameService = FrenchBeloteGameService( - frenchBeloteScoreService: mockFrenchBeloteScoreService, - frenchBeloteGameRepository: mockFrenchBeloteGameRepository, - teamService: mockTeamService); + frenchBeloteScoreService: mockFrenchBeloteScoreService, + frenchBeloteGameRepository: mockFrenchBeloteGameRepository, + teamService: mockTeamService, + ); final game = await frenchBeloteGameService.generateNewGame( - teamUs, teamThem, playerIds, date, settings); + teamUs, + teamThem, + playerIds, + date, + settings, + ); expect(game, expectedGame); }); }); diff --git a/test/units/services/game/french_belote/french_belote_game_service_test.mocks.dart b/test/units/services/game/french_belote/french_belote_game_service_test.mocks.dart index c4f2ce0f..3ae01017 100644 --- a/test/units/services/game/french_belote/french_belote_game_service_test.mocks.dart +++ b/test/units/services/game/french_belote/french_belote_game_service_test.mocks.dart @@ -48,6 +48,7 @@ import 'package:mockito/src/dummies.dart' as _i19; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractBeloteScoreRepository_0< T extends _i1.BeloteScore<_i2.BeloteRound>> extends _i3.SmartFake @@ -323,21 +324,20 @@ class MockFrenchBeloteGameRepository extends _i3.Mock ) as String); @override - set lastFetchGameDocument( - _i11.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i11.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/game/tarot/tarot_game_service_test.dart b/test/units/services/game/tarot/tarot_game_service_test.dart index cfa031bf..a196f6e5 100644 --- a/test/units/services/game/tarot/tarot_game_service_test.dart +++ b/test/units/services/game/tarot/tarot_game_service_test.dart @@ -16,8 +16,12 @@ import 'package:mockito/mockito.dart'; import 'tarot_game_service_test.mocks.dart'; -@GenerateMocks( - [TarotScoreService, TarotGameRepository, PlayerService, TeamService]) +@GenerateMocks([ + TarotScoreService, + TarotGameRepository, + PlayerService, + TeamService, +]) void main() { final mockTarotScoreService = MockTarotScoreService(); final mockTarotGameRepository = MockTarotGameRepository(); @@ -31,17 +35,21 @@ void main() { const players = ['p1', 'p2']; final score = TarotScore( - game: uid, - totalPoints: [tarotPlayerScore, tarotPlayerScore2], - rounds: [TarotRound(attackScore: 100.0, defenseScore: 12.0)], - players: players); + game: uid, + totalPoints: [tarotPlayerScore, tarotPlayerScore2], + rounds: [TarotRound(attackScore: 100.0, defenseScore: 12.0)], + players: players, + ); final game = Tarot( - id: uid, - startingDate: date, - players: TarotPlayers(playerList: ['p1', 'p2'])); + id: uid, + startingDate: date, + players: TarotPlayers(playerList: ['p1', 'p2']), + ); final gameNoId = Tarot( - startingDate: date, players: TarotPlayers(playerList: ['p1', 'p2'])); + startingDate: date, + players: TarotPlayers(playerList: ['p1', 'p2']), + ); final settings = TarotGameSetting(maxPoint: 1000, isInfinite: false); setUp(() { @@ -53,54 +61,72 @@ void main() { group('TarotGameService', () { group('End a game', () { test('OK', () async { - when(mockTarotScoreService.getScoreByGame(uid)) - .thenAnswer((_) => Future(() => score)); + when( + mockTarotScoreService.getScoreByGame(uid), + ).thenAnswer((_) => Future(() => score)); final tarotGameService = TarotGameService( - tarotScoreService: mockTarotScoreService, - tarotGameRepository: mockTarotGameRepository, - playerService: mockPlayerService); + tarotScoreService: mockTarotScoreService, + tarotGameRepository: mockTarotGameRepository, + playerService: mockPlayerService, + ); await tarotGameService.endAGame(game, date); - verify(mockPlayerService.incrementPlayedGamesByOne('p1', game)) - .called(1); - verify(mockPlayerService.incrementPlayedGamesByOne('p2', game)) - .called(1); + verify( + mockPlayerService.incrementPlayedGamesByOne('p1', game), + ).called(1); + verify( + mockPlayerService.incrementPlayedGamesByOne('p2', game), + ).called(1); verify(mockPlayerService.incrementWonGamesByOne('p1', game)).called(1); }); test('Throw exception', () async { final tarotGameService = TarotGameService( - tarotScoreService: mockTarotScoreService, - tarotGameRepository: mockTarotGameRepository, - playerService: mockPlayerService); - expect(tarotGameService.endAGame(null, null), - throwsA(isA())); + tarotScoreService: mockTarotScoreService, + tarotGameRepository: mockTarotGameRepository, + playerService: mockPlayerService, + ); + expect( + tarotGameService.endAGame(null, null), + throwsA(isA()), + ); }); test('Throw exception 2', () async { - when(mockTarotScoreService.getScoreByGame(uid)) - .thenAnswer((_) => Future(() => null)); + when( + mockTarotScoreService.getScoreByGame(uid), + ).thenAnswer((_) => Future(() => null)); final tarotGameService = TarotGameService( - tarotScoreService: mockTarotScoreService, - tarotGameRepository: mockTarotGameRepository, - playerService: mockPlayerService); - expect(tarotGameService.endAGame(game, date), - throwsA(isA())); + tarotScoreService: mockTarotScoreService, + tarotGameRepository: mockTarotGameRepository, + playerService: mockPlayerService, + ); + expect( + tarotGameService.endAGame(game, date), + throwsA(isA()), + ); }); }); group('Create game with players', () { test('OK', () async { - when(mockTarotGameRepository.create(gameNoId)) - .thenAnswer((_) => Future(() => uid)); - when(mockTarotScoreService.create(score)) - .thenAnswer((_) => Future(() => 'scoreId')); + when( + mockTarotGameRepository.create(gameNoId), + ).thenAnswer((_) => Future(() => uid)); + when( + mockTarotScoreService.create(score), + ).thenAnswer((_) => Future(() => 'scoreId')); final tarotGameService = TarotGameService( - tarotScoreService: mockTarotScoreService, - tarotGameRepository: mockTarotGameRepository, - playerService: mockPlayerService); + tarotScoreService: mockTarotScoreService, + tarotGameRepository: mockTarotGameRepository, + playerService: mockPlayerService, + ); await tarotGameService.createGameWithPlayerList( - players, players, date, settings); + players, + players, + date, + settings, + ); verify(mockTarotGameRepository.create(game)).called(1); verify(mockTarotScoreService.create(score)).called(1); }); diff --git a/test/units/services/game/tarot/tarot_game_service_test.mocks.dart b/test/units/services/game/tarot/tarot_game_service_test.mocks.dart index a3cf4598..e219a6fe 100644 --- a/test/units/services/game/tarot/tarot_game_service_test.mocks.dart +++ b/test/units/services/game/tarot/tarot_game_service_test.mocks.dart @@ -44,6 +44,7 @@ import 'package:mockito/src/dummies.dart' as _i17; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractTarotScoreRepository_0 extends _i1.SmartFake implements _i2.AbstractTarotScoreRepository { @@ -306,21 +307,20 @@ class MockTarotGameRepository extends _i1.Mock ) as String); @override - set lastFetchGameDocument( - _i9.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i9.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/player/player_service_test.dart b/test/units/services/player/player_service_test.dart index d717e169..1ccd1e57 100644 --- a/test/units/services/player/player_service_test.dart +++ b/test/units/services/player/player_service_test.dart @@ -12,9 +12,7 @@ import 'player_service_test.mocks.dart'; const uid = '123'; const userId = '123_user'; -@GenerateMocks([ - PlayerRepository, -]) +@GenerateMocks([PlayerRepository]) void main() { final mockPlayerRepository = MockPlayerRepository(); final game = FrenchBelote(); @@ -27,17 +25,20 @@ void main() { group('Create', () { test('OK', () async { final player = Player(owned: true, userName: 'test'); - when(mockPlayerRepository.create(player)) - .thenAnswer((_) async => Future(() => uid)); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); + when( + mockPlayerRepository.create(player), + ).thenAnswer((_) async => Future(() => uid)); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); expect(await playerService.create(player), uid); verify(mockPlayerRepository.create(player)).called(1); }); test('Throw exception', () { - final playerService = - PlayerService(playerRepository: mockPlayerRepository); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); expect(playerService.create(null), throwsA(isA())); verifyNever(mockPlayerRepository.create(null)); }); @@ -46,42 +47,54 @@ void main() { group('Increment played games', () { test('Player exists', () async { final player = Player(owned: true, id: uid); - when(mockPlayerRepository.get(uid)) - .thenAnswer((_) async => Future(() => player)); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); + when( + mockPlayerRepository.get(uid), + ).thenAnswer((_) async => Future(() => player)); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); await playerService.incrementPlayedGamesByOne(uid, game); verify(mockPlayerRepository.update(player)).called(1); }); test('Player does not exist', () async { final player = Player(owned: true, id: uid); - when(mockPlayerRepository.get(uid)) - .thenAnswer((_) async => Future(() => null)); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); - expect(playerService.incrementPlayedGamesByOne(uid, game), - throwsA(isA())); + when( + mockPlayerRepository.get(uid), + ).thenAnswer((_) async => Future(() => null)); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); + expect( + playerService.incrementPlayedGamesByOne(uid, game), + throwsA(isA()), + ); verify(mockPlayerRepository.get(uid)).called(1); verifyNever(mockPlayerRepository.update(player)); }); test('Throw exception Id null', () async { final player = Player(owned: true, id: uid); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); - expect(playerService.incrementPlayedGamesByOne(null, game), - throwsA(isA())); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); + expect( + playerService.incrementPlayedGamesByOne(null, game), + throwsA(isA()), + ); verifyNever(mockPlayerRepository.get(uid)); verifyNever(mockPlayerRepository.update(player)); }); test('Throw exception Game null', () async { final player = Player(owned: true, id: uid); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); - expect(playerService.incrementPlayedGamesByOne(uid, null), - throwsA(isA())); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); + expect( + playerService.incrementPlayedGamesByOne(uid, null), + throwsA(isA()), + ); verifyNever(mockPlayerRepository.get(uid)); verifyNever(mockPlayerRepository.update(player)); }); @@ -90,42 +103,54 @@ void main() { group('Increment won games', () { test('Player exists', () async { final player = Player(owned: true, id: uid); - when(mockPlayerRepository.get(uid)) - .thenAnswer((_) async => Future(() => player)); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); + when( + mockPlayerRepository.get(uid), + ).thenAnswer((_) async => Future(() => player)); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); await playerService.incrementWonGamesByOne(uid, game); verify(mockPlayerRepository.update(player)).called(1); }); test('Player does not exist', () async { final player = Player(owned: true, id: uid); - when(mockPlayerRepository.get(uid)) - .thenAnswer((_) async => Future(() => null)); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); - expect(playerService.incrementWonGamesByOne(uid, game), - throwsA(isA())); + when( + mockPlayerRepository.get(uid), + ).thenAnswer((_) async => Future(() => null)); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); + expect( + playerService.incrementWonGamesByOne(uid, game), + throwsA(isA()), + ); verify(mockPlayerRepository.get(uid)).called(1); verifyNever(mockPlayerRepository.update(player)); }); test('Throw exception Id null', () async { final player = Player(owned: true, id: uid); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); - expect(playerService.incrementWonGamesByOne(null, game), - throwsA(isA())); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); + expect( + playerService.incrementWonGamesByOne(null, game), + throwsA(isA()), + ); verifyNever(mockPlayerRepository.get(uid)); verifyNever(mockPlayerRepository.update(player)); }); test('Throw exception Game null', () async { final player = Player(owned: true, id: uid); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); - expect(playerService.incrementWonGamesByOne(uid, null), - throwsA(isA())); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); + expect( + playerService.incrementWonGamesByOne(uid, null), + throwsA(isA()), + ); verifyNever(mockPlayerRepository.get(uid)); verifyNever(mockPlayerRepository.update(player)); }); @@ -134,19 +159,24 @@ void main() { group('Get player of user', () { test('OK', () async { final player = Player(owned: true, linkedUserId: userId); - when(mockPlayerRepository.getPlayerOfUser(userId)) - .thenAnswer((_) async => Future(() => player)); - final playerService = - PlayerService(playerRepository: mockPlayerRepository); + when( + mockPlayerRepository.getPlayerOfUser(userId), + ).thenAnswer((_) async => Future(() => player)); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); expect(await playerService.getPlayerOfUser(userId), player); verify(mockPlayerRepository.getPlayerOfUser(userId)).called(1); }); test('Throw exception', () async { - final playerService = - PlayerService(playerRepository: mockPlayerRepository); - expect(playerService.getPlayerOfUser(null), - throwsA(isA())); + final playerService = PlayerService( + playerRepository: mockPlayerRepository, + ); + expect( + playerService.getPlayerOfUser(null), + throwsA(isA()), + ); verifyNever(mockPlayerRepository.getPlayerOfUser(null)); }); }); diff --git a/test/units/services/player/player_service_test.mocks.dart b/test/units/services/player/player_service_test.mocks.dart index 53b45a3a..04952fd7 100644 --- a/test/units/services/player/player_service_test.mocks.dart +++ b/test/units/services/player/player_service_test.mocks.dart @@ -24,6 +24,7 @@ import 'package:mockito/src/dummies.dart' as _i4; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseFirestore_0 extends _i1.SmartFake implements _i2.FirebaseFirestore { @@ -81,21 +82,20 @@ class MockPlayerRepository extends _i1.Mock implements _i3.PlayerRepository { ) as String); @override - set lastFetchGameDocument( - _i2.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i2.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/round/abstract_round_service_test.dart b/test/units/services/round/abstract_round_service_test.dart index aa80913c..124f297d 100644 --- a/test/units/services/round/abstract_round_service_test.dart +++ b/test/units/services/round/abstract_round_service_test.dart @@ -13,7 +13,7 @@ import 'abstract_round_service_test.mocks.dart'; class FakeRoundService extends AbstractRoundService { FakeRoundService(MockAbstractScoreService abstractScoreService) - : super(abstractScoreService: abstractScoreService); + : super(abstractScoreService: abstractScoreService); @override BeloteRound getNewRound(GameSetting? settings) { @@ -35,16 +35,18 @@ void main() { group('AbstractRoundService', () { test('edit the last round of a game', () async { - when(mockAbstractScoreService.getScoreByGame(uid)) - .thenAnswer((_) async => Future(() => score)); + when( + mockAbstractScoreService.getScoreByGame(uid), + ).thenAnswer((_) async => Future(() => score)); final roundService = FakeRoundService(mockAbstractScoreService); await roundService.editGameRound(uid, round, 0); verify(mockAbstractScoreService.update(score)).called(1); }); test('delete the last round of a game', () async { - when(mockAbstractScoreService.getScoreByGame(uid)) - .thenAnswer((_) async => Future(() => score)); + when( + mockAbstractScoreService.getScoreByGame(uid), + ).thenAnswer((_) async => Future(() => score)); final roundService = FakeRoundService(mockAbstractScoreService); await roundService.deleteGameRound(uid, 0); verify(mockAbstractScoreService.update(score)).called(1); diff --git a/test/units/services/round/abstract_round_service_test.mocks.dart b/test/units/services/round/abstract_round_service_test.mocks.dart index 31a85c17..b027dbc8 100644 --- a/test/units/services/round/abstract_round_service_test.mocks.dart +++ b/test/units/services/round/abstract_round_service_test.mocks.dart @@ -28,6 +28,7 @@ import 'package:mockito/src/dummies.dart' as _i10; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractScoreRepository_0< T1 extends _i1.Score<_i2.Round<_i3.GameSetting>>> extends _i4.SmartFake diff --git a/test/units/services/round/belote/abstract_belote_round_service_test.dart b/test/units/services/round/belote/abstract_belote_round_service_test.dart index 97761533..cbb4c007 100644 --- a/test/units/services/round/belote/abstract_belote_round_service_test.dart +++ b/test/units/services/round/belote/abstract_belote_round_service_test.dart @@ -12,8 +12,7 @@ import 'package:mockito/mockito.dart'; import 'abstract_belote_round_service_test.mocks.dart'; class FakeBeloteRoundService extends AbstractBeloteRoundService { - FakeBeloteRoundService( - {required super.scoreService}); + FakeBeloteRoundService({required super.scoreService}); @override BeloteRound getNewRound(GameSetting? settings) { @@ -21,27 +20,28 @@ class FakeBeloteRoundService extends AbstractBeloteRoundService { } } -@GenerateMocks([ - FrenchBeloteScoreService, -]) +@GenerateMocks([FrenchBeloteScoreService]) void main() { final mockFrenchBeloteScoreService = MockFrenchBeloteScoreService(); const uid = '123'; final score = FrenchBeloteScore(); final round = FrenchBeloteRound( - index: 0, - takerScore: 300, - defenderScore: 200, - taker: BeloteTeamEnum.US, - defender: BeloteTeamEnum.THEM); + index: 0, + takerScore: 300, + defenderScore: 200, + taker: BeloteTeamEnum.US, + defender: BeloteTeamEnum.THEM, + ); group('TarotRoundService', () { group('Add round to game', () { test('OK', () async { - when(mockFrenchBeloteScoreService.getScoreByGame(uid)) - .thenAnswer((_) async => Future(() => score)); - final roundService = - FakeBeloteRoundService(scoreService: mockFrenchBeloteScoreService); + when( + mockFrenchBeloteScoreService.getScoreByGame(uid), + ).thenAnswer((_) async => Future(() => score)); + final roundService = FakeBeloteRoundService( + scoreService: mockFrenchBeloteScoreService, + ); await roundService.addRoundToGame(uid, round); verify(mockFrenchBeloteScoreService.update(score)).called(1); expect(score.themTotalPoints, 200); diff --git a/test/units/services/round/belote/abstract_belote_round_service_test.mocks.dart b/test/units/services/round/belote/abstract_belote_round_service_test.mocks.dart index 6a173921..7f523c01 100644 --- a/test/units/services/round/belote/abstract_belote_round_service_test.mocks.dart +++ b/test/units/services/round/belote/abstract_belote_round_service_test.mocks.dart @@ -34,6 +34,7 @@ import 'package:mockito/src/dummies.dart' as _i14; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractBeloteScoreRepository_0< T extends _i1.BeloteScore<_i2.BeloteRound>> extends _i3.SmartFake diff --git a/test/units/services/round/tarot/tarot_round_service_test.dart b/test/units/services/round/tarot/tarot_round_service_test.dart index eea4e403..e4bc5c9b 100644 --- a/test/units/services/round/tarot/tarot_round_service_test.dart +++ b/test/units/services/round/tarot/tarot_round_service_test.dart @@ -13,46 +13,50 @@ import 'package:mockito/mockito.dart'; import 'tarot_round_service_test.mocks.dart'; -@GenerateMocks([ - TarotScoreService, -]) +@GenerateMocks([TarotScoreService]) void main() { final mockTarotScoreService = MockTarotScoreService(); const uid = '123'; - final score = TarotScore(totalPoints: [ - TarotPlayerScore(player: 'p1', score: 0), - TarotPlayerScore(player: 'p2', score: 0), - TarotPlayerScore(player: 'p3', score: 0), - TarotPlayerScore(player: 'p4', score: 0) - ]); + final score = TarotScore( + totalPoints: [ + TarotPlayerScore(player: 'p1', score: 0), + TarotPlayerScore(player: 'p2', score: 0), + TarotPlayerScore(player: 'p3', score: 0), + TarotPlayerScore(player: 'p4', score: 0), + ], + ); final totalPoints = [ TarotPlayerScore(player: 'p1', score: 300), TarotPlayerScore(player: 'p2', score: 300 / 3), TarotPlayerScore(player: 'p3', score: 200), - TarotPlayerScore(player: 'p4', score: 200) + TarotPlayerScore(player: 'p4', score: 200), ]; final roundPlayers = TarotRoundPlayers( - attackPlayer: 'p1', - calledPlayer: 'p2', - playerList: ['p1', 'p2', 'p3', 'p4']); + attackPlayer: 'p1', + calledPlayer: 'p2', + playerList: ['p1', 'p2', 'p3', 'p4'], + ); final round = TarotRound( - index: 0, - attackScore: 300, - defenseScore: 200, - attackTrickPoints: 100, - defenseTrickPoints: 200, - oudler: TarotOudler.ONE, - contract: TarotContract.GARDE_CONTRE, - bonus: TarotBonus.CHELEM, - players: roundPlayers); + index: 0, + attackScore: 300, + defenseScore: 200, + attackTrickPoints: 100, + defenseTrickPoints: 200, + oudler: TarotOudler.ONE, + contract: TarotContract.GARDE_CONTRE, + bonus: TarotBonus.CHELEM, + players: roundPlayers, + ); group('TarotRoundService', () { group('Add round to game', () { test('OK', () async { - when(mockTarotScoreService.getScoreByGame(uid)) - .thenAnswer((_) async => Future(() => score)); - final tarotRoundService = - TarotRoundService(tarotScoreService: mockTarotScoreService); + when( + mockTarotScoreService.getScoreByGame(uid), + ).thenAnswer((_) async => Future(() => score)); + final tarotRoundService = TarotRoundService( + tarotScoreService: mockTarotScoreService, + ); await tarotRoundService.addRoundToGame(uid, round); verify(mockTarotScoreService.update(score)).called(1); expect(score.totalPoints, totalPoints); diff --git a/test/units/services/round/tarot/tarot_round_service_test.mocks.dart b/test/units/services/round/tarot/tarot_round_service_test.mocks.dart index 6319d645..7620137a 100644 --- a/test/units/services/round/tarot/tarot_round_service_test.mocks.dart +++ b/test/units/services/round/tarot/tarot_round_service_test.mocks.dart @@ -31,6 +31,7 @@ import 'package:mockito/src/dummies.dart' as _i12; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractTarotScoreRepository_0 extends _i1.SmartFake implements _i2.AbstractTarotScoreRepository { diff --git a/test/units/services/score/abstract_score_service_test.dart b/test/units/services/score/abstract_score_service_test.dart index 53afb098..8a961235 100644 --- a/test/units/services/score/abstract_score_service_test.dart +++ b/test/units/services/score/abstract_score_service_test.dart @@ -9,13 +9,10 @@ import '../../mocks/fake_score.dart'; import 'abstract_score_service_test.mocks.dart'; class FakeScoreService extends AbstractScoreService { - FakeScoreService( - {required super.scoreRepository}); + FakeScoreService({required super.scoreRepository}); } -@GenerateMocks([ - AbstractScoreRepository, -]) +@GenerateMocks([AbstractScoreRepository]) void main() { final mockAbstractScoreRepository = MockAbstractScoreRepository(); const uid = '123'; @@ -29,51 +26,65 @@ void main() { group('AbstractScoreService', () { group('Get score by game', () { test('OK', () async { - when(mockAbstractScoreRepository.getScoreByGame(uid)) - .thenAnswer((_) async => Future(() => score)); - final scoreService = - FakeScoreService(scoreRepository: mockAbstractScoreRepository); + when( + mockAbstractScoreRepository.getScoreByGame(uid), + ).thenAnswer((_) async => Future(() => score)); + final scoreService = FakeScoreService( + scoreRepository: mockAbstractScoreRepository, + ); expect(await scoreService.getScoreByGame(uid), score); }); test('NOK - Exception', () { - final scoreService = - FakeScoreService(scoreRepository: mockAbstractScoreRepository); - expect(scoreService.getScoreByGame(null), - throwsA(isA())); + final scoreService = FakeScoreService( + scoreRepository: mockAbstractScoreRepository, + ); + expect( + scoreService.getScoreByGame(null), + throwsA(isA()), + ); }); }); group('Get score by game STREAM', () { test('OK', () { - when(mockAbstractScoreRepository.getScoreByGameStream(uid)) - .thenAnswer((_) => Stream.value(score)); - final scoreService = - FakeScoreService(scoreRepository: mockAbstractScoreRepository); + when( + mockAbstractScoreRepository.getScoreByGameStream(uid), + ).thenAnswer((_) => Stream.value(score)); + final scoreService = FakeScoreService( + scoreRepository: mockAbstractScoreRepository, + ); scoreService.getScoreByGameStream(uid); }); test('NOK - Exception', () async* { - final scoreService = - FakeScoreService(scoreRepository: mockAbstractScoreRepository); - expect(scoreService.getScoreByGameStream(null), - throwsA(isA())); + final scoreService = FakeScoreService( + scoreRepository: mockAbstractScoreRepository, + ); + expect( + scoreService.getScoreByGameStream(null), + throwsA(isA()), + ); }); }); group('Delete score by game', () { test('OK', () async { - final scoreService = - FakeScoreService(scoreRepository: mockAbstractScoreRepository); + final scoreService = FakeScoreService( + scoreRepository: mockAbstractScoreRepository, + ); await scoreService.deleteScoreByGame(uid); verify(mockAbstractScoreRepository.deleteScoreByGame(uid)).called(1); }); test('NOK - Exception', () { - final scoreService = - FakeScoreService(scoreRepository: mockAbstractScoreRepository); - expect(scoreService.deleteScoreByGame(null), - throwsA(isA())); + final scoreService = FakeScoreService( + scoreRepository: mockAbstractScoreRepository, + ); + expect( + scoreService.deleteScoreByGame(null), + throwsA(isA()), + ); }); }); }); diff --git a/test/units/services/score/abstract_score_service_test.mocks.dart b/test/units/services/score/abstract_score_service_test.mocks.dart index c32793e2..54ae00f2 100644 --- a/test/units/services/score/abstract_score_service_test.mocks.dart +++ b/test/units/services/score/abstract_score_service_test.mocks.dart @@ -26,6 +26,7 @@ import 'package:mockito/src/dummies.dart' as _i7; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseFirestore_0 extends _i1.SmartFake implements _i2.FirebaseFirestore { @@ -85,21 +86,20 @@ class MockAbstractScoreRepository< ) as String); @override - set lastFetchGameDocument( - _i2.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i2.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/score/coinche_belote/coinche_belote_score_service_test.dart b/test/units/services/score/coinche_belote/coinche_belote_score_service_test.dart index 7bfc8c69..0bbac3d4 100644 --- a/test/units/services/score/coinche_belote/coinche_belote_score_service_test.dart +++ b/test/units/services/score/coinche_belote/coinche_belote_score_service_test.dart @@ -7,9 +7,7 @@ import 'package:mockito/mockito.dart'; import 'coinche_belote_score_service_test.mocks.dart'; -@GenerateMocks([ - CoincheBeloteScoreRepository, -]) +@GenerateMocks([CoincheBeloteScoreRepository]) void main() { final mockCoincheBeloteScoreRepository = MockCoincheBeloteScoreRepository(); const uid = '123'; @@ -23,14 +21,19 @@ void main() { group('CoincheBeloteScoreService', () { group('Generate New Score', () { test('OK', () async { - when(mockCoincheBeloteScoreRepository.create(coincheBeloteScore)) - .thenAnswer((_) async => Future(() => scoreId)); + when( + mockCoincheBeloteScoreRepository.create(coincheBeloteScore), + ).thenAnswer((_) async => Future(() => scoreId)); final coincheBeloteScoreService = CoincheBeloteScoreService( - coincheBeloteScoreRepository: mockCoincheBeloteScoreRepository); - expect(await coincheBeloteScoreService.generateNewScore(uid), - coincheBeloteScore); - verify(mockCoincheBeloteScoreRepository.create(coincheBeloteScore)) - .called(1); + coincheBeloteScoreRepository: mockCoincheBeloteScoreRepository, + ); + expect( + await coincheBeloteScoreService.generateNewScore(uid), + coincheBeloteScore, + ); + verify( + mockCoincheBeloteScoreRepository.create(coincheBeloteScore), + ).called(1); }); }); }); diff --git a/test/units/services/score/coinche_belote/coinche_belote_score_service_test.mocks.dart b/test/units/services/score/coinche_belote/coinche_belote_score_service_test.mocks.dart index fdc2e8b8..48d39356 100644 --- a/test/units/services/score/coinche_belote/coinche_belote_score_service_test.mocks.dart +++ b/test/units/services/score/coinche_belote/coinche_belote_score_service_test.mocks.dart @@ -25,6 +25,7 @@ import 'package:mockito/src/dummies.dart' as _i4; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseFirestore_0 extends _i1.SmartFake implements _i2.FirebaseFirestore { @@ -83,21 +84,20 @@ class MockCoincheBeloteScoreRepository extends _i1.Mock ) as String); @override - set lastFetchGameDocument( - _i2.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i2.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/score/contree_belote/contree_belote_score_service_test.dart b/test/units/services/score/contree_belote/contree_belote_score_service_test.dart index 13c3110d..ea3f32a1 100644 --- a/test/units/services/score/contree_belote/contree_belote_score_service_test.dart +++ b/test/units/services/score/contree_belote/contree_belote_score_service_test.dart @@ -7,9 +7,7 @@ import 'package:mockito/mockito.dart'; import 'contree_belote_score_service_test.mocks.dart'; -@GenerateMocks([ - ContreeBeloteScoreRepository, -]) +@GenerateMocks([ContreeBeloteScoreRepository]) void main() { final mockContreeBeloteScoreRepository = MockContreeBeloteScoreRepository(); const uid = '123'; @@ -23,14 +21,19 @@ void main() { group('ContreeBeloteScoreService', () { group('Generate New Score', () { test('OK', () async { - when(mockContreeBeloteScoreRepository.create(contreeBeloteScore)) - .thenAnswer((_) async => Future(() => scoreId)); + when( + mockContreeBeloteScoreRepository.create(contreeBeloteScore), + ).thenAnswer((_) async => Future(() => scoreId)); final contreeBeloteScoreService = ContreeBeloteScoreService( - contreeBeloteScoreRepository: mockContreeBeloteScoreRepository); - expect(await contreeBeloteScoreService.generateNewScore(uid), - contreeBeloteScore); - verify(mockContreeBeloteScoreRepository.create(contreeBeloteScore)) - .called(1); + contreeBeloteScoreRepository: mockContreeBeloteScoreRepository, + ); + expect( + await contreeBeloteScoreService.generateNewScore(uid), + contreeBeloteScore, + ); + verify( + mockContreeBeloteScoreRepository.create(contreeBeloteScore), + ).called(1); }); }); }); diff --git a/test/units/services/score/contree_belote/contree_belote_score_service_test.mocks.dart b/test/units/services/score/contree_belote/contree_belote_score_service_test.mocks.dart index d8e739da..0d7ebe28 100644 --- a/test/units/services/score/contree_belote/contree_belote_score_service_test.mocks.dart +++ b/test/units/services/score/contree_belote/contree_belote_score_service_test.mocks.dart @@ -25,6 +25,7 @@ import 'package:mockito/src/dummies.dart' as _i4; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseFirestore_0 extends _i1.SmartFake implements _i2.FirebaseFirestore { @@ -83,21 +84,20 @@ class MockContreeBeloteScoreRepository extends _i1.Mock ) as String); @override - set lastFetchGameDocument( - _i2.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i2.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/score/french_belote/french_belote_score_service_test.dart b/test/units/services/score/french_belote/french_belote_score_service_test.dart index 24f8af52..5ba58cf1 100644 --- a/test/units/services/score/french_belote/french_belote_score_service_test.dart +++ b/test/units/services/score/french_belote/french_belote_score_service_test.dart @@ -7,9 +7,7 @@ import 'package:mockito/mockito.dart'; import 'french_belote_score_service_test.mocks.dart'; -@GenerateMocks([ - FrenchBeloteScoreRepository, -]) +@GenerateMocks([FrenchBeloteScoreRepository]) void main() { final mockFrenchBeloteScoreRepository = MockFrenchBeloteScoreRepository(); const uid = '123'; @@ -23,14 +21,19 @@ void main() { group('FrenchBeloteScoreService', () { group('Generate New Score', () { test('OK', () async { - when(mockFrenchBeloteScoreRepository.create(frenchBeloteScore)) - .thenAnswer((_) async => Future(() => scoreId)); + when( + mockFrenchBeloteScoreRepository.create(frenchBeloteScore), + ).thenAnswer((_) async => Future(() => scoreId)); final frenchBeloteScoreService = FrenchBeloteScoreService( - frenchBeloteScoreRepository: mockFrenchBeloteScoreRepository); - expect(await frenchBeloteScoreService.generateNewScore(uid), - frenchBeloteScore); - verify(mockFrenchBeloteScoreRepository.create(frenchBeloteScore)) - .called(1); + frenchBeloteScoreRepository: mockFrenchBeloteScoreRepository, + ); + expect( + await frenchBeloteScoreService.generateNewScore(uid), + frenchBeloteScore, + ); + verify( + mockFrenchBeloteScoreRepository.create(frenchBeloteScore), + ).called(1); }); }); }); diff --git a/test/units/services/score/french_belote/french_belote_score_service_test.mocks.dart b/test/units/services/score/french_belote/french_belote_score_service_test.mocks.dart index 045d1d63..917fca4f 100644 --- a/test/units/services/score/french_belote/french_belote_score_service_test.mocks.dart +++ b/test/units/services/score/french_belote/french_belote_score_service_test.mocks.dart @@ -25,6 +25,7 @@ import 'package:mockito/src/dummies.dart' as _i4; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseFirestore_0 extends _i1.SmartFake implements _i2.FirebaseFirestore { @@ -83,21 +84,20 @@ class MockFrenchBeloteScoreRepository extends _i1.Mock ) as String); @override - set lastFetchGameDocument( - _i2.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i2.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/team/team_service_test.dart b/test/units/services/team/team_service_test.dart index e7c5a3f9..e2d66cc9 100644 --- a/test/units/services/team/team_service_test.dart +++ b/test/units/services/team/team_service_test.dart @@ -16,10 +16,7 @@ import 'team_service_test.mocks.dart'; const uid = '123'; var playerIds = ['p1', 'p2']; -@GenerateMocks([ - TeamRepository, - PlayerService, -]) +@GenerateMocks([TeamRepository, PlayerService]) void main() { final mockTeamRepository = MockTeamRepository(); final mockPlayerService = MockPlayerService(); @@ -32,55 +29,83 @@ void main() { group('TeamService - ', () { group('Get Team By Players', () { test('Team exists', () async { - final team = - Team(id: uid, wonGames: 0, playedGames: 1, players: ['p1', 'p2']); - final expectedTeam = - Team(id: uid, wonGames: 0, playedGames: 1, players: ['p1', 'p2']); - when(mockTeamRepository.getTeamByPlayers(playerIds)) - .thenAnswer((_) async => Future(() => team)); + final team = Team( + id: uid, + wonGames: 0, + playedGames: 1, + players: ['p1', 'p2'], + ); + final expectedTeam = Team( + id: uid, + wonGames: 0, + playedGames: 1, + players: ['p1', 'p2'], + ); + when( + mockTeamRepository.getTeamByPlayers(playerIds), + ).thenAnswer((_) async => Future(() => team)); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); expect(await teamService.getTeamByPlayers(playerIds), expectedTeam); verify(mockTeamRepository.getTeamByPlayers(playerIds)).called(1); verifyNever(mockTeamRepository.createTeamWithPlayers(playerIds)); }); test('Team does not exist', () async { - final team = - Team(id: uid, wonGames: 0, playedGames: 1, players: ['p1', 'p2']); - final expectedTeam = - Team(id: uid, wonGames: 0, playedGames: 1, players: ['p1', 'p2']); - when(mockTeamRepository.getTeamByPlayers(playerIds)) - .thenAnswer((_) async => Future(() => null)); - when(mockTeamRepository.createTeamWithPlayers(playerIds)) - .thenAnswer((_) async => Future(() => team)); + final team = Team( + id: uid, + wonGames: 0, + playedGames: 1, + players: ['p1', 'p2'], + ); + final expectedTeam = Team( + id: uid, + wonGames: 0, + playedGames: 1, + players: ['p1', 'p2'], + ); + when( + mockTeamRepository.getTeamByPlayers(playerIds), + ).thenAnswer((_) async => Future(() => null)); + when( + mockTeamRepository.createTeamWithPlayers(playerIds), + ).thenAnswer((_) async => Future(() => team)); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); expect(await teamService.getTeamByPlayers(playerIds), expectedTeam); verify(mockTeamRepository.getTeamByPlayers(playerIds)).called(1); verify(mockTeamRepository.createTeamWithPlayers(playerIds)).called(1); }); test('Throw exception (from repository)', () async { - when(mockTeamRepository.getTeamByPlayers(playerIds)) - .thenThrow(RepositoryException('error')); + when( + mockTeamRepository.getTeamByPlayers(playerIds), + ).thenThrow(RepositoryException('error')); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.getTeamByPlayers(playerIds), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.getTeamByPlayers(playerIds), + throwsA(isA()), + ); verify(mockTeamRepository.getTeamByPlayers(playerIds)).called(1); verifyNever(mockTeamRepository.createTeamWithPlayers(playerIds)); }); test('Throw exception (from service)', () async { final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.getTeamByPlayers(null), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.getTeamByPlayers(null), + throwsA(isA()), + ); verifyNever(mockTeamRepository.getTeamByPlayers(playerIds)); verifyNever(mockTeamRepository.createTeamWithPlayers(playerIds)); }); @@ -88,79 +113,119 @@ void main() { group('Increment played games', () { test('Team exists', () async { - final gameStat = - GameStats(gameType: GameType.COINCHE, wonGames: 0, playedGames: 1); - final team = - Team(id: uid, gameStatsList: [gameStat], players: ['p1', 'p2']); + final gameStat = GameStats( + gameType: GameType.COINCHE, + wonGames: 0, + playedGames: 1, + ); + final team = Team( + id: uid, + gameStatsList: [gameStat], + players: ['p1', 'p2'], + ); - when(mockTeamRepository.get(uid)) - .thenAnswer((_) async => Future(() => team)); + when( + mockTeamRepository.get(uid), + ).thenAnswer((_) async => Future(() => team)); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); expect( - (await teamService.incrementPlayedGamesByOne(uid, game)) - .totalPlayedGames(), - 2); + (await teamService.incrementPlayedGamesByOne( + uid, + game, + )).totalPlayedGames(), + 2, + ); verify(mockTeamRepository.update(team)); - verify(mockPlayerService.incrementPlayedGamesByOne('p1', game)) - .called(1); + verify( + mockPlayerService.incrementPlayedGamesByOne('p1', game), + ).called(1); }); test('Team does not exist', () async { - final team = - Team(id: uid, wonGames: 0, playedGames: 1, players: ['p1', 'p2']); - when(mockTeamRepository.get(uid)) - .thenAnswer((_) async => Future(() => null)); - when(mockTeamRepository.createTeamWithPlayers(playerIds)) - .thenAnswer((_) async => Future(() => team)); + final team = Team( + id: uid, + wonGames: 0, + playedGames: 1, + players: ['p1', 'p2'], + ); + when( + mockTeamRepository.get(uid), + ).thenAnswer((_) async => Future(() => null)); + when( + mockTeamRepository.createTeamWithPlayers(playerIds), + ).thenAnswer((_) async => Future(() => team)); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.incrementPlayedGamesByOne(null, game), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.incrementPlayedGamesByOne(null, game), + throwsA(isA()), + ); }); test('Throw exception (from repository)', () async { - when(mockTeamRepository.get(uid)) - .thenThrow(RepositoryException('error')); + when( + mockTeamRepository.get(uid), + ).thenThrow(RepositoryException('error')); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.incrementPlayedGamesByOne(uid, game), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.incrementPlayedGamesByOne(uid, game), + throwsA(isA()), + ); }); test('Throw exception GAME (from service)', () async { final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.incrementPlayedGamesByOne(uid, null), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.incrementPlayedGamesByOne(uid, null), + throwsA(isA()), + ); }); test('Throw exception GAME (team = null)', () async { final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - when(mockTeamRepository.get(uid)) - .thenAnswer((_) async => Future(() => null)); - expect(teamService.incrementPlayedGamesByOne(uid, game), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + when( + mockTeamRepository.get(uid), + ).thenAnswer((_) async => Future(() => null)); + expect( + teamService.incrementPlayedGamesByOne(uid, game), + throwsA(isA()), + ); }); }); group('Increment won games', () { - final gameStat = - GameStats(gameType: GameType.COINCHE, wonGames: 0, playedGames: 0); - final team = - Team(id: uid, gameStatsList: [gameStat], players: ['p1', 'p2']); + final gameStat = GameStats( + gameType: GameType.COINCHE, + wonGames: 0, + playedGames: 0, + ); + final team = Team( + id: uid, + gameStatsList: [gameStat], + players: ['p1', 'p2'], + ); test('Team exists', () async { - when(mockTeamRepository.get(uid)) - .thenAnswer((_) async => Future(() => team)); + when( + mockTeamRepository.get(uid), + ).thenAnswer((_) async => Future(() => team)); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); final editedTeam = await teamService.incrementWonGamesByOne(uid, game); expect(editedTeam.totalWonGames(), 1); expect(editedTeam.totalPlayedGames(), 0); @@ -170,41 +235,57 @@ void main() { }); test('Team does not exist', () async { - when(mockTeamRepository.get(uid)) - .thenAnswer((_) async => Future(() => null)); - when(mockTeamRepository.createTeamWithPlayers(playerIds)) - .thenAnswer((_) async => Future(() => team)); + when( + mockTeamRepository.get(uid), + ).thenAnswer((_) async => Future(() => null)); + when( + mockTeamRepository.createTeamWithPlayers(playerIds), + ).thenAnswer((_) async => Future(() => team)); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.incrementWonGamesByOne(null, game), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.incrementWonGamesByOne(null, game), + throwsA(isA()), + ); }); test('Throw exception (from repository)', () async { - when(mockTeamRepository.get(uid)) - .thenThrow(RepositoryException('error')); + when( + mockTeamRepository.get(uid), + ).thenThrow(RepositoryException('error')); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.incrementWonGamesByOne(uid, game), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.incrementWonGamesByOne(uid, game), + throwsA(isA()), + ); }); test('Throw exception GAME (from service)', () async { final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.incrementWonGamesByOne(uid, null), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.incrementWonGamesByOne(uid, null), + throwsA(isA()), + ); }); test('Throw exception GAME (team = null)', () async { final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - when(mockTeamRepository.get(uid)) - .thenAnswer((_) async => Future(() => null)); - expect(teamService.incrementWonGamesByOne(uid, game), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + when( + mockTeamRepository.get(uid), + ).thenAnswer((_) async => Future(() => null)); + expect( + teamService.incrementWonGamesByOne(uid, game), + throwsA(isA()), + ); }); }); group('Get all teams of players', () { @@ -213,45 +294,58 @@ void main() { const pageSize = 10; final List teams = [ Team(id: uid, players: ['p1', 'p2']), - Team(id: uid, players: ['p1', 'p2']) + Team(id: uid, players: ['p1', 'p2']), ]; - when(mockTeamRepository.getAllTeamOfPlayer(playerId, pageSize)) - .thenAnswer((_) async => Future>(() => teams)); + when( + mockTeamRepository.getAllTeamOfPlayer(playerId, pageSize), + ).thenAnswer((_) async => Future>(() => teams)); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); expect(await teamService.getAllTeamOfPlayer(playerId, pageSize), teams); - verify(mockTeamRepository.getAllTeamOfPlayer(playerId, pageSize)) - .called(1); + verify( + mockTeamRepository.getAllTeamOfPlayer(playerId, pageSize), + ).called(1); }); test('Throw exception GAME (playerId = null)', () async { final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.getAllTeamOfPlayer(null, 10), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.getAllTeamOfPlayer(null, 10), + throwsA(isA()), + ); }); test('Throw exception GAME (page = null)', () async { const playerId = 'p1'; final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.getAllTeamOfPlayer(playerId, null), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.getAllTeamOfPlayer(playerId, null), + throwsA(isA()), + ); }); test('Throw exception (from repository)', () async { const playerId = 'p1'; - when(mockTeamRepository.getAllTeamOfPlayer(playerId, 10)) - .thenThrow(RepositoryException('error')); + when( + mockTeamRepository.getAllTeamOfPlayer(playerId, 10), + ).thenThrow(RepositoryException('error')); final teamService = TeamService( - teamRepository: mockTeamRepository, - playerService: mockPlayerService); - expect(teamService.getAllTeamOfPlayer(playerId, 10), - throwsA(isA())); + teamRepository: mockTeamRepository, + playerService: mockPlayerService, + ); + expect( + teamService.getAllTeamOfPlayer(playerId, 10), + throwsA(isA()), + ); }); }); }); diff --git a/test/units/services/team/team_service_test.mocks.dart b/test/units/services/team/team_service_test.mocks.dart index 4547119a..ae9dc71a 100644 --- a/test/units/services/team/team_service_test.mocks.dart +++ b/test/units/services/team/team_service_test.mocks.dart @@ -33,6 +33,7 @@ import 'package:mockito/src/dummies.dart' as _i8; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeFirebaseFirestore_0 extends _i1.SmartFake implements _i2.FirebaseFirestore { @@ -122,21 +123,20 @@ class MockTeamRepository extends _i1.Mock implements _i7.TeamRepository { ) as String); @override - set lastFetchGameDocument( - _i2.DocumentSnapshot? _lastFetchGameDocument) => + set lastFetchGameDocument(_i2.DocumentSnapshot? value) => super.noSuchMethod( Invocation.setter( #lastFetchGameDocument, - _lastFetchGameDocument, + value, ), returnValueForMissingStub: null, ); @override - set connectionString(String? _connectionString) => super.noSuchMethod( + set connectionString(String? value) => super.noSuchMethod( Invocation.setter( #connectionString, - _connectionString, + value, ), returnValueForMissingStub: null, ); diff --git a/test/units/services/theme/theme_service_test.dart b/test/units/services/theme/theme_service_test.dart new file mode 100644 index 00000000..923ea87b --- /dev/null +++ b/test/units/services/theme/theme_service_test.dart @@ -0,0 +1,59 @@ +import 'package:carg/services/storage_service.dart'; +import 'package:carg/styles/theme/enums.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; + +import 'theme_service_test.mocks.dart'; + +@GenerateMocks([StorageService]) +void main() { + late MockStorageService mockStorageService; + + setUp(() { + mockStorageService = MockStorageService(); + + // Default behavior - dynamic colors disabled + when(mockStorageService.readDynamicColors()).thenReturn(false); + when(mockStorageService.readTheme()).thenReturn(ThemeValue.system); + when(mockStorageService.readContrast()).thenReturn(ContrastValue.none); + }); + + group('ThemeService - Dynamic Colors Storage Interaction', () { + test('Should read dynamic colors from storage on initialization', () { + when(mockStorageService.readDynamicColors()).thenReturn(true); + + // We can't fully test ThemeService without a proper BuildContext, + // but we can verify the storage interaction + verifyNever(mockStorageService.readDynamicColors()); + + // The actual reading happens in ThemeService constructor + // This test just verifies our mock setup works + expect(mockStorageService.readDynamicColors(), true); + }); + + test('Should save dynamic colors when enabled', () async { + when( + mockStorageService.saveDynamicColors(true), + ).thenAnswer((_) async => true); + + // Simulate what happens when useDynamicColors setter is called + final result = await mockStorageService.saveDynamicColors(true); + + expect(result, true); + verify(mockStorageService.saveDynamicColors(true)).called(1); + }); + + test('Should save dynamic colors when disabled', () async { + when( + mockStorageService.saveDynamicColors(false), + ).thenAnswer((_) async => true); + + // Simulate what happens when useDynamicColors setter is called + final result = await mockStorageService.saveDynamicColors(false); + + expect(result, true); + verify(mockStorageService.saveDynamicColors(false)).called(1); + }); + }); +} diff --git a/test/units/services/theme/theme_service_test.mocks.dart b/test/units/services/theme/theme_service_test.mocks.dart new file mode 100644 index 00000000..e9902300 --- /dev/null +++ b/test/units/services/theme/theme_service_test.mocks.dart @@ -0,0 +1,83 @@ +// Mocks generated by Mockito 5.4.6 from annotations +// in carg/test/units/services/theme/theme_service_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i4; + +import 'package:carg/services/storage_service.dart' as _i3; +import 'package:carg/styles/theme/enums.dart' as _i5; +import 'package:mockito/mockito.dart' as _i1; +import 'package:shared_preferences/shared_preferences.dart' as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: must_be_immutable +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member + +class _FakeSharedPreferences_0 extends _i1.SmartFake + implements _i2.SharedPreferences { + _FakeSharedPreferences_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [StorageService]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockStorageService extends _i1.Mock implements _i3.StorageService { + MockStorageService() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.SharedPreferences get sharedPreferences => (super.noSuchMethod( + Invocation.getter(#sharedPreferences), + returnValue: _FakeSharedPreferences_0( + this, + Invocation.getter(#sharedPreferences), + ), + ) as _i2.SharedPreferences); + + @override + _i4.Future saveTheme(_i5.ThemeValue? value) => (super.noSuchMethod( + Invocation.method( + #saveTheme, + [value], + ), + returnValue: _i4.Future.value(false), + ) as _i4.Future); + + @override + _i4.Future saveContrast(_i5.ContrastValue? value) => + (super.noSuchMethod( + Invocation.method( + #saveContrast, + [value], + ), + returnValue: _i4.Future.value(false), + ) as _i4.Future); + + @override + _i4.Future saveDynamicColors(bool? value) => (super.noSuchMethod( + Invocation.method( + #saveDynamicColors, + [value], + ), + returnValue: _i4.Future.value(false), + ) as _i4.Future); +} diff --git a/test/widgets/ad_banner_widget_test.dart b/test/widgets/ad_banner_widget_test.dart index 99d6c1cc..270b1a94 100644 --- a/test/widgets/ad_banner_widget_test.dart +++ b/test/widgets/ad_banner_widget_test.dart @@ -10,9 +10,11 @@ import 'package:provider/provider.dart'; import 'ad_banner_widget_test.mocks.dart'; Widget testableWidget(AuthService mockAuthService) => MaterialApp( - home: ChangeNotifierProvider.value( - value: mockAuthService, - builder: (context, _) => const AdBannerWidget())); + home: ChangeNotifierProvider.value( + value: mockAuthService, + builder: (context, _) => const AdBannerWidget(), + ), +); @GenerateMocks([AuthService]) void main() { diff --git a/test/widgets/ad_banner_widget_test.mocks.dart b/test/widgets/ad_banner_widget_test.mocks.dart index 002732c5..11ebd058 100644 --- a/test/widgets/ad_banner_widget_test.mocks.dart +++ b/test/widgets/ad_banner_widget_test.mocks.dart @@ -25,6 +25,7 @@ import 'package:mockito/src/dummies.dart' as _i5; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeWidget_0 extends _i1.SmartFake implements _i2.Widget { _FakeWidget_0( diff --git a/test/widgets/belote_widget_test.dart b/test/widgets/belote_widget_test.dart index 1236c761..430df093 100644 --- a/test/widgets/belote_widget_test.dart +++ b/test/widgets/belote_widget_test.dart @@ -33,27 +33,32 @@ final mockAbstractBeloteRoundService = MockAbstractBeloteRoundService(); final mockAbstractPlayerService = MockAbstractPlayerService(); Widget testableWidget(Belote beloteGame) => localizedTestableWidget( - BeloteWidget( - beloteGame: beloteGame, - gameService: mockAbstractBeloteGameService, - scoreService: mockAbstractBeloteScoreService, - teamService: mockAbstractTeamService, - roundService: mockAbstractBeloteRoundService, - playerService: mockAbstractPlayerService), - ); + BeloteWidget( + beloteGame: beloteGame, + gameService: mockAbstractBeloteGameService, + scoreService: mockAbstractBeloteScoreService, + teamService: mockAbstractTeamService, + roundService: mockAbstractBeloteRoundService, + playerService: mockAbstractPlayerService, + ), +); Object getNewRound(GameSetting? settings) => {}; -@GenerateMocks([ - AbstractBeloteGameService, - AbstractBeloteScoreService, - AbstractTeamService, - AbstractPlayerService -], customMocks: [ - MockSpec( +@GenerateMocks( + [ + AbstractBeloteGameService, + AbstractBeloteScoreService, + AbstractTeamService, + AbstractPlayerService, + ], + customMocks: [ + MockSpec( unsupportedMembers: {#getNewRound}, - fallbackGenerators: {#getNewRound: getNewRound}) -]) + fallbackGenerators: {#getNewRound: getNewRound}, + ), + ], +) void main() { late FrenchBelote frenchBelote; late CoincheBelote coincheBelote; @@ -73,114 +78,154 @@ void main() { final Player player4 = Player(owned: false, id: 'p4', userName: 'player 4'); final BelotePlayers players = BelotePlayers( - us: teamId1, them: teamId2, playerList: ['p1', 'p2', 'p3', 'p4']); - - final FrenchBeloteScore frenchBeloteScore = FrenchBeloteScore(rounds: [ - FrenchBeloteRound( + us: teamId1, + them: teamId2, + playerList: ['p1', 'p2', 'p3', 'p4'], + ); + + final FrenchBeloteScore frenchBeloteScore = FrenchBeloteScore( + rounds: [ + FrenchBeloteRound( taker: BeloteTeamEnum.THEM, defender: BeloteTeamEnum.US, defenderScore: 90, - takerScore: 110) - ], themTotalPoints: 110, usTotalPoints: 90); - final CoincheBeloteScore coincheBeloteScore = CoincheBeloteScore(rounds: [ - CoincheBeloteRound( + takerScore: 110, + ), + ], + themTotalPoints: 110, + usTotalPoints: 90, + ); + final CoincheBeloteScore coincheBeloteScore = CoincheBeloteScore( + rounds: [ + CoincheBeloteRound( taker: BeloteTeamEnum.THEM, defender: BeloteTeamEnum.US, defenderScore: 90, - takerScore: 110) - ], themTotalPoints: 110, usTotalPoints: 90); + takerScore: 110, + ), + ], + themTotalPoints: 110, + usTotalPoints: 90, + ); setUp(() { - when(mockAbstractTeamService.get(teamId1)) - .thenAnswer((_) => Future(() => team1)); - when(mockAbstractTeamService.get(teamId2)) - .thenAnswer((_) => Future(() => team2)); - when(mockAbstractBeloteScoreService.getScoreByGame(gameId1)) - .thenAnswer((_) => Future(() => frenchBeloteScore)); - when(mockAbstractBeloteScoreService.getScoreByGame(gameId2)) - .thenAnswer((_) => Future(() => coincheBeloteScore)); - when(mockAbstractPlayerService.get('p1')) - .thenAnswer((_) => Future(() => player1)); - when(mockAbstractPlayerService.get('p2')) - .thenAnswer((_) => Future(() => player2)); - when(mockAbstractPlayerService.get('p3')) - .thenAnswer((_) => Future(() => player3)); - when(mockAbstractPlayerService.get('p4')) - .thenAnswer((_) => Future(() => player4)); + when( + mockAbstractTeamService.get(teamId1), + ).thenAnswer((_) => Future(() => team1)); + when( + mockAbstractTeamService.get(teamId2), + ).thenAnswer((_) => Future(() => team2)); + when( + mockAbstractBeloteScoreService.getScoreByGame(gameId1), + ).thenAnswer((_) => Future(() => frenchBeloteScore)); + when( + mockAbstractBeloteScoreService.getScoreByGame(gameId2), + ).thenAnswer((_) => Future(() => coincheBeloteScore)); + when( + mockAbstractPlayerService.get('p1'), + ).thenAnswer((_) => Future(() => player1)); + when( + mockAbstractPlayerService.get('p2'), + ).thenAnswer((_) => Future(() => player2)); + when( + mockAbstractPlayerService.get('p3'), + ).thenAnswer((_) => Future(() => player3)); + when( + mockAbstractPlayerService.get('p4'), + ).thenAnswer((_) => Future(() => player4)); frenchBelote = FrenchBelote( - id: gameId1, - isEnded: true, - startingDate: DateTime(2020, 9, 7, 17, 30), - players: players); + id: gameId1, + isEnded: true, + startingDate: DateTime(2020, 9, 7, 17, 30), + players: players, + ); coincheBelote = CoincheBelote( - id: gameId2, - isEnded: false, - startingDate: DateTime(2017, 9, 7, 17, 30), - players: players); + id: gameId2, + isEnded: false, + startingDate: DateTime(2017, 9, 7, 17, 30), + players: players, + ); contreeBelote = ContreeBelote( - id: gameId2, - isEnded: true, - startingDate: DateTime(2017, 9, 7, 17, 30), - players: players); + id: gameId2, + isEnded: true, + startingDate: DateTime(2017, 9, 7, 17, 30), + players: players, + ); }); - testWidgets('French belote - Must find two Team widget', - (WidgetTester tester) async { + testWidgets('French belote - Must find two Team widget', ( + WidgetTester tester, + ) async { await mockNetworkImagesFor( - () => tester.pumpWidget(testableWidget(frenchBelote))); + () => tester.pumpWidget(testableWidget(frenchBelote)), + ); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('expansionTileTitle')))); + () => tester.tap(find.byKey(const ValueKey('expansionTileTitle'))), + ); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect(find.byKey(const ValueKey('teamWidget-US')), findsOneWidget); expect(find.byKey(const ValueKey('teamWidget-THEM')), findsOneWidget); }); - testWidgets('Coinche belote - Must show three buttons : STOP, CONTINUE', - (WidgetTester tester) async { + testWidgets('Coinche belote - Must show three buttons : STOP, CONTINUE', ( + WidgetTester tester, + ) async { await mockNetworkImagesFor( - () => tester.pumpWidget(testableWidget(coincheBelote))); + () => tester.pumpWidget(testableWidget(coincheBelote)), + ); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('expansionTileTitle')))); + () => tester.tap(find.byKey(const ValueKey('expansionTileTitle'))), + ); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect(find.byKey(const ValueKey('stopButton')), findsOneWidget); expect(find.byKey(const ValueKey('continueButton')), findsOneWidget); }); - testWidgets('Contree belote - Must show three buttons : DELETE, SHOW_SCORE', - (WidgetTester tester) async { + testWidgets('Contree belote - Must show three buttons : DELETE, SHOW_SCORE', ( + WidgetTester tester, + ) async { await mockNetworkImagesFor( - () => tester.pumpWidget(testableWidget(contreeBelote))); + () => tester.pumpWidget(testableWidget(contreeBelote)), + ); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('expansionTileTitle')))); + () => tester.tap(find.byKey(const ValueKey('expansionTileTitle'))), + ); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect(find.byKey(const ValueKey('deleteButton')), findsOneWidget); expect(find.byKey(const ValueKey('showScoreButton')), findsOneWidget); }); - testWidgets('French belote - Must find total scores (US: 100 and THEM: 90)', - (WidgetTester tester) async { + testWidgets('French belote - Must find total scores (US: 100 and THEM: 90)', ( + WidgetTester tester, + ) async { await mockNetworkImagesFor( - () => tester.pumpWidget(testableWidget(frenchBelote))); + () => tester.pumpWidget(testableWidget(frenchBelote)), + ); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('expansionTileTitle')))); + () => tester.tap(find.byKey(const ValueKey('expansionTileTitle'))), + ); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect( - tester - .widget(find.byKey(const ValueKey('usTotalPointsText'))) - .data, - '90'); + tester.widget(find.byKey(const ValueKey('usTotalPointsText'))).data, + '90', + ); expect( - tester - .widget(find.byKey(const ValueKey('themTotalPointsText'))) - .data, - '110'); + tester + .widget(find.byKey(const ValueKey('themTotalPointsText'))) + .data, + '110', + ); }); } diff --git a/test/widgets/belote_widget_test.mocks.dart b/test/widgets/belote_widget_test.mocks.dart index dcee6e0a..e184a653 100644 --- a/test/widgets/belote_widget_test.mocks.dart +++ b/test/widgets/belote_widget_test.mocks.dart @@ -52,6 +52,7 @@ import 'belote_widget_test.dart' as _i30; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractBeloteGameRepository_0< T1 extends _i1.Belote<_i2.BelotePlayers, _i3.BeloteGameSetting>> diff --git a/test/widgets/card_color_picker_widget_test.dart b/test/widgets/card_color_picker_widget_test.dart index a7a85504..dc14b071 100644 --- a/test/widgets/card_color_picker_widget_test.dart +++ b/test/widgets/card_color_picker_widget_test.dart @@ -7,12 +7,8 @@ import '../units/mocks/fake_belote_round.dart'; import 'localized_testable_widget.dart'; Widget testableWidget(FakeBeloteRound beloteRound) => localizedTestableWidget( - Scaffold( - body: CardColorPickerWidget( - beloteRound: beloteRound, - ), - ), - ); + Scaffold(body: CardColorPickerWidget(beloteRound: beloteRound)), +); void main() { late FakeBeloteRound beloteRound; @@ -23,7 +19,9 @@ void main() { testWidgets("Display at least 'Coeur'", (WidgetTester tester) async { await tester.pumpWidget(testableWidget(beloteRound)); expect( - find.byKey(const ValueKey('cardColorInputChip-Cœur')), findsOneWidget); + find.byKey(const ValueKey('cardColorInputChip-Cœur')), + findsOneWidget, + ); expect(find.text('Couleur (Cœur)'), findsOneWidget); }); diff --git a/test/widgets/contract_coinche_widget_test.dart b/test/widgets/contract_coinche_widget_test.dart index 4ddd3fe0..355e4309 100644 --- a/test/widgets/contract_coinche_widget_test.dart +++ b/test/widgets/contract_coinche_widget_test.dart @@ -9,11 +9,7 @@ import 'localized_testable_widget.dart'; Widget testableWidget(CoincheBeloteRound coincheRound) => localizedTestableWidget( - Scaffold( - body: ContractCoincheWidget( - coincheRound: coincheRound, - ), - ), + Scaffold(body: ContractCoincheWidget(coincheRound: coincheRound)), ); void main() { @@ -24,8 +20,10 @@ void main() { testWidgets("All sub widget are displayed", (WidgetTester tester) async { await tester.pumpWidget(testableWidget(coincheRound)); - expect(find.byKey(const ValueKey('contractValueTextFieldWidget')), - findsOneWidget); + expect( + find.byKey(const ValueKey('contractValueTextFieldWidget')), + findsOneWidget, + ); expect(find.byKey(const ValueKey('contractTypeWidget')), findsOneWidget); expect(find.byKey(const ValueKey('contractNameWidget')), findsOneWidget); expect(find.byKey(const ValueKey('cardColorPickerWidget')), findsOneWidget); @@ -36,7 +34,8 @@ void main() { await tester.tap(find.byKey(const ValueKey('contractTypeWidget-Capot'))); await tester.pumpAndSettle(); var textField = tester.widget( - find.byKey(const ValueKey('contractValueTextFieldValue'))); + find.byKey(const ValueKey('contractValueTextFieldValue')), + ); expect(textField.enabled, false); expect(textField.controller!.text, "162"); expect(find.byKey(const ValueKey('lockWidget')), findsOneWidget); @@ -48,7 +47,8 @@ void main() { await tester.tap(find.byKey(const ValueKey('contractTypeWidget-Générale'))); await tester.pumpAndSettle(); var textField = tester.widget( - find.byKey(const ValueKey('contractValueTextFieldValue'))); + find.byKey(const ValueKey('contractValueTextFieldValue')), + ); expect(textField.enabled, false); expect(textField.controller!.text, "162"); expect(find.byKey(const ValueKey('lockWidget')), findsOneWidget); @@ -60,7 +60,8 @@ void main() { await tester.tap(find.byKey(const ValueKey('contractTypeWidget-Normal'))); await tester.pumpAndSettle(); var textField = tester.widget( - find.byKey(const ValueKey('contractValueTextFieldValue'))); + find.byKey(const ValueKey('contractValueTextFieldValue')), + ); expect(textField.enabled, true); expect(find.byKey(const ValueKey('noLockWidget')), findsOneWidget); expect(find.byKey(const ValueKey('lockWidget')), findsNothing); diff --git a/test/widgets/contract_contree_widget_test.dart b/test/widgets/contract_contree_widget_test.dart index 56730715..2d236c60 100644 --- a/test/widgets/contract_contree_widget_test.dart +++ b/test/widgets/contract_contree_widget_test.dart @@ -9,11 +9,7 @@ import 'localized_testable_widget.dart'; Widget testableWidget(ContreeBeloteRound contreeRound) => localizedTestableWidget( - Scaffold( - body: ContractContreeWidget( - contreeRound: contreeRound, - ), - ), + Scaffold(body: ContractContreeWidget(contreeRound: contreeRound)), ); void main() { @@ -24,8 +20,10 @@ void main() { testWidgets("All sub widget are displayed", (WidgetTester tester) async { await tester.pumpWidget(testableWidget(contreeRound)); - expect(find.byKey(const ValueKey('contractValueTextFieldWidget')), - findsOneWidget); + expect( + find.byKey(const ValueKey('contractValueTextFieldWidget')), + findsOneWidget, + ); expect(find.byKey(const ValueKey('contractTypeWidget')), findsOneWidget); expect(find.byKey(const ValueKey('contractNameWidget')), findsOneWidget); expect(find.byKey(const ValueKey('cardColorPickerWidget')), findsOneWidget); @@ -36,7 +34,8 @@ void main() { await tester.tap(find.byKey(const ValueKey('contractTypeWidget-Capot'))); await tester.pumpAndSettle(); var textField = tester.widget( - find.byKey(const ValueKey('contractValueTextFieldValue'))); + find.byKey(const ValueKey('contractValueTextFieldValue')), + ); expect(textField.enabled, false); expect(textField.controller!.text, "162"); expect(find.byKey(const ValueKey('lockWidget')), findsOneWidget); @@ -48,7 +47,8 @@ void main() { await tester.tap(find.byKey(const ValueKey('contractTypeWidget-Générale'))); await tester.pumpAndSettle(); var textField = tester.widget( - find.byKey(const ValueKey('contractValueTextFieldValue'))); + find.byKey(const ValueKey('contractValueTextFieldValue')), + ); expect(textField.enabled, false); expect(textField.controller!.text, "162"); expect(find.byKey(const ValueKey('lockWidget')), findsOneWidget); @@ -60,7 +60,8 @@ void main() { await tester.tap(find.byKey(const ValueKey('contractTypeWidget-Normal'))); await tester.pumpAndSettle(); var textField = tester.widget( - find.byKey(const ValueKey('contractValueTextFieldValue'))); + find.byKey(const ValueKey('contractValueTextFieldValue')), + ); expect(textField.enabled, true); expect(find.byKey(const ValueKey('noLockWidget')), findsOneWidget); expect(find.byKey(const ValueKey('lockWidget')), findsNothing); diff --git a/test/widgets/game_info_dialog_test.dart b/test/widgets/game_info_dialog_test.dart index 6a2710c1..9eacb5f2 100644 --- a/test/widgets/game_info_dialog_test.dart +++ b/test/widgets/game_info_dialog_test.dart @@ -8,13 +8,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'localized_testable_widget.dart'; -Widget testableWidget(Game game) => localizedTestableWidget( - Scaffold( - body: GameInfoDialog( - game: game, - ), - ), - ); +Widget testableWidget(Game game) => + localizedTestableWidget(Scaffold(body: GameInfoDialog(game: game))); void main() { late Game game; @@ -36,22 +31,29 @@ void main() { group('GameInfoDialog', () { testWidgets('display coinche setting', (WidgetTester tester) async { await tester.pumpWidget(testableWidget(game)); - expect(find.byKey(const ValueKey('addAnnouncementAndPointOption')), - findsOneWidget); + expect( + find.byKey(const ValueKey('addAnnouncementAndPointOption')), + findsOneWidget, + ); expect(find.byKey(const ValueKey('maxPointOption')), findsOneWidget); }); - testWidgets('display coinche setting (infinite)', - (WidgetTester tester) async { + testWidgets('display coinche setting (infinite)', ( + WidgetTester tester, + ) async { await tester.pumpWidget(testableWidget(game3)); - expect(find.byKey(const ValueKey('addAnnouncementAndPointOption')), - findsOneWidget); + expect( + find.byKey(const ValueKey('addAnnouncementAndPointOption')), + findsOneWidget, + ); expect(find.byKey(const ValueKey('maxPointOption')), findsNothing); expect(find.byKey(const ValueKey('infiniteIcon')), findsOneWidget); }); testWidgets('display french belote setting', (WidgetTester tester) async { await tester.pumpWidget(testableWidget(game2)); - expect(find.byKey(const ValueKey('addAnnouncementAndPointOption')), - findsNothing); + expect( + find.byKey(const ValueKey('addAnnouncementAndPointOption')), + findsNothing, + ); expect(find.byKey(const ValueKey('maxPointOption')), findsOneWidget); }); }); diff --git a/test/widgets/game_title_widget_test.dart b/test/widgets/game_title_widget_test.dart index a9ad1e5b..f9cc4f00 100644 --- a/test/widgets/game_title_widget_test.dart +++ b/test/widgets/game_title_widget_test.dart @@ -9,11 +9,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'localized_testable_widget.dart'; -Widget testableWidget(Game game) => localizedTestableWidget( - GameTitleWidget( - game: game, - ), - ); +Widget testableWidget(Game game) => + localizedTestableWidget(GameTitleWidget(game: game)); void main() { late Tarot tarotGame; @@ -22,45 +19,63 @@ void main() { late ContreeBelote contreeBelote; setUp(() { tarotGame = Tarot( - id: 'ID1', isEnded: false, startingDate: DateTime(2017, 9, 7, 17, 30)); + id: 'ID1', + isEnded: false, + startingDate: DateTime(2017, 9, 7, 17, 30), + ); frenchBelote = FrenchBelote( - id: 'ID2', isEnded: true, startingDate: DateTime(2020, 9, 7, 17, 30)); + id: 'ID2', + isEnded: true, + startingDate: DateTime(2020, 9, 7, 17, 30), + ); coincheBelote = CoincheBelote( - id: 'ID3', isEnded: false, startingDate: DateTime(2017, 9, 7, 17, 30)); + id: 'ID3', + isEnded: false, + startingDate: DateTime(2017, 9, 7, 17, 30), + ); contreeBelote = ContreeBelote( - id: 'ID4', isEnded: true, startingDate: DateTime(2017, 9, 7, 17, 30)); + id: 'ID4', + isEnded: true, + startingDate: DateTime(2017, 9, 7, 17, 30), + ); }); - testWidgets("Tarot - must display 'En cours' and '07/09/2017, 17:30'", - (WidgetTester tester) async { + testWidgets("Tarot - must display 'En cours' and '07/09/2017, 17:30'", ( + WidgetTester tester, + ) async { await tester.pumpWidget(testableWidget(tarotGame)); expect(find.text('En cours'), findsOneWidget); expect(find.text('7 septembre 2017'), findsOneWidget); }); - testWidgets("French belote - must display 'Terminée' and '07/09/2020, 17:30'", - (WidgetTester tester) async { - await tester.pumpWidget(testableWidget(frenchBelote)); + testWidgets( + "French belote - must display 'Terminée' and '07/09/2020, 17:30'", + (WidgetTester tester) async { + await tester.pumpWidget(testableWidget(frenchBelote)); - expect(find.text('Terminée'), findsOneWidget); - expect(find.text('7 septembre 2020'), findsOneWidget); - }); + expect(find.text('Terminée'), findsOneWidget); + expect(find.text('7 septembre 2020'), findsOneWidget); + }, + ); testWidgets( - "Coinche belote - must display 'En cours' and '07/09/2017, 17:30'", - (WidgetTester tester) async { - await tester.pumpWidget(testableWidget(coincheBelote)); + "Coinche belote - must display 'En cours' and '07/09/2017, 17:30'", + (WidgetTester tester) async { + await tester.pumpWidget(testableWidget(coincheBelote)); - expect(find.text('En cours'), findsOneWidget); - expect(find.text('7 septembre 2017'), findsOneWidget); - }); + expect(find.text('En cours'), findsOneWidget); + expect(find.text('7 septembre 2017'), findsOneWidget); + }, + ); - testWidgets("Contre belote - must display 'Terminée' and '07/09/2017, 17:30'", - (WidgetTester tester) async { - await tester.pumpWidget(testableWidget(contreeBelote)); + testWidgets( + "Contre belote - must display 'Terminée' and '07/09/2017, 17:30'", + (WidgetTester tester) async { + await tester.pumpWidget(testableWidget(contreeBelote)); - expect(find.text('Terminée'), findsOneWidget); - expect(find.text('7 septembre 2017'), findsOneWidget); - }); + expect(find.text('Terminée'), findsOneWidget); + expect(find.text('7 septembre 2017'), findsOneWidget); + }, + ); } diff --git a/test/widgets/localized_testable_widget.dart b/test/widgets/localized_testable_widget.dart index 3208e27d..cc5603d1 100644 --- a/test/widgets/localized_testable_widget.dart +++ b/test/widgets/localized_testable_widget.dart @@ -1,16 +1,14 @@ -import 'package:flutter/material.dart'; import 'package:carg/l10n/app_localizations.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; Widget localizedTestableWidget(Widget child) => MaterialApp( - localizationsDelegates: const [ - AppLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: const [ - Locale('fr', ''), - ], - home: child, - ); + localizationsDelegates: const [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: const [Locale('fr', '')], + home: child, +); diff --git a/test/widgets/player_color_explanation_dialog_test.dart b/test/widgets/player_color_explanation_dialog_test.dart index abf4e9e4..fcd3c5a0 100644 --- a/test/widgets/player_color_explanation_dialog_test.dart +++ b/test/widgets/player_color_explanation_dialog_test.dart @@ -8,47 +8,66 @@ import 'package:network_image_mock/network_image_mock.dart'; import 'localized_testable_widget.dart'; -Widget testableWidget(bool isAdmin) => localizedTestableWidget( - PlayerColorExplanationDialog( - isAdmin: isAdmin, - ), - ); +Widget testableWidget(bool isAdmin) => + localizedTestableWidget(PlayerColorExplanationDialog(isAdmin: isAdmin)); @GenerateMocks([PlayerService, AuthService]) void main() { testWidgets('Display the 3 widgets', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget(true))); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect( - find.byKey(const ValueKey('playerWidgetRealPlayer')), findsOneWidget); + find.byKey(const ValueKey('playerWidgetRealPlayer')), + findsOneWidget, + ); expect(find.byKey(const ValueKey('realPlayerDescription')), findsOneWidget); expect( - find.byKey(const ValueKey('playerWidgetOwnedPlayer')), findsOneWidget); + find.byKey(const ValueKey('playerWidgetOwnedPlayer')), + findsOneWidget, + ); expect( - find.byKey(const ValueKey('ownedPlayerDescription')), findsOneWidget); - expect(find.byKey(const ValueKey('playerWidgetTestingPlayer')), - findsOneWidget); + find.byKey(const ValueKey('ownedPlayerDescription')), + findsOneWidget, + ); + expect( + find.byKey(const ValueKey('playerWidgetTestingPlayer')), + findsOneWidget, + ); expect( - find.byKey(const ValueKey('testingPlayerDescription')), findsOneWidget); + find.byKey(const ValueKey('testingPlayerDescription')), + findsOneWidget, + ); expect(find.byKey(const ValueKey('wonGamesDescription')), findsOneWidget); expect( - find.byKey(const ValueKey('playedGamesDescription')), findsOneWidget); + find.byKey(const ValueKey('playedGamesDescription')), + findsOneWidget, + ); }); testWidgets('Display only 2 widgets', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget(true))); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect( - find.byKey(const ValueKey('playerWidgetRealPlayer')), findsOneWidget); + find.byKey(const ValueKey('playerWidgetRealPlayer')), + findsOneWidget, + ); expect(find.byKey(const ValueKey('realPlayerDescription')), findsOneWidget); expect( - find.byKey(const ValueKey('playerWidgetOwnedPlayer')), findsOneWidget); + find.byKey(const ValueKey('playerWidgetOwnedPlayer')), + findsOneWidget, + ); expect( - find.byKey(const ValueKey('ownedPlayerDescription')), findsOneWidget); + find.byKey(const ValueKey('ownedPlayerDescription')), + findsOneWidget, + ); expect(find.byKey(const ValueKey('wonGamesDescription')), findsOneWidget); expect( - find.byKey(const ValueKey('playedGamesDescription')), findsOneWidget); + find.byKey(const ValueKey('playedGamesDescription')), + findsOneWidget, + ); }); } diff --git a/test/widgets/player_color_explanation_dialog_test.mocks.dart b/test/widgets/player_color_explanation_dialog_test.mocks.dart index 65f3a26f..2ba0cba2 100644 --- a/test/widgets/player_color_explanation_dialog_test.mocks.dart +++ b/test/widgets/player_color_explanation_dialog_test.mocks.dart @@ -33,6 +33,7 @@ import 'package:mockito/src/dummies.dart' as _i9; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractPlayerRepository_0 extends _i1.SmartFake implements _i2.AbstractPlayerRepository { diff --git a/test/widgets/player_info_dialog_test.dart b/test/widgets/player_info_dialog_test.dart index 49fa670c..057df799 100644 --- a/test/widgets/player_info_dialog_test.dart +++ b/test/widgets/player_info_dialog_test.dart @@ -14,18 +14,21 @@ import 'package:provider/provider.dart'; import 'localized_testable_widget.dart'; import 'player_info_dialog_test.mocks.dart'; -Widget testableWidget(bool mockIsNewPlayer, PlayerService playerService, - Player mockPlayer, AuthService mockAuthService) => - localizedTestableWidget( - ChangeNotifierProvider.value( - value: mockAuthService, - builder: (context, _) => PlayerInfoDialog( - player: mockPlayer, - playerService: playerService, - isNewPlayer: mockIsNewPlayer, - ), - ), - ); +Widget testableWidget( + bool mockIsNewPlayer, + PlayerService playerService, + Player mockPlayer, + AuthService mockAuthService, +) => localizedTestableWidget( + ChangeNotifierProvider.value( + value: mockAuthService, + builder: (context, _) => PlayerInfoDialog( + player: mockPlayer, + playerService: playerService, + isNewPlayer: mockIsNewPlayer, + ), + ), +); @GenerateMocks([PlayerService, AuthService]) void main() { @@ -42,130 +45,241 @@ void main() { group('PlayerInfoDialog', () { group('Title', () { testWidgets('EDITING', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - false, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + false, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect( - tester.widget(find.byKey(const ValueKey('titleText'))).data, - 'Édition'); + tester.widget(find.byKey(const ValueKey('titleText'))).data, + 'Édition', + ); }); testWidgets('CREATING', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect( - tester.widget(find.byKey(const ValueKey('titleText'))).data, - 'Nouveau.elle joueur.euse'); + tester.widget(find.byKey(const ValueKey('titleText'))).data, + 'Nouveau.elle joueur.euse', + ); }); testWidgets('INFORMATIONS', (WidgetTester tester) async { var mockPlayer = Player(owned: false, userName: 'toto'); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - false, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + false, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect( - tester.widget(find.byKey(const ValueKey('titleText'))).data, - 'Informations'); + tester.widget(find.byKey(const ValueKey('titleText'))).data, + 'Informations', + ); }); }); group('Copy ID button', () { testWidgets('is displayed (editing)', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - false, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + false, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('copyIDButton')), findsOneWidget); }); testWidgets('is hidden (creating)', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('copyIDButton')), findsNothing); }); testWidgets('is hidden (information)', (WidgetTester tester) async { var mockPlayer = Player(owned: false, userName: 'toto'); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('copyIDButton')), findsNothing); }); testWidgets('click on it', (WidgetTester tester) async { var mockPlayer = Player(owned: true, userName: 'toto', id: 'test'); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - false, mockPlayerService, mockPlayer, mockAuthService))); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('copyIDButton')))); + () => tester.pumpWidget( + testableWidget( + false, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); + await mockNetworkImagesFor( + () => tester.tap(find.byKey(const ValueKey('copyIDButton'))), + ); await mockNetworkImagesFor(() => tester.pump()); }); }); group('Username TextField', () { testWidgets('is enabled (editing)', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - false, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + false, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect( - tester - .widget( - find.byKey(const ValueKey('usernameTextField'))) - .enabled, - true); + tester + .widget( + find.byKey(const ValueKey('usernameTextField')), + ) + .enabled, + true, + ); }); testWidgets('is enabled (creating)', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect( - tester - .widget( - find.byKey(const ValueKey('usernameTextField'))) - .enabled, - true); + tester + .widget( + find.byKey(const ValueKey('usernameTextField')), + ) + .enabled, + true, + ); }); testWidgets('is disabled (information)', (WidgetTester tester) async { var mockPlayer = Player(owned: false, userName: 'toto'); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect( - tester - .widget( - find.byKey(const ValueKey('usernameTextField'))) - .enabled, - false); + tester + .widget( + find.byKey(const ValueKey('usernameTextField')), + ) + .enabled, + false, + ); }); }); testWidgets('Display the username', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - false, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget(false, mockPlayerService, mockPlayer, mockAuthService), + ), + ); expect( - tester - .widget( - find.byKey(const ValueKey('usernameTextField'))) - .initialValue, - 'toto'); + tester + .widget( + find.byKey(const ValueKey('usernameTextField')), + ) + .initialValue, + 'toto', + ); }); group('Buttons', () { testWidgets('save (editing)', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - false, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + false, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('saveButton')), findsOneWidget); expect(find.byKey(const ValueKey('closeButton')), findsNothing); }); testWidgets('save (creation)', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('saveButton')), findsOneWidget); expect(find.byKey(const ValueKey('closeButton')), findsNothing); @@ -173,8 +287,16 @@ void main() { testWidgets('close (informations)', (WidgetTester tester) async { var mockPlayer = Player(owned: false, userName: 'toto'); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('saveButton')), findsNothing); expect(find.byKey(const ValueKey('closeButton')), findsOneWidget); @@ -183,11 +305,21 @@ void main() { group('Profile picture text field', () { testWidgets('display', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); - expect(find.byKey(const ValueKey('profilePictureTextField')), - findsOneWidget); + expect( + find.byKey(const ValueKey('profilePictureTextField')), + findsOneWidget, + ); }); }); @@ -195,11 +327,19 @@ void main() { testWidgets('display', (WidgetTester tester) async { var gameStats = [ GameStats(gameType: GameType.CONTREE, wonGames: 0, playedGames: 1), - GameStats(gameType: GameType.COINCHE, wonGames: 0, playedGames: 10) + GameStats(gameType: GameType.COINCHE, wonGames: 0, playedGames: 10), ]; var mockPlayer = Player(owned: false, gameStatsList: gameStats); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('stat-0-Contrée')), findsOneWidget); expect(find.byKey(const ValueKey('stat-1-Coinche')), findsOneWidget); @@ -207,16 +347,32 @@ void main() { testWidgets('no display (no stats)', (WidgetTester tester) async { var mockPlayer = Player(owned: false); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('noStatsText')), findsNothing); }); testWidgets('no display (new player)', (WidgetTester tester) async { var mockPlayer = Player(owned: false); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); expect(find.byKey(const ValueKey('noStatsText')), findsNothing); }); @@ -225,10 +381,19 @@ void main() { group('Save player', () { testWidgets('tap (edit)', (WidgetTester tester) async { var mockPlayer = Player(owned: true, userName: 'toto', id: 'test'); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - false, mockPlayerService, mockPlayer, mockAuthService))); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('saveButton')))); + () => tester.pumpWidget( + testableWidget( + false, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); + await mockNetworkImagesFor( + () => tester.tap(find.byKey(const ValueKey('saveButton'))), + ); await mockNetworkImagesFor(() => tester.pump()); verify(mockPlayerService.update(mockPlayer)).called(1); }); @@ -236,14 +401,28 @@ void main() { testWidgets('tap (create)', (WidgetTester tester) async { var mockPlayer = Player(owned: true, userName: 'toto', id: 'test'); var editedMockPlayer = Player( - owned: true, userName: 'toto', id: 'test', ownedBy: 'user_toto'); + owned: true, + userName: 'toto', + id: 'test', + ownedBy: 'user_toto', + ); when(mockAuthService.getPlayerIdOfUser()).thenReturn('user_toto'); - when(mockPlayerService.create(mockPlayer)) - .thenAnswer((_) async => Future(() => 'playerId')); - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - true, mockPlayerService, mockPlayer, mockAuthService))); + when( + mockPlayerService.create(mockPlayer), + ).thenAnswer((_) async => Future(() => 'playerId')); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + true, + mockPlayerService, + mockPlayer, + mockAuthService, + ), + ), + ); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('saveButton')))); + () => tester.tap(find.byKey(const ValueKey('saveButton'))), + ); await mockNetworkImagesFor(() => tester.pumpAndSettle()); expect(mockPlayer.ownedBy, 'user_toto'); diff --git a/test/widgets/player_info_dialog_test.mocks.dart b/test/widgets/player_info_dialog_test.mocks.dart index 289ae0ab..3f513812 100644 --- a/test/widgets/player_info_dialog_test.mocks.dart +++ b/test/widgets/player_info_dialog_test.mocks.dart @@ -33,6 +33,7 @@ import 'package:mockito/src/dummies.dart' as _i9; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractPlayerRepository_0 extends _i1.SmartFake implements _i2.AbstractPlayerRepository { diff --git a/test/widgets/player_list_screen_test.dart b/test/widgets/player_list_screen_test.dart index 36109717..2b38f0e1 100644 --- a/test/widgets/player_list_screen_test.dart +++ b/test/widgets/player_list_screen_test.dart @@ -1,3 +1,4 @@ +import 'package:carg/l10n/app_localizations.dart'; import 'package:carg/models/player.dart'; import 'package:carg/models/team.dart'; import 'package:carg/services/auth/auth_service.dart'; @@ -11,25 +12,25 @@ import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:network_image_mock/network_image_mock.dart'; import 'package:provider/provider.dart'; -import 'package:carg/l10n/app_localizations.dart'; import 'player_list_screen_test.mocks.dart'; Widget testableWidget() => MaterialApp( - localizationsDelegates: const [ - AppLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: const [ - Locale('en', ''), - ], - home: ChangeNotifierProvider.value( - value: mockAuthService, - builder: (context, _) => PlayerListScreen( - teamService: mockAbstractTeamService, - playerService: mockAbstractPlayerService))); + localizationsDelegates: const [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: const [Locale('en', '')], + home: ChangeNotifierProvider.value( + value: mockAuthService, + builder: (context, _) => PlayerListScreen( + teamService: mockAbstractTeamService, + playerService: mockAbstractPlayerService, + ), + ), +); final mockAbstractPlayerService = MockAbstractPlayerService(); final mockAbstractTeamService = MockAbstractTeamService(); @@ -39,7 +40,7 @@ final mockAuthService = MockAuthService(); AbstractPlayerService, AbstractTeamService, TextEditingController, - AuthService + AuthService, ]) void main() { late List mockPlayerList; @@ -54,27 +55,36 @@ void main() { ]; mockTeamList = [ Team(id: 't1', players: ['p1', 'p2']), - Team(id: 't2', players: ['p3', 'p4']) + Team(id: 't2', players: ['p3', 'p4']), ]; currentPlayer = Player(id: 'player-id', userName: 'Player', owned: false); - when(mockAbstractPlayerService.searchPlayers( - query: '', currentPlayer: currentPlayer, myPlayers: false)) - .thenAnswer((_) => Future>(() => (mockPlayerList))); - when(mockAbstractTeamService.getAllTeamOfPlayer('player-id', 10)) - .thenAnswer((_) => Future>(() => (mockTeamList))); + when( + mockAbstractPlayerService.searchPlayers( + query: '', + currentPlayer: currentPlayer, + myPlayers: false, + ), + ).thenAnswer((_) => Future>(() => (mockPlayerList))); + when( + mockAbstractTeamService.getAllTeamOfPlayer('player-id', 10), + ).thenAnswer((_) => Future>(() => (mockTeamList))); when(mockAuthService.getPlayerIdOfUser()).thenReturn('player-id'); when(mockAuthService.getPlayer()).thenReturn(currentPlayer); when(mockAuthService.getAdmin()).thenReturn(false); when(mockAuthService.isAdFreeUser()).thenAnswer((_) => Future(() => true)); - when(mockAbstractPlayerService.get('p1')) - .thenAnswer((_) => Future(() => (mockPlayerList[0]))); - when(mockAbstractPlayerService.get('p2')) - .thenAnswer((_) => Future(() => (mockPlayerList[0]))); - when(mockAbstractPlayerService.get('p3')) - .thenAnswer((_) => Future(() => (mockPlayerList[0]))); - when(mockAbstractPlayerService.get('p4')) - .thenAnswer((_) => Future(() => (mockPlayerList[0]))); + when( + mockAbstractPlayerService.get('p1'), + ).thenAnswer((_) => Future(() => (mockPlayerList[0]))); + when( + mockAbstractPlayerService.get('p2'), + ).thenAnswer((_) => Future(() => (mockPlayerList[0]))); + when( + mockAbstractPlayerService.get('p3'), + ).thenAnswer((_) => Future(() => (mockPlayerList[0]))); + when( + mockAbstractPlayerService.get('p4'), + ).thenAnswer((_) => Future(() => (mockPlayerList[0]))); }); group('PlayerListScreen ', () { @@ -82,7 +92,8 @@ void main() { testWidgets('display 2 teams', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget())); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('playerListTeam')))); + () => tester.tap(find.byKey(const ValueKey('playerListTeam'))), + ); await mockNetworkImagesFor(() => tester.pumpAndSettle()); }); }); @@ -97,9 +108,13 @@ void main() { }); testWidgets('no players', (WidgetTester tester) async { - when(mockAbstractPlayerService.searchPlayers( - query: '', currentPlayer: currentPlayer, myPlayers: false)) - .thenAnswer((_) => Future>(() => [])); + when( + mockAbstractPlayerService.searchPlayers( + query: '', + currentPlayer: currentPlayer, + myPlayers: false, + ), + ).thenAnswer((_) => Future>(() => [])); await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget())); await mockNetworkImagesFor(() => tester.pumpAndSettle()); expect(find.byKey(const ValueKey('noPlayersMessage')), findsOneWidget); @@ -108,7 +123,8 @@ void main() { testWidgets('reset search', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget())); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('resetSearchButton')))); + () => tester.tap(find.byKey(const ValueKey('resetSearchButton'))), + ); await mockNetworkImagesFor(() => tester.pumpAndSettle()); }); }); @@ -116,40 +132,65 @@ void main() { group('display popups', () { testWidgets('popup menu items', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget())); - await mockNetworkImagesFor(() => tester - .tap(find.byKey(const ValueKey('playerListPopupMenuButton')))); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); - expect(find.byKey(const ValueKey('addPlayerPopupMenuItem')), - findsOneWidget); - expect(find.byKey(const ValueKey('showInformationPopupMenuItem')), - findsOneWidget); + () => tester.tap( + find.byKey(const ValueKey('playerListPopupMenuButton')), + ), + ); + await mockNetworkImagesFor( + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); + expect( + find.byKey(const ValueKey('addPlayerPopupMenuItem')), + findsOneWidget, + ); + expect( + find.byKey(const ValueKey('showInformationPopupMenuItem')), + findsOneWidget, + ); }); testWidgets('information dialog', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget())); - await mockNetworkImagesFor(() => tester - .tap(find.byKey(const ValueKey('playerListPopupMenuButton')))); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); - await mockNetworkImagesFor(() => tester - .tap(find.byKey(const ValueKey('showInformationPopupMenuItem')))); + () => tester.tap( + find.byKey(const ValueKey('playerListPopupMenuButton')), + ), + ); + await mockNetworkImagesFor( + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); - expect(find.byKey(const ValueKey('playerColorExplanationDialog')), - findsOneWidget); + () => tester.tap( + find.byKey(const ValueKey('showInformationPopupMenuItem')), + ), + ); + await mockNetworkImagesFor( + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); + expect( + find.byKey(const ValueKey('playerColorExplanationDialog')), + findsOneWidget, + ); }); testWidgets('add player dialog', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget())); - await mockNetworkImagesFor(() => tester - .tap(find.byKey(const ValueKey('playerListPopupMenuButton')))); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); - await mockNetworkImagesFor(() => - tester.tap(find.byKey(const ValueKey('addPlayerPopupMenuItem')))); + () => tester.tap( + find.byKey(const ValueKey('playerListPopupMenuButton')), + ), + ); + await mockNetworkImagesFor( + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); + await mockNetworkImagesFor( + () => + tester.tap(find.byKey(const ValueKey('addPlayerPopupMenuItem'))), + ); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect(find.byKey(const ValueKey('addPlayerDialog')), findsOneWidget); }); }); diff --git a/test/widgets/player_list_screen_test.mocks.dart b/test/widgets/player_list_screen_test.mocks.dart index c067827b..f03b0469 100644 --- a/test/widgets/player_list_screen_test.mocks.dart +++ b/test/widgets/player_list_screen_test.mocks.dart @@ -36,6 +36,7 @@ import 'package:mockito/src/dummies.dart' as _i14; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractPlayerRepository_0 extends _i1.SmartFake implements _i2.AbstractPlayerRepository { diff --git a/test/widgets/register_screen_test.mocks.dart b/test/widgets/register_screen_test.mocks.dart index 5d64f9c4..f135016d 100644 --- a/test/widgets/register_screen_test.mocks.dart +++ b/test/widgets/register_screen_test.mocks.dart @@ -31,44 +31,24 @@ import 'package:mockito/src/dummies.dart' as _i9; // ignore_for_file: subtype_of_sealed_class class _FakeFirebaseApp_0 extends _i1.SmartFake implements _i2.FirebaseApp { - _FakeFirebaseApp_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeFirebaseApp_0(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeUri_1 extends _i1.SmartFake implements Uri { - _FakeUri_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeUri_1(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeShortDynamicLink_2 extends _i1.SmartFake implements _i3.ShortDynamicLink { - _FakeShortDynamicLink_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeShortDynamicLink_2(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); } class _FakeWidget_3 extends _i1.SmartFake implements _i4.Widget { - _FakeWidget_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); + _FakeWidget_3(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); @override String toString({_i5.DiagnosticLevel? minLevel = _i5.DiagnosticLevel.info}) => @@ -85,70 +65,60 @@ class MockFirebaseDynamicLinks extends _i1.Mock } @override - _i2.FirebaseApp get app => (super.noSuchMethod( - Invocation.getter(#app), - returnValue: _FakeFirebaseApp_0( - this, - Invocation.getter(#app), - ), - ) as _i2.FirebaseApp); + _i2.FirebaseApp get app => + (super.noSuchMethod( + Invocation.getter(#app), + returnValue: _FakeFirebaseApp_0(this, Invocation.getter(#app)), + ) + as _i2.FirebaseApp); @override set app(_i2.FirebaseApp? _app) => super.noSuchMethod( - Invocation.setter( - #app, - _app, - ), - returnValueForMissingStub: null, - ); + Invocation.setter(#app, _app), + returnValueForMissingStub: null, + ); @override - _i7.Stream<_i3.PendingDynamicLinkData> get onLink => (super.noSuchMethod( - Invocation.getter(#onLink), - returnValue: _i7.Stream<_i3.PendingDynamicLinkData>.empty(), - ) as _i7.Stream<_i3.PendingDynamicLinkData>); + _i7.Stream<_i3.PendingDynamicLinkData> get onLink => + (super.noSuchMethod( + Invocation.getter(#onLink), + returnValue: _i7.Stream<_i3.PendingDynamicLinkData>.empty(), + ) + as _i7.Stream<_i3.PendingDynamicLinkData>); @override - Map get pluginConstants => (super.noSuchMethod( - Invocation.getter(#pluginConstants), - returnValue: {}, - ) as Map); + Map get pluginConstants => + (super.noSuchMethod( + Invocation.getter(#pluginConstants), + returnValue: {}, + ) + as Map); @override _i7.Future<_i3.PendingDynamicLinkData?> getInitialLink() => (super.noSuchMethod( - Invocation.method( - #getInitialLink, - [], - ), - returnValue: _i7.Future<_i3.PendingDynamicLinkData?>.value(), - ) as _i7.Future<_i3.PendingDynamicLinkData?>); + Invocation.method(#getInitialLink, []), + returnValue: _i7.Future<_i3.PendingDynamicLinkData?>.value(), + ) + as _i7.Future<_i3.PendingDynamicLinkData?>); @override _i7.Future<_i3.PendingDynamicLinkData?> getDynamicLink(Uri? url) => (super.noSuchMethod( - Invocation.method( - #getDynamicLink, - [url], - ), - returnValue: _i7.Future<_i3.PendingDynamicLinkData?>.value(), - ) as _i7.Future<_i3.PendingDynamicLinkData?>); + Invocation.method(#getDynamicLink, [url]), + returnValue: _i7.Future<_i3.PendingDynamicLinkData?>.value(), + ) + as _i7.Future<_i3.PendingDynamicLinkData?>); @override _i7.Future buildLink(_i3.DynamicLinkParameters? parameters) => (super.noSuchMethod( - Invocation.method( - #buildLink, - [parameters], - ), - returnValue: _i7.Future.value(_FakeUri_1( - this, - Invocation.method( - #buildLink, - [parameters], - ), - )), - ) as _i7.Future); + Invocation.method(#buildLink, [parameters]), + returnValue: _i7.Future.value( + _FakeUri_1(this, Invocation.method(#buildLink, [parameters])), + ), + ) + as _i7.Future); @override _i7.Future<_i3.ShortDynamicLink> buildShortLink( @@ -156,21 +126,23 @@ class MockFirebaseDynamicLinks extends _i1.Mock _i3.ShortDynamicLinkType? shortLinkType = _i3.ShortDynamicLinkType.short, }) => (super.noSuchMethod( - Invocation.method( - #buildShortLink, - [parameters], - {#shortLinkType: shortLinkType}, - ), - returnValue: - _i7.Future<_i3.ShortDynamicLink>.value(_FakeShortDynamicLink_2( - this, - Invocation.method( - #buildShortLink, - [parameters], - {#shortLinkType: shortLinkType}, - ), - )), - ) as _i7.Future<_i3.ShortDynamicLink>); + Invocation.method( + #buildShortLink, + [parameters], + {#shortLinkType: shortLinkType}, + ), + returnValue: _i7.Future<_i3.ShortDynamicLink>.value( + _FakeShortDynamicLink_2( + this, + Invocation.method( + #buildShortLink, + [parameters], + {#shortLinkType: shortLinkType}, + ), + ), + ), + ) + as _i7.Future<_i3.ShortDynamicLink>); } /// A class which mocks [PendingDynamicLinkData]. @@ -183,28 +155,28 @@ class MockPendingDynamicLinkData extends _i1.Mock } @override - Uri get link => (super.noSuchMethod( - Invocation.getter(#link), - returnValue: _FakeUri_1( - this, - Invocation.getter(#link), - ), - ) as Uri); + Uri get link => + (super.noSuchMethod( + Invocation.getter(#link), + returnValue: _FakeUri_1(this, Invocation.getter(#link)), + ) + as Uri); @override - Map get utmParameters => (super.noSuchMethod( - Invocation.getter(#utmParameters), - returnValue: {}, - ) as Map); + Map get utmParameters => + (super.noSuchMethod( + Invocation.getter(#utmParameters), + returnValue: {}, + ) + as Map); @override - Map asMap() => (super.noSuchMethod( - Invocation.method( - #asMap, - [], - ), - returnValue: {}, - ) as Map); + Map asMap() => + (super.noSuchMethod( + Invocation.method(#asMap, []), + returnValue: {}, + ) + as Map); } /// A class which mocks [AuthService]. @@ -216,67 +188,46 @@ class MockAuthService extends _i1.Mock implements _i8.AuthService { } @override - bool get isAuth => (super.noSuchMethod( - Invocation.getter(#isAuth), - returnValue: false, - ) as bool); + bool get isAuth => + (super.noSuchMethod(Invocation.getter(#isAuth), returnValue: false) + as bool); @override - bool get hasListeners => (super.noSuchMethod( - Invocation.getter(#hasListeners), - returnValue: false, - ) as bool); + bool get hasListeners => + (super.noSuchMethod(Invocation.getter(#hasListeners), returnValue: false) + as bool); @override - _i7.Future googleLogIn() => (super.noSuchMethod( - Invocation.method( - #googleLogIn, - [], - ), - returnValue: _i7.Future.value(_i9.dummyValue( - this, - Invocation.method( - #googleLogIn, - [], - ), - )), - ) as _i7.Future); + _i7.Future googleLogIn() => + (super.noSuchMethod( + Invocation.method(#googleLogIn, []), + returnValue: _i7.Future.value( + _i9.dummyValue(this, Invocation.method(#googleLogIn, [])), + ), + ) + as _i7.Future); @override _i7.Future sendSignInWithEmailLink(String? email) => (super.noSuchMethod( - Invocation.method( - #sendSignInWithEmailLink, - [email], - ), - returnValue: _i7.Future.value(), - returnValueForMissingStub: _i7.Future.value(), - ) as _i7.Future); + Invocation.method(#sendSignInWithEmailLink, [email]), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) + as _i7.Future); @override - _i7.Future signInWithEmailLink( - String? email, - String? link, - ) => + _i7.Future signInWithEmailLink(String? email, String? link) => (super.noSuchMethod( - Invocation.method( - #signInWithEmailLink, - [ - email, - link, - ], - ), - returnValue: _i7.Future.value(_i9.dummyValue( - this, - Invocation.method( - #signInWithEmailLink, - [ - email, - link, - ], - ), - )), - ) as _i7.Future); + Invocation.method(#signInWithEmailLink, [email, link]), + returnValue: _i7.Future.value( + _i9.dummyValue( + this, + Invocation.method(#signInWithEmailLink, [email, link]), + ), + ), + ) + as _i7.Future); @override _i7.Future validatePhoneNumber( @@ -284,24 +235,18 @@ class MockAuthService extends _i1.Mock implements _i8.AuthService { String? verificationId, ) => (super.noSuchMethod( - Invocation.method( - #validatePhoneNumber, - [ - smsCode, - verificationId, - ], - ), - returnValue: _i7.Future.value(_i9.dummyValue( - this, - Invocation.method( - #validatePhoneNumber, - [ - smsCode, - verificationId, - ], - ), - )), - ) as _i7.Future); + Invocation.method(#validatePhoneNumber, [smsCode, verificationId]), + returnValue: _i7.Future.value( + _i9.dummyValue( + this, + Invocation.method(#validatePhoneNumber, [ + smsCode, + verificationId, + ]), + ), + ), + ) + as _i7.Future); @override _i7.Future changePhoneNumber( @@ -309,15 +254,10 @@ class MockAuthService extends _i1.Mock implements _i8.AuthService { String? verificationId, ) => (super.noSuchMethod( - Invocation.method( - #changePhoneNumber, - [ - smsCode, - verificationId, - ], - ), - returnValue: _i7.Future.value(), - ) as _i7.Future); + Invocation.method(#changePhoneNumber, [smsCode, verificationId]), + returnValue: _i7.Future.value(), + ) + as _i7.Future); @override _i7.Future resendPhoneVerificationCode( @@ -325,15 +265,13 @@ class MockAuthService extends _i1.Mock implements _i8.AuthService { _i4.BuildContext? context, ) => (super.noSuchMethod( - Invocation.method( - #resendPhoneVerificationCode, - [ - phoneNumber, - context, - ], - ), - returnValue: _i7.Future.value(), - ) as _i7.Future); + Invocation.method(#resendPhoneVerificationCode, [ + phoneNumber, + context, + ]), + returnValue: _i7.Future.value(), + ) + as _i7.Future); @override _i7.Future sendPhoneVerificationCode( @@ -342,112 +280,87 @@ class MockAuthService extends _i1.Mock implements _i8.AuthService { _i8.CredentialVerificationType? credentialVerificationType, ) => (super.noSuchMethod( - Invocation.method( - #sendPhoneVerificationCode, - [ - phoneNumber, - context, - credentialVerificationType, - ], - ), - returnValue: _i7.Future.value(), - ) as _i7.Future); + Invocation.method(#sendPhoneVerificationCode, [ + phoneNumber, + context, + credentialVerificationType, + ]), + returnValue: _i7.Future.value(), + ) + as _i7.Future); @override - _i7.Future isAlreadyLogin() => (super.noSuchMethod( - Invocation.method( - #isAlreadyLogin, - [], - ), - returnValue: _i7.Future.value(false), - ) as _i7.Future); + _i7.Future isAlreadyLogin() => + (super.noSuchMethod( + Invocation.method(#isAlreadyLogin, []), + returnValue: _i7.Future.value(false), + ) + as _i7.Future); @override - _i7.Future signOut(_i4.BuildContext? context) => (super.noSuchMethod( - Invocation.method( - #signOut, - [context], - ), - returnValue: _i7.Future.value(), - returnValueForMissingStub: _i7.Future.value(), - ) as _i7.Future); + _i7.Future signOut(_i4.BuildContext? context) => + (super.noSuchMethod( + Invocation.method(#signOut, [context]), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) + as _i7.Future); @override - _i7.Future changeEmail(String? newEmail) => (super.noSuchMethod( - Invocation.method( - #changeEmail, - [newEmail], - ), - returnValue: _i7.Future.value(), - returnValueForMissingStub: _i7.Future.value(), - ) as _i7.Future); + _i7.Future changeEmail(String? newEmail) => + (super.noSuchMethod( + Invocation.method(#changeEmail, [newEmail]), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) + as _i7.Future); @override - _i4.Widget getCorrectLandingScreen() => (super.noSuchMethod( - Invocation.method( - #getCorrectLandingScreen, - [], - ), - returnValue: _FakeWidget_3( - this, - Invocation.method( - #getCorrectLandingScreen, - [], - ), - ), - ) as _i4.Widget); + _i4.Widget getCorrectLandingScreen() => + (super.noSuchMethod( + Invocation.method(#getCorrectLandingScreen, []), + returnValue: _FakeWidget_3( + this, + Invocation.method(#getCorrectLandingScreen, []), + ), + ) + as _i4.Widget); @override void setCurrentPlayer(_i10.Player? player) => super.noSuchMethod( - Invocation.method( - #setCurrentPlayer, - [player], - ), - returnValueForMissingStub: null, - ); + Invocation.method(#setCurrentPlayer, [player]), + returnValueForMissingStub: null, + ); @override - _i7.Future isAdFreeUser() => (super.noSuchMethod( - Invocation.method( - #isAdFreeUser, - [], - ), - returnValue: _i7.Future.value(false), - ) as _i7.Future); + _i7.Future isAdFreeUser() => + (super.noSuchMethod( + Invocation.method(#isAdFreeUser, []), + returnValue: _i7.Future.value(false), + ) + as _i7.Future); @override void addListener(_i11.VoidCallback? listener) => super.noSuchMethod( - Invocation.method( - #addListener, - [listener], - ), - returnValueForMissingStub: null, - ); + Invocation.method(#addListener, [listener]), + returnValueForMissingStub: null, + ); @override void removeListener(_i11.VoidCallback? listener) => super.noSuchMethod( - Invocation.method( - #removeListener, - [listener], - ), - returnValueForMissingStub: null, - ); + Invocation.method(#removeListener, [listener]), + returnValueForMissingStub: null, + ); @override void dispose() => super.noSuchMethod( - Invocation.method( - #dispose, - [], - ), - returnValueForMissingStub: null, - ); + Invocation.method(#dispose, []), + returnValueForMissingStub: null, + ); @override void notifyListeners() => super.noSuchMethod( - Invocation.method( - #notifyListeners, - [], - ), - returnValueForMissingStub: null, - ); + Invocation.method(#notifyListeners, []), + returnValueForMissingStub: null, + ); } diff --git a/test/widgets/settings_screen_test.dart b/test/widgets/settings_screen_test.dart index 0a657dce..df557586 100644 --- a/test/widgets/settings_screen_test.dart +++ b/test/widgets/settings_screen_test.dart @@ -15,21 +15,19 @@ import 'localized_testable_widget.dart'; import 'settings_screen_test.mocks.dart'; Widget testableWidget( - AuthService mockAuthService, - ThemeService mockThemeService, - PlayerService playerService, - Player mockPlayer) => - localizedTestableWidget( - MultiProvider( - providers: [ - ChangeNotifierProvider.value(value: mockAuthService), - ChangeNotifierProvider.value(value: mockThemeService) - ], - child: SettingsScreen( - player: mockPlayer, - playerService: playerService, - )), - ); + AuthService mockAuthService, + ThemeService mockThemeService, + PlayerService playerService, + Player mockPlayer, +) => localizedTestableWidget( + MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: mockAuthService), + ChangeNotifierProvider.value(value: mockThemeService), + ], + child: SettingsScreen(player: mockPlayer, playerService: playerService), + ), +); @GenerateMocks([PlayerService, AuthService, ThemeService]) void main() { @@ -51,90 +49,170 @@ void main() { when(themeService.showContrastPicker()).thenReturn(true); when(themeService.currentThemeValue).thenReturn(ThemeValue.light); when(themeService.currentContrastValue).thenReturn(ContrastValue.high); + when(themeService.useDynamicColors).thenReturn(false); }); testWidgets('Display the correct username', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget( - authService, themeService, mockPlayerService, mockPlayer))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + authService, + themeService, + mockPlayerService, + mockPlayer, + ), + ), + ); expect( - tester - .widget( - find.byKey(const ValueKey('usernameTextField'))) - .initialValue, - 'toto'); + tester + .widget( + find.byKey(const ValueKey('usernameTextField')), + ) + .initialValue, + 'toto', + ); }); - testWidgets('Display the correct profile picture URL', - (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget( - testableWidget(authService, themeService, mockPlayerService, mockPlayer))); + testWidgets('Display the correct profile picture URL', ( + WidgetTester tester, + ) async { + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + authService, + themeService, + mockPlayerService, + mockPlayer, + ), + ), + ); expect( - tester - .widget( - find.byKey(const ValueKey('imageURLTextField'))) - .initialValue, - Player.defaultProfilePicture); + tester + .widget( + find.byKey(const ValueKey('imageURLTextField')), + ) + .initialValue, + Player.defaultProfilePicture, + ); }); group('URL TextField', () { testWidgets('is enabled', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget( - testableWidget(authService, themeService, mockPlayerService, mockPlayer))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + authService, + themeService, + mockPlayerService, + mockPlayer, + ), + ), + ); expect( - tester - .widget( - find.byKey(const ValueKey('imageURLTextField'))) - .enabled, - true); + tester + .widget( + find.byKey(const ValueKey('imageURLTextField')), + ) + .enabled, + true, + ); }); testWidgets('is disabled', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget( - testableWidget(authService, themeService, mockPlayerService, mockPlayer))); - when(mockPlayerService.update(mockPlayer)) - .thenAnswer((_) async => Future.value()); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + authService, + themeService, + mockPlayerService, + mockPlayer, + ), + ), + ); + when( + mockPlayerService.update(mockPlayer), + ).thenAnswer((_) async => Future.value()); await tester.tap(find.byKey(const ValueKey('gravatarSwitchTile'))); await tester.pump(); expect( - tester - .widget( - find.byKey(const ValueKey('imageURLTextField'))) - .enabled, - false); + tester + .widget( + find.byKey(const ValueKey('imageURLTextField')), + ) + .enabled, + false, + ); }); }); group('Account', () { testWidgets('Must display the phone number', (WidgetTester tester) async { - await mockNetworkImagesFor(() => tester.pumpWidget( - testableWidget(authService, themeService, mockPlayerService, mockPlayer))); - expect(tester.widget(find.byKey(const ValueKey('phoneText'))).data, - telephoneNumber); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + authService, + themeService, + mockPlayerService, + mockPlayer, + ), + ), + ); + expect( + tester.widget(find.byKey(const ValueKey('phoneText'))).data, + telephoneNumber, + ); }); testWidgets('No phone number', (WidgetTester tester) async { when(authService.getConnectedUserPhoneNumber()).thenReturn(null); - await mockNetworkImagesFor(() => tester.pumpWidget( - testableWidget(authService, themeService, mockPlayerService, mockPlayer))); - expect(tester.widget(find.byKey(const ValueKey('phoneText'))).data, - 'Pas de numéro de téléphone renseigné'); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + authService, + themeService, + mockPlayerService, + mockPlayer, + ), + ), + ); + expect( + tester.widget(find.byKey(const ValueKey('phoneText'))).data, + 'Pas de numéro de téléphone renseigné', + ); }); testWidgets('Must display the "Admin" label', (WidgetTester tester) async { when(authService.getConnectedUserPhoneNumber()).thenReturn(null); - await mockNetworkImagesFor(() => tester.pumpWidget( - testableWidget(authService, themeService, mockPlayerService, mockPlayer))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + authService, + themeService, + mockPlayerService, + mockPlayer, + ), + ), + ); expect(find.byKey(const ValueKey('adminLabel')), findsOneWidget); }); - testWidgets('Must not display the "Admin" label', - (WidgetTester tester) async { + testWidgets('Must not display the "Admin" label', ( + WidgetTester tester, + ) async { mockPlayer = Player(owned: false, userName: 'toto', admin: false); when(authService.getConnectedUserPhoneNumber()).thenReturn(null); - await mockNetworkImagesFor(() => tester.pumpWidget( - testableWidget(authService, themeService, mockPlayerService, mockPlayer))); + await mockNetworkImagesFor( + () => tester.pumpWidget( + testableWidget( + authService, + themeService, + mockPlayerService, + mockPlayer, + ), + ), + ); expect(find.byKey(const ValueKey('adminLabel')), findsNothing); }); }); diff --git a/test/widgets/settings_screen_test.mocks.dart b/test/widgets/settings_screen_test.mocks.dart index aa72a15d..6e5d1678 100644 --- a/test/widgets/settings_screen_test.mocks.dart +++ b/test/widgets/settings_screen_test.mocks.dart @@ -37,6 +37,7 @@ import 'package:mockito/src/dummies.dart' as _i11; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractPlayerRepository_0 extends _i1.SmartFake implements _i2.AbstractPlayerRepository { @@ -545,6 +546,12 @@ class MockThemeService extends _i1.Mock implements _i17.ThemeService { returnValue: _i18.ContrastValue.none, ) as _i18.ContrastValue); + @override + bool get useDynamicColors => (super.noSuchMethod( + Invocation.getter(#useDynamicColors), + returnValue: false, + ) as bool); + @override set currentContrastValue(_i18.ContrastValue? value) => super.noSuchMethod( Invocation.setter( @@ -572,6 +579,15 @@ class MockThemeService extends _i1.Mock implements _i17.ThemeService { returnValueForMissingStub: null, ); + @override + set useDynamicColors(bool? value) => super.noSuchMethod( + Invocation.setter( + #useDynamicColors, + value, + ), + returnValueForMissingStub: null, + ); + @override bool get hasListeners => (super.noSuchMethod( Invocation.getter(#hasListeners), diff --git a/test/widgets/taker_team_widget_test.dart b/test/widgets/taker_team_widget_test.dart index e8db6cd5..ad9e0626 100644 --- a/test/widgets/taker_team_widget_test.dart +++ b/test/widgets/taker_team_widget_test.dart @@ -7,12 +7,8 @@ import '../units/mocks/fake_belote_round.dart'; import 'localized_testable_widget.dart'; Widget testableWidget(FakeBeloteRound beloteRound) => localizedTestableWidget( - Scaffold( - body: TakerTeamWidget( - beloteRound: beloteRound, - ), - ), - ); + Scaffold(body: TakerTeamWidget(beloteRound: beloteRound)), +); void main() { late FakeBeloteRound beloteRound; diff --git a/test/widgets/tarot_widget_test.dart b/test/widgets/tarot_widget_test.dart index 33922e76..8db5f518 100644 --- a/test/widgets/tarot_widget_test.dart +++ b/test/widgets/tarot_widget_test.dart @@ -18,13 +18,13 @@ import 'localized_testable_widget.dart'; import 'tarot_widget_test.mocks.dart'; Widget testableWidget(Tarot tarotGame) => localizedTestableWidget( - TarotWidget( - tarotGame: tarotGame, - gameService: mockAbstractGameService, - scoreService: mockAbstractScoreService, - playerService: mockAbstractPlayerService, - ), - ); + TarotWidget( + tarotGame: tarotGame, + gameService: mockAbstractGameService, + scoreService: mockAbstractScoreService, + playerService: mockAbstractPlayerService, + ), +); final mockAbstractGameService = MockAbstractTarotGameService(); final mockAbstractScoreService = MockAbstractTarotScoreService(); @@ -33,7 +33,7 @@ final mockAbstractPlayerService = MockAbstractPlayerService(); @GenerateMocks([ AbstractTarotGameService, AbstractTarotScoreService, - AbstractPlayerService + AbstractPlayerService, ]) void main() { late Tarot tarotGame; @@ -52,40 +52,53 @@ void main() { gameType: GameType.TAROT, ); - tarotScore = TarotScore(players: [ - 'p1', - 'p2', - 'p3' - ], totalPoints: [ - TarotPlayerScore(score: 0, player: 'p1'), - TarotPlayerScore(score: 100, player: 'p2'), - TarotPlayerScore(score: 150, player: 'p3') - ]); + tarotScore = TarotScore( + players: ['p1', 'p2', 'p3'], + totalPoints: [ + TarotPlayerScore(score: 0, player: 'p1'), + TarotPlayerScore(score: 100, player: 'p2'), + TarotPlayerScore(score: 150, player: 'p3'), + ], + ); - when(mockAbstractScoreService.getScoreByGame('ID')) - .thenAnswer((_) => Future(() => tarotScore)); - when(mockAbstractPlayerService.get('p1')) - .thenAnswer((_) => Future(() => player1)); - when(mockAbstractPlayerService.get('p2')) - .thenAnswer((_) => Future(() => player2)); - when(mockAbstractPlayerService.get('p3')) - .thenAnswer((_) => Future(() => player3)); + when( + mockAbstractScoreService.getScoreByGame('ID'), + ).thenAnswer((_) => Future(() => tarotScore)); + when( + mockAbstractPlayerService.get('p1'), + ).thenAnswer((_) => Future(() => player1)); + when( + mockAbstractPlayerService.get('p2'), + ).thenAnswer((_) => Future(() => player2)); + when( + mockAbstractPlayerService.get('p3'), + ).thenAnswer((_) => Future(() => player3)); }); - testWidgets('Players - must display 3 players widget when tapped', - (WidgetTester tester) async { + testWidgets('Players - must display 3 players widget when tapped', ( + WidgetTester tester, + ) async { await mockNetworkImagesFor( - () => tester.pumpWidget(testableWidget(tarotGame))); + () => tester.pumpWidget(testableWidget(tarotGame)), + ); await mockNetworkImagesFor( - () => tester.tap(find.byKey(const ValueKey('expansionTileTitle')))); + () => tester.tap(find.byKey(const ValueKey('expansionTileTitle'))), + ); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect( - find.byKey(const ValueKey('apiminiplayerwidget-p1')), findsOneWidget); + find.byKey(const ValueKey('apiminiplayerwidget-p1')), + findsOneWidget, + ); expect( - find.byKey(const ValueKey('apiminiplayerwidget-p2')), findsOneWidget); + find.byKey(const ValueKey('apiminiplayerwidget-p2')), + findsOneWidget, + ); expect( - find.byKey(const ValueKey('apiminiplayerwidget-p3')), findsOneWidget); + find.byKey(const ValueKey('apiminiplayerwidget-p3')), + findsOneWidget, + ); }); } diff --git a/test/widgets/tarot_widget_test.mocks.dart b/test/widgets/tarot_widget_test.mocks.dart index 969d6bf3..419f492f 100644 --- a/test/widgets/tarot_widget_test.mocks.dart +++ b/test/widgets/tarot_widget_test.mocks.dart @@ -44,6 +44,7 @@ import 'package:mockito/src/dummies.dart' as _i22; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractTarotScoreService_0 extends _i1.SmartFake implements _i2.AbstractTarotScoreService { diff --git a/test/widgets/team_stat_dialog_test.dart b/test/widgets/team_stat_dialog_test.dart index 737e84e5..a7d6befa 100644 --- a/test/widgets/team_stat_dialog_test.dart +++ b/test/widgets/team_stat_dialog_test.dart @@ -13,14 +13,14 @@ import 'localized_testable_widget.dart'; import 'team_stat_dialog_test.mocks.dart'; Widget testableWidget(Team team) => localizedTestableWidget( - Scaffold( - body: TeamStatDialog( - playerService: mockPlayerService, - teamService: mockTeamService, - team: team, - ), - ), - ); + Scaffold( + body: TeamStatDialog( + playerService: mockPlayerService, + teamService: mockTeamService, + team: team, + ), + ), +); final mockPlayerService = MockAbstractPlayerService(); final mockTeamService = MockAbstractTeamService(); @@ -37,20 +37,23 @@ void main() { testWidgets('existing team name', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget(team))); expect( - tester - .widget( - find.byKey(const ValueKey('nameTextField'))) - .controller - ?.text, - 'My name'); + tester + .widget(find.byKey(const ValueKey('nameTextField'))) + .controller + ?.text, + 'My name', + ); }); testWidgets('enter new name', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget(team))); await tester.enterText( - find.byKey(const ValueKey('nameTextField')), 'Ny new name'); + find.byKey(const ValueKey('nameTextField')), + 'Ny new name', + ); await mockNetworkImagesFor( - () => tester.testTextInput.receiveAction(TextInputAction.done)); + () => tester.testTextInput.receiveAction(TextInputAction.done), + ); await mockNetworkImagesFor(() => tester.pumpAndSettle()); verify(mockTeamService.update(team)).called(1); diff --git a/test/widgets/team_stat_dialog_test.mocks.dart b/test/widgets/team_stat_dialog_test.mocks.dart index 7062d66a..75ae9c1e 100644 --- a/test/widgets/team_stat_dialog_test.mocks.dart +++ b/test/widgets/team_stat_dialog_test.mocks.dart @@ -36,6 +36,7 @@ import 'package:mockito/src/dummies.dart' as _i14; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractPlayerRepository_0 extends _i1.SmartFake implements _i2.AbstractPlayerRepository { diff --git a/test/widgets/team_widget_test.dart b/test/widgets/team_widget_test.dart index e78dcc38..760857c6 100644 --- a/test/widgets/team_widget_test.dart +++ b/test/widgets/team_widget_test.dart @@ -12,13 +12,15 @@ import 'package:network_image_mock/network_image_mock.dart'; import 'team_widget_test.mocks.dart'; Widget testableWidget() => MaterialApp( - home: Material( - child: TeamWidget( - title: 'Nous', - teamService: mockAbstractTeamService, - playerService: mockAbstractPlayerService, - teamId: 'TEAM_ID'), - )); + home: Material( + child: TeamWidget( + title: 'Nous', + teamService: mockAbstractTeamService, + playerService: mockAbstractPlayerService, + teamId: 'TEAM_ID', + ), + ), +); final mockAbstractTeamService = MockAbstractTeamService(); final mockAbstractPlayerService = MockAbstractPlayerService(); @@ -30,31 +32,41 @@ void main() { final Player player2 = Player(owned: false, id: 'p2', userName: 'player 2'); when(mockAbstractTeamService.get('TEAM_ID')).thenAnswer( - (_) => Future(() => Team(id: 'TEAM_ID', players: ['p1', 'p2']))); - when(mockAbstractPlayerService.get('p1')) - .thenAnswer((_) => Future(() => player1)); - when(mockAbstractPlayerService.get('p2')) - .thenAnswer((_) => Future(() => player2)); + (_) => Future(() => Team(id: 'TEAM_ID', players: ['p1', 'p2'])), + ); + when( + mockAbstractPlayerService.get('p1'), + ).thenAnswer((_) => Future(() => player1)); + when( + mockAbstractPlayerService.get('p2'), + ).thenAnswer((_) => Future(() => player2)); }); testWidgets('Title', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget())); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 1000))); + () => tester.pumpAndSettle(const Duration(milliseconds: 1000)), + ); expect( - tester.widget(find.byKey(const ValueKey('textTitleWidget'))).data, - 'Nous'); + tester.widget(find.byKey(const ValueKey('textTitleWidget'))).data, + 'Nous', + ); }); testWidgets('Players', (WidgetTester tester) async { await mockNetworkImagesFor(() => tester.pumpWidget(testableWidget())); await mockNetworkImagesFor( - () => tester.pumpAndSettle(const Duration(milliseconds: 100))); + () => tester.pumpAndSettle(const Duration(milliseconds: 100)), + ); expect( - find.byKey(const ValueKey('apiminiplayerwidget-p1')), findsOneWidget); + find.byKey(const ValueKey('apiminiplayerwidget-p1')), + findsOneWidget, + ); expect( - find.byKey(const ValueKey('apiminiplayerwidget-p2')), findsOneWidget); + find.byKey(const ValueKey('apiminiplayerwidget-p2')), + findsOneWidget, + ); }); } diff --git a/test/widgets/team_widget_test.mocks.dart b/test/widgets/team_widget_test.mocks.dart index 6cf6e348..4b3f4d5e 100644 --- a/test/widgets/team_widget_test.mocks.dart +++ b/test/widgets/team_widget_test.mocks.dart @@ -33,6 +33,7 @@ import 'package:mockito/src/dummies.dart' as _i13; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeAbstractPlayerRepository_0 extends _i1.SmartFake implements _i2.AbstractPlayerRepository { diff --git a/test/widgets/trick_points_belote_widget_test.dart b/test/widgets/trick_points_belote_widget_test.dart index a4c968ae..fd5421ed 100644 --- a/test/widgets/trick_points_belote_widget_test.dart +++ b/test/widgets/trick_points_belote_widget_test.dart @@ -7,12 +7,8 @@ import '../units/mocks/fake_belote_round.dart'; import 'localized_testable_widget.dart'; Widget testableWidget(FakeBeloteRound beloteRound) => localizedTestableWidget( - Scaffold( - body: TrickPointsBeloteWidget( - round: beloteRound, - ), - ), - ); + Scaffold(body: TrickPointsBeloteWidget(round: beloteRound)), +); void main() { late FakeBeloteRound beloteRound; @@ -29,20 +25,24 @@ void main() { testWidgets("Add 2 to us score", (WidgetTester tester) async { await tester.pumpWidget(testableWidget(beloteRound)); - await tester - .tap(find.byKey(const ValueKey('trickPointsBeloteRightButton'))); - await tester - .tap(find.byKey(const ValueKey('trickPointsBeloteRightButton'))); + await tester.tap( + find.byKey(const ValueKey('trickPointsBeloteRightButton')), + ); + await tester.tap( + find.byKey(const ValueKey('trickPointsBeloteRightButton')), + ); expect(beloteRound.usTrickScore, 2); expect(beloteRound.themTrickScore, 150); }); testWidgets("Add 2 to us score", (WidgetTester tester) async { await tester.pumpWidget(testableWidget(beloteRound)); - await tester - .tap(find.byKey(const ValueKey('trickPointsBeloteRightButton'))); - await tester - .tap(find.byKey(const ValueKey('trickPointsBeloteRightButton'))); + await tester.tap( + find.byKey(const ValueKey('trickPointsBeloteRightButton')), + ); + await tester.tap( + find.byKey(const ValueKey('trickPointsBeloteRightButton')), + ); expect(beloteRound.usTrickScore, 2); expect(beloteRound.themTrickScore, 150); }); diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index e5bd990a..7e8b4447 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,6 +7,7 @@ #include "generated_plugin_registrant.h" #include +#include #include #include #include @@ -15,6 +16,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { CloudFirestorePluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("CloudFirestorePluginCApi")); + DynamicColorPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("DynamicColorPluginCApi")); FirebaseAuthPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("FirebaseAuthPluginCApi")); FirebaseCorePluginCApiRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 4d5411ce..df7d3112 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST cloud_firestore + dynamic_color firebase_auth firebase_core flutter_secure_storage_windows