Add test helpers for widget testing
Provides reusable MaterialApp wrappers with localization support for Flutter widget tests.
This commit is contained in:
parent
db0c5337ed
commit
4bee9c1498
57
test/helpers/test_helpers.dart
Normal file
57
test/helpers/test_helpers.dart
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
import 'package:agenda_tasks/l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
/// Wraps a widget with MaterialApp and localization support for testing
|
||||||
|
Widget createTestableWidget(Widget child) {
|
||||||
|
return MaterialApp(
|
||||||
|
localizationsDelegates: const [
|
||||||
|
AppLocalizations.delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
],
|
||||||
|
supportedLocales: const [
|
||||||
|
Locale('en'),
|
||||||
|
Locale('de'),
|
||||||
|
],
|
||||||
|
locale: const Locale('en'),
|
||||||
|
home: Scaffold(body: child),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wraps a widget with MaterialApp for testing (no Scaffold)
|
||||||
|
Widget createTestableWidgetNoScaffold(Widget child) {
|
||||||
|
return MaterialApp(
|
||||||
|
localizationsDelegates: const [
|
||||||
|
AppLocalizations.delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
],
|
||||||
|
supportedLocales: const [
|
||||||
|
Locale('en'),
|
||||||
|
Locale('de'),
|
||||||
|
],
|
||||||
|
locale: const Locale('en'),
|
||||||
|
home: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wraps a page widget with MaterialApp and navigation for testing
|
||||||
|
Widget createTestablePageWidget(Widget child) {
|
||||||
|
return MaterialApp(
|
||||||
|
localizationsDelegates: const [
|
||||||
|
AppLocalizations.delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
],
|
||||||
|
supportedLocales: const [
|
||||||
|
Locale('en'),
|
||||||
|
Locale('de'),
|
||||||
|
],
|
||||||
|
locale: const Locale('en'),
|
||||||
|
home: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user