Migrate time picker tests cases relying on localization from material_ui to flutter_localization#188753
Migrate time picker tests cases relying on localization from material_ui to flutter_localization#188753elliette wants to merge 3 commits into
Conversation
…_ui to flutter_localization
234b7ab to
7184892
Compare
|
|
||
| // This file is run as part of a reduced test set in CI on Mac and Windows | ||
| // machines. | ||
| @Tags(<String>['reduced-test-set']) |
There was a problem hiding this comment.
It seems a bit weird to need to add this when the only golden test is currently skipped. I could also move that test case to a temporarily_disabled_test directory (like we had in cupertino_ui/material_ui) if that's preferred.
There was a problem hiding this comment.
Code Review
This pull request refactors the mediaQueryBoilerplate helper in time_picker_test.dart to support custom locales and adds regression tests for Farsi 24-hour formatting, non-English separator alignment, and Korean day period spacing. The review feedback suggests extending mediaQueryBoilerplate with a textDirection parameter to properly support and test right-to-left (RTL) layouts, specifically for the new Farsi test case.
| WidgetTester tester, { | ||
| required bool alwaysUse24HourFormat, | ||
| required bool useMaterial3, | ||
| Locale locale = const Locale('en', 'US'), | ||
| }) async { | ||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| theme: ThemeData(useMaterial3: useMaterial3), | ||
| builder: (BuildContext context, Widget? child) { | ||
| return MediaQuery( | ||
| data: MediaQueryData(alwaysUse24HourFormat: alwaysUse24HourFormat), | ||
| child: child!, | ||
| ); | ||
| }, | ||
| home: Material( | ||
| child: Directionality( | ||
| textDirection: TextDirection.ltr, | ||
| child: Navigator( | ||
| onGenerateRoute: (RouteSettings settings) { | ||
| return MaterialPageRoute<void>( | ||
| builder: (BuildContext context) { | ||
| return TextButton( | ||
| onPressed: () { | ||
| showTimePicker( | ||
| context: context, | ||
| initialTime: const TimeOfDay(hour: 7, minute: 0), | ||
| Theme( | ||
| data: ThemeData(useMaterial3: useMaterial3), | ||
| child: Localizations( | ||
| locale: locale, | ||
| delegates: const <LocalizationsDelegate<dynamic>>[ | ||
| GlobalMaterialLocalizations.delegate, | ||
| GlobalWidgetsLocalizations.delegate, | ||
| ], | ||
| child: MediaQuery( | ||
| data: MediaQueryData( | ||
| alwaysUse24HourFormat: alwaysUse24HourFormat, | ||
| size: tester.view.physicalSize / tester.view.devicePixelRatio, | ||
| ), | ||
| child: Material( | ||
| child: Directionality( | ||
| textDirection: TextDirection.ltr, | ||
| child: Navigator( |
There was a problem hiding this comment.
The mediaQueryBoilerplate helper currently hardcodes textDirection: TextDirection.ltr. Since this helper is now being used for localized tests (including RTL locales like Farsi fa_IR), hardcoding LTR prevents the time picker from being tested in its actual RTL layout.
To fix this, we should add an optional textDirection parameter to mediaQueryBoilerplate and pass it to the Directionality widget.
WidgetTester tester, {
required bool alwaysUse24HourFormat,
required bool useMaterial3,
Locale locale = const Locale('en', 'US'),
TextDirection textDirection = TextDirection.ltr,
}) async {
await tester.pumpWidget(
Theme(
data: ThemeData(useMaterial3: useMaterial3),
child: Localizations(
locale: locale,
delegates: const <LocalizationsDelegate<dynamic>>[
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
child: MediaQuery(
data: MediaQueryData(
alwaysUse24HourFormat: alwaysUse24HourFormat,
size: tester.view.physicalSize / tester.view.devicePixelRatio,
),
child: Material(
child: Directionality(
textDirection: textDirection,
child: Navigator(| await mediaQueryBoilerplate( | ||
| tester, | ||
| locale: const Locale('fa', 'IR'), | ||
| useMaterial3: true, | ||
| alwaysUse24HourFormat: true, | ||
| ); |
There was a problem hiding this comment.
Port over `time_picker_test` from flutter/flutter#184279 The test cases that depend on `flutter_localizations` are being moved to `flutter_localizations` in PR flutter/flutter#188753, see flutter/flutter#188757 for rationale. Work towards flutter/flutter#182636 and flutter/flutter#188395 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Work towards #188757
The added test cases in this PR were split out of flutter/packages#12061. To avoid a circular dependency in
material_ui, we are moving any test cases that depend onflutter_localizationsout of thematerial_uipackage and intoflutter_localizations.Note: One of those test cases is currently skipped, since it relies on golden testing infrastructure that is not currently enabled for
flutter_localizations. I've filed #188758 to track re-enabling it.