chore(legacy): add test infrastructure + mocktail
This commit is contained in:
6
packages/sf_shared/lib/src/testing/container_helper.dart
Normal file
6
packages/sf_shared/lib/src/testing/container_helper.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_riverpod/misc.dart' show Override;
|
||||
|
||||
ProviderContainer makeContainer({List<Override> overrides = const []}) {
|
||||
return ProviderContainer(overrides: overrides);
|
||||
}
|
||||
35
packages/sf_shared/lib/src/testing/pump_app.dart
Normal file
35
packages/sf_shared/lib/src/testing/pump_app.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_riverpod/misc.dart' show Override;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sf_localizations/sf_localizations.dart';
|
||||
|
||||
/// Set [withLocalizations] only when the widget uses `context.translate(...)`;
|
||||
/// it requires the JSON asset bundle loaded in the test environment.
|
||||
Future<void> pumpApp(
|
||||
WidgetTester tester, {
|
||||
required Widget child,
|
||||
List<Override> overrides = const [],
|
||||
Locale locale = const Locale('es'),
|
||||
bool withLocalizations = false,
|
||||
}) async {
|
||||
final delegates = <LocalizationsDelegate<Object>>[
|
||||
if (withLocalizations) SFLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
];
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: overrides,
|
||||
child: MaterialApp(
|
||||
locale: locale,
|
||||
supportedLocales: supportedLanguages.map(Locale.new).toList(),
|
||||
localizationsDelegates: delegates,
|
||||
home: Scaffold(body: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
2
packages/sf_shared/lib/testing.dart
Normal file
2
packages/sf_shared/lib/testing.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
export 'src/testing/container_helper.dart';
|
||||
export 'src/testing/pump_app.dart';
|
||||
@@ -12,6 +12,10 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_localizations:
|
||||
sdk: flutter
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
sf_infrastructure:
|
||||
path: ../../packages/sf_infrastructure
|
||||
@@ -41,12 +45,11 @@ dependencies:
|
||||
permission_handler: ^12.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^5.0.0
|
||||
riverpod_generator: ^3.0.3
|
||||
build_runner: ^2.7.1
|
||||
riverpod_lint: ^3.0.3
|
||||
mocktail: ^1.0.4
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
|
||||
Reference in New Issue
Block a user