Skip to content

Commit a0e27cc

Browse files
authored
[material_ui] Enable localized time_picker_test cases (flutter#12391)
Follow up to flutter/packages#12061, flutter/packages#12119 Port over the remaining `time_picker_test` cases from flutter#184279 that were initially excluded in flutter/packages#12061 due to lack of localization support in `material_ui`. Work towards flutter#182636 and 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.
1 parent 41b464a commit a0e27cc

1 file changed

Lines changed: 144 additions & 0 deletions

File tree

‎packages/material_ui/test/time_picker_test.dart‎

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,64 @@ void main() {
235235
expect(selectedLabels.map<bool>((dynamic tp) => tp.inner as bool), inner0To23);
236236
});
237237

238+
// Regression test for https://github.com/flutter/flutter/issues/164860
239+
testWidgets('Material3 - formats 24-hour numbers correctly in Farsi', (
240+
WidgetTester tester,
241+
) async {
242+
await mediaQueryBoilerplate(
243+
tester,
244+
locale: const Locale('fa', 'IR'),
245+
materialType: MaterialType.material3,
246+
);
247+
248+
final labels00To23 = <String>[
249+
'۰',
250+
'۱',
251+
'۲',
252+
'۳',
253+
'۴',
254+
'۵',
255+
'۶',
256+
'۷',
257+
'۸',
258+
'۹',
259+
'۱۰',
260+
'۱۱',
261+
'۱۲',
262+
'۱۳',
263+
'۱۴',
264+
'۱۵',
265+
'۱۶',
266+
'۱۷',
267+
'۱۸',
268+
'۱۹',
269+
'۲۰',
270+
'۲۱',
271+
'۲۲',
272+
'۲۳',
273+
];
274+
final inner0To23 = List<bool>.generate(24, (int index) => index >= 12);
275+
276+
final CustomPaint dialPaint = tester.widget(findDialPaint);
277+
final dynamic dialPainter = dialPaint.painter;
278+
// ignore: avoid_dynamic_calls
279+
final primaryLabels = dialPainter.primaryLabels as List<dynamic>;
280+
// ignore: avoid_dynamic_calls
281+
expect(primaryLabels.map<String>((dynamic tp) => tp.painter.text.text as String), labels00To23);
282+
// ignore: avoid_dynamic_calls
283+
expect(primaryLabels.map<bool>((dynamic tp) => tp.inner as bool), inner0To23);
284+
285+
// ignore: avoid_dynamic_calls
286+
final selectedLabels = dialPainter.selectedLabels as List<dynamic>;
287+
expect(
288+
// ignore: avoid_dynamic_calls
289+
selectedLabels.map<String>((dynamic tp) => tp.painter.text.text as String),
290+
labels00To23,
291+
);
292+
// ignore: avoid_dynamic_calls
293+
expect(selectedLabels.map<bool>((dynamic tp) => tp.inner as bool), inner0To23);
294+
});
295+
238296
testWidgets('Material3 - Dial background uses correct default color', (
239297
WidgetTester tester,
240298
) async {
@@ -1480,6 +1538,35 @@ void main() {
14801538
},
14811539
);
14821540

1541+
testWidgets(
1542+
'TimePicker dialog displays centered separator between hour and minute inputs for non-english locale',
1543+
(WidgetTester tester) async {
1544+
tester.view.physicalSize = const Size(400, 800);
1545+
tester.view.devicePixelRatio = 1.0;
1546+
addTearDown(tester.view.reset);
1547+
1548+
await tester.pumpWidget(
1549+
const MaterialApp(
1550+
localizationsDelegates: GlobalMaterialLocalizations.delegates,
1551+
supportedLocales: <Locale>[Locale('en'), Locale('es')],
1552+
locale: Locale('es'),
1553+
home: Material(
1554+
child: TimePickerDialog(
1555+
initialTime: TimeOfDay(hour: 12, minute: 0),
1556+
initialEntryMode: TimePickerEntryMode.input,
1557+
),
1558+
),
1559+
),
1560+
);
1561+
await tester.pumpAndSettle();
1562+
1563+
await expectLater(
1564+
find.byType(Dialog),
1565+
matchesGoldenFile('time_picker.dialog.separator.alignment.non_english_locale.png'),
1566+
);
1567+
},
1568+
);
1569+
14831570
testWidgets('provides semantics information for text fields', (WidgetTester tester) async {
14841571
final semantics = SemanticsTester(tester);
14851572
await mediaQueryBoilerplate(
@@ -2453,6 +2540,59 @@ void main() {
24532540
expect(tester.getSize(findBorderPainter().first), const Size(96.0, 70.0));
24542541
});
24552542

2543+
// Regression test for https://github.com/flutter/flutter/issues/162229.
2544+
testWidgets(
2545+
'Time picker spacing between time control and day period control for locales using "a h:mm" pattern',
2546+
(WidgetTester tester) async {
2547+
addTearDown(tester.view.reset);
2548+
2549+
final Finder amMaterialFinder = find.descendant(
2550+
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_AmPmButton').first,
2551+
matching: find.byType(Material),
2552+
);
2553+
final Finder timeControlFinder = find
2554+
.ancestor(of: find.text('7'), matching: find.byType(Row))
2555+
.first;
2556+
2557+
// Render in portrait mode.
2558+
tester.view.physicalSize = const Size(800, 800.5);
2559+
tester.view.devicePixelRatio = 1;
2560+
await mediaQueryBoilerplate(
2561+
tester,
2562+
materialType: MaterialType.material3,
2563+
locale: const Locale('ko', 'KR'),
2564+
);
2565+
2566+
const dayPeriodPortraitGap = 12.0; // From Material spec.
2567+
expect(
2568+
tester.getBottomLeft(timeControlFinder).dx - tester.getBottomRight(amMaterialFinder).dx,
2569+
dayPeriodPortraitGap,
2570+
);
2571+
2572+
// Dismiss the dialog.
2573+
final MaterialLocalizations materialLocalizations = MaterialLocalizations.of(
2574+
tester.element(find.byType(TextButton).first),
2575+
);
2576+
await tester.tap(find.text(materialLocalizations.okButtonLabel));
2577+
await tester.pumpAndSettle();
2578+
2579+
// Render in landscape mode.
2580+
tester.view.physicalSize = const Size(800.5, 800);
2581+
tester.view.devicePixelRatio = 1;
2582+
await mediaQueryBoilerplate(
2583+
tester,
2584+
materialType: MaterialType.material3,
2585+
locale: const Locale('ko', 'KR'),
2586+
);
2587+
2588+
const dayPeriodLandscapeGap = 16.0; // From Material spec.
2589+
expect(
2590+
tester.getTopLeft(timeControlFinder).dy - tester.getBottomLeft(amMaterialFinder).dy,
2591+
dayPeriodLandscapeGap,
2592+
);
2593+
},
2594+
);
2595+
24562596
testWidgets('AM/PM buttons have correct selected/checked semantics for platform variant', (
24572597
WidgetTester tester,
24582598
) async {
@@ -2554,10 +2694,14 @@ Future<void> mediaQueryBoilerplate(
25542694
bool tapButton = true,
25552695
required MaterialType materialType,
25562696
Orientation? orientation,
2697+
Locale locale = const Locale('en', 'US'),
25572698
}) async {
25582699
await tester.pumpWidget(
25592700
MaterialApp(
25602701
theme: ThemeData(useMaterial3: materialType == MaterialType.material3),
2702+
locale: locale,
2703+
supportedLocales: <Locale>[locale],
2704+
localizationsDelegates: GlobalMaterialLocalizations.delegates,
25612705
builder: (BuildContext context, Widget? child) {
25622706
return MediaQuery(
25632707
data: MediaQueryData(

0 commit comments

Comments
 (0)