Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unit testing repositories #202

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .fvmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"flutter": "3.13.9"
"flutter": "3.13.9",
"flavors": {}
}
3 changes: 3 additions & 0 deletions .github/hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

printf "\e[33;1m%s\e[0m\n" 'Running the Pre-push checks'
./scripts/checks.sh

printf "\e[33;1m%s\e[0m\n" 'Running the Pre-push tests'
fvm flutter test
1 change: 1 addition & 0 deletions Gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,16 @@ dart_code_metrics:
allowed-duplicated-chains: 3
- prefer-trailing-comma



# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
analyzer:
exclude:
- '**/*.freezed.dart'
- '**/*.g.dart'
- '**/*.gen.dart'
- '**/*.gr.dart'
- 'bricks'
- 'lib/generated_plugin_registrant.dart'
- "**/*.freezed.dart"
- "**/*.g.dart"
- "**/*.gen.dart"
- "**/*.gr.dart"
- "bricks"
- "lib/generated_plugin_registrant.dart"
errors:
invalid_annotation_target: ignore
unused_element: ignore # https://github.com/dart-lang/sdk/issues/49025
14 changes: 8 additions & 6 deletions lib/core/di/di_provider.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_template/core/di/app_providers_module.dart';
import 'package:flutter_template/core/di/di_repository_module.dart';
import 'package:flutter_template/core/di/di_utils_module.dart';
import 'package:get_it/get_it.dart';

abstract class DiProvider {
static GetIt get _instance => GetIt.instance;
@visibleForTesting
static GetIt get instance => GetIt.instance;

static Future<void> init() async {
// Setup app providers have to be done first
await AppProvidersModule().setupModule(_instance);
UtilsDiModule().setupModule(_instance);
RepositoryDiModule().setupModule(_instance);
await _instance.allReady();
await AppProvidersModule().setupModule(instance);
UtilsDiModule().setupModule(instance);
RepositoryDiModule().setupModule(instance);
await instance.allReady();
}

static T get<T extends Object>({
String? instanceName,
dynamic param1,
dynamic param2,
}) =>
_instance.get(instanceName: instanceName, param1: param1, param2: param2);
instance.get(instanceName: instanceName, param1: param1, param2: param2);
}
4 changes: 3 additions & 1 deletion lib/core/di/di_repository_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class RepositoryDiModule {

extension _GetItDiModuleExtensions on GetIt {
void _setupProvidersAndUtils() {
registerLazySingleton(() => HttpServiceDio([AuthInterceptor(get())]));
registerLazySingleton<HttpService>(
() => HttpServiceDio([AuthInterceptor(get())]),
);
}

void _setupRepositories() {
Expand Down
2 changes: 1 addition & 1 deletion lib/core/source/auth_remote_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter_template/core/model/service/service_response.dart';
import 'package:flutter_template/core/source/common/http_service.dart';

class AuthRemoteSource {
final HttpServiceDio _httpService;
final HttpService _httpService;

static const _urlLogin = 'auth/v1/token';

Expand Down
4 changes: 2 additions & 2 deletions lib/core/source/project_remote_source.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:flutter_template/core/model/service/service_response.dart';
import 'package:flutter_template/core/model/project.dart';
import 'package:flutter_template/core/model/service/service_response.dart';
import 'package:flutter_template/core/source/common/http_service.dart';

class ProjectRemoteSource {
static const _urlGetProjects = 'rest/v1/projects?select=*';

final HttpServiceDio _httpService;
final HttpService _httpService;

ProjectRemoteSource(this._httpService);

Expand Down
108 changes: 106 additions & 2 deletions pubspec.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: flutter_template
description: A new Flutter project.

publish_to: 'none'
publish_to: "none"

version: 1.0.0+1

environment:
sdk: '>=3.0.0 <4.0.0'
sdk: ">=3.0.0 <4.0.0"
flutter: 3.13.9

dependencies:
Expand Down Expand Up @@ -54,6 +54,7 @@ dev_dependencies:

auto_route_generator: 7.3.1
build_runner: 2.4.6
bloc_test: 9.1.5
dart_code_metrics: 5.7.6
flutter_flavorizr: 2.2.1
flutter_gen_runner: 5.3.1
Expand All @@ -62,6 +63,7 @@ dev_dependencies:
freezed: 2.4.1
json_serializable: 6.7.1
lints: 3.0.0
mocktail: 1.0.1

flutter:
generate: true
Expand All @@ -80,19 +82,19 @@ flutter_gen:
flutter_launcher_icons:
android: true
ios: true
image_path: 'icons/ic_launcher.png'
image_path_ios: 'icons/ic_launcher_ios.png' # Transparency not supported on IOS
adaptive_icon_foreground: 'icons/ic_launcher_foreground.png'
adaptive_icon_background: '#ee1a64'
image_path: "icons/ic_launcher.png"
image_path_ios: "icons/ic_launcher_ios.png" # Transparency not supported on IOS
adaptive_icon_foreground: "icons/ic_launcher_foreground.png"
adaptive_icon_background: "#ee1a64"
remove_alpha_ios: true
web:
generate: false
windows:
generate: false

flutter_native_splash:
color: '#ffffff'
image: 'icons/splash_logo.png'
color: "#ffffff"
image: "icons/splash_logo.png"
android_12:
image: 'icons/splash_logo_android_12.png'
branding: 'icons/splash_branding.png'
image: "icons/splash_logo_android_12.png"
branding: "icons/splash_branding.png"
3 changes: 3 additions & 0 deletions scripts/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ echo ':: Run Catalog checks'
echo ':: Run linter catalog ::'
fvm flutter analyze catalog || error "Linter error - Flutter Analyze error - Catalog gallery"
fvm flutter analyze catalog/gallery || error "Linter error - Flutter Analyze error - Catalog gallery"

echo ':: Run tests ::'
fvm flutter test || error "Tests failed"
5 changes: 5 additions & 0 deletions test/common/cubit_mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_template/ui/section/error_handler/global_event_handler_cubit.dart';

class MockGlobalEventHandlerCubit extends MockCubit<GlobalEventHandlerState>
implements GlobalEventHandlerCubit {}
Loading
Loading