chore(legacy): add test infrastructure + mocktail

This commit is contained in:
2026-04-21 19:32:40 +02:00
parent 424b8d9034
commit 1056895c31
8 changed files with 201 additions and 2 deletions

View 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);
}

View 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),
),
),
);
}

View File

@@ -0,0 +1,2 @@
export 'src/testing/container_helper.dart';
export 'src/testing/pump_app.dart';

View File

@@ -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