mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
There is a lot of cross-library importing in the framework unit tests that I'd like to clean up, see the design doc for more: https://docs.google.com/document/d/1UHxALQqCbmgjnM1RNV9xE2pK3IGyx-UktGX1D7hYCjs/edit?tab=t.0 This PR cleans up a few obvious instances and adds TODOs for others. I created this while doing an investigation for the design doc linked above. I hope that we'll be able to follow up with fixes for all of the problematic tests (tracked in the issue below). Part of https://github.com/flutter/flutter/issues/177028
200 lines
6.3 KiB
Dart
200 lines
6.3 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
testWidgets('Shows prefix', (WidgetTester tester) async {
|
|
const Widget prefix = Text('Enter Value');
|
|
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(
|
|
child: CupertinoFormRow(prefix: prefix, child: CupertinoTextField()),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(prefix, tester.widget(find.byType(Text)));
|
|
});
|
|
|
|
testWidgets('Shows child', (WidgetTester tester) async {
|
|
const Widget child = CupertinoTextField();
|
|
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(child: CupertinoFormRow(child: child)),
|
|
),
|
|
);
|
|
|
|
expect(child, tester.widget(find.byType(CupertinoTextField)));
|
|
});
|
|
|
|
testWidgets('RTL puts prefix after child', (WidgetTester tester) async {
|
|
const Widget prefix = Text('Enter Value');
|
|
const Widget child = CupertinoTextField();
|
|
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(
|
|
child: Directionality(
|
|
textDirection: TextDirection.rtl,
|
|
child: CupertinoFormRow(prefix: prefix, child: child),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
tester.getTopLeft(find.byType(Text)).dx >
|
|
tester.getTopLeft(find.byType(CupertinoTextField)).dx,
|
|
true,
|
|
);
|
|
});
|
|
|
|
testWidgets('LTR puts child after prefix', (WidgetTester tester) async {
|
|
const Widget prefix = Text('Enter Value');
|
|
const Widget child = CupertinoTextField();
|
|
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(
|
|
child: Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: CupertinoFormRow(prefix: prefix, child: child),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
tester.getTopLeft(find.byType(Text)).dx >
|
|
tester.getTopLeft(find.byType(CupertinoTextField)).dx,
|
|
false,
|
|
);
|
|
});
|
|
|
|
testWidgets('Shows error widget', (WidgetTester tester) async {
|
|
const Widget error = Text('Error');
|
|
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(
|
|
child: CupertinoFormRow(error: error, child: CupertinoTextField()),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(error, tester.widget(find.byType(Text)));
|
|
});
|
|
|
|
testWidgets('Shows helper widget', (WidgetTester tester) async {
|
|
const Widget helper = Text('Helper');
|
|
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(
|
|
child: CupertinoFormRow(helper: helper, child: CupertinoTextField()),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(helper, tester.widget(find.byType(Text)));
|
|
});
|
|
|
|
testWidgets('Shows helper text above error text', (WidgetTester tester) async {
|
|
const Widget helper = Text('Helper');
|
|
const Widget error = CupertinoActivityIndicator();
|
|
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(
|
|
child: CupertinoFormRow(helper: helper, error: error, child: CupertinoTextField()),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
tester.getTopLeft(find.byType(CupertinoActivityIndicator)).dy >
|
|
tester.getTopLeft(find.byType(Text)).dy,
|
|
true,
|
|
);
|
|
});
|
|
|
|
testWidgets('Shows helper in label color and error text in red color', (
|
|
WidgetTester tester,
|
|
) async {
|
|
const Widget helper = Text('Helper');
|
|
const Widget error = Text('Error');
|
|
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(
|
|
child: CupertinoFormRow(helper: helper, error: error, child: CupertinoTextField()),
|
|
),
|
|
),
|
|
);
|
|
|
|
final DefaultTextStyle helperTextStyle = tester.widget(find.byType(DefaultTextStyle).first);
|
|
|
|
expect(helperTextStyle.style.color, CupertinoColors.label);
|
|
|
|
final DefaultTextStyle errorTextStyle = tester.widget(find.byType(DefaultTextStyle).last);
|
|
|
|
expect(errorTextStyle.style.color, CupertinoColors.destructiveRed);
|
|
});
|
|
|
|
// TODO(justinmc): Don't test Material interactions in Cupertino tests.
|
|
// https://github.com/flutter/flutter/issues/177028
|
|
testWidgets('CupertinoFormRow adapts to MaterialApp dark mode', (WidgetTester tester) async {
|
|
const Widget prefix = Text('Prefix');
|
|
const Widget helper = Text('Helper');
|
|
|
|
Widget buildFormRow(Brightness brightness) {
|
|
return MaterialApp(
|
|
theme: ThemeData(brightness: brightness),
|
|
home: const Center(
|
|
child: CupertinoFormRow(prefix: prefix, helper: helper, child: CupertinoTextField()),
|
|
),
|
|
);
|
|
}
|
|
|
|
// CupertinoFormRow with light theme.
|
|
await tester.pumpWidget(buildFormRow(Brightness.light));
|
|
RenderParagraph helperParagraph = tester.renderObject(find.text('Helper'));
|
|
expect(helperParagraph.text.style!.color, CupertinoColors.label);
|
|
// Text style should not return unresolved color.
|
|
expect(helperParagraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
|
|
RenderParagraph prefixParagraph = tester.renderObject(find.text('Prefix'));
|
|
expect(prefixParagraph.text.style!.color, CupertinoColors.label);
|
|
// Text style should not return unresolved color.
|
|
expect(prefixParagraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
|
|
|
|
// CupertinoFormRow with light theme.
|
|
await tester.pumpWidget(buildFormRow(Brightness.dark));
|
|
helperParagraph = tester.renderObject(find.text('Helper'));
|
|
expect(helperParagraph.text.style!.color, CupertinoColors.label);
|
|
// Text style should not return unresolved color.
|
|
expect(helperParagraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
|
|
prefixParagraph = tester.renderObject(find.text('Prefix'));
|
|
expect(prefixParagraph.text.style!.color, CupertinoColors.label);
|
|
// Text style should not return unresolved color.
|
|
expect(prefixParagraph.text.style!.color.toString().contains('UNRESOLVED'), isFalse);
|
|
});
|
|
|
|
testWidgets('CupertinoFormRow does not crash at zero area', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const CupertinoApp(
|
|
home: Center(
|
|
child: SizedBox.shrink(child: CupertinoFormRow(child: Text('X'))),
|
|
),
|
|
),
|
|
);
|
|
expect(tester.getSize(find.byType(CupertinoFormRow)), Size.zero);
|
|
});
|
|
}
|