Cupertino examples improvements and clean up (#103044)

This commit is contained in:
Taha Tesser
2022-05-05 09:22:53 +03:00
committed by GitHub
parent 27fee486ef
commit d80f3e3921
27 changed files with 219 additions and 202 deletions

View File

@@ -0,0 +1,23 @@
// 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_api_samples/cupertino/bottom_tab_bar/cupertino_tab_bar.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can switch between tabs', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoTabBarApp(),
);
expect(find.byType(CupertinoTabBar), findsOneWidget);
expect(find.text('Content of tab 0'), findsOneWidget);
await tester.tap(find.text('Contacts'));
await tester.pump();
expect(find.text('Content of tab 2'), findsOneWidget);
});
}

View File

@@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Has 4 CupertinoButton variants', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.CupertinoButtonApp(),
);
expect(find.byType(CupertinoButton), findsNWidgets(4));

View File

@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() {
testWidgets('Can change date, time and dateTime using CupertinoDatePicker', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.DatePickerApp(),
);
// Open the date picker.
await tester.tap(find.text('10-26-2016'));

View File

@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() {
testWidgets('Can pick a duration from CupertinoTimerPicker', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.TimerPickerApp(),
);
// Launch the timer picker.

View File

@@ -10,7 +10,7 @@ void main() {
testWidgets('Perform an action on CupertinoActionSheet', (WidgetTester tester) async {
const String actionText = 'Destructive Action';
await tester.pumpWidget(
const example.MyApp(),
const example.ActionSheetApp(),
);
// Launch the CupertinoActionSheet.

View File

@@ -10,7 +10,7 @@ void main() {
testWidgets('Perform an action on CupertinoAlertDialog', (WidgetTester tester) async {
const String actionText = 'Yes';
await tester.pumpWidget(
const example.MyApp(),
const example.AlertDialogApp(),
);
// Launch the CupertinoAlertDialog.

View File

@@ -0,0 +1,20 @@
// 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_api_samples/cupertino/nav_bar/cupertino_navigation_bar.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoNavigationBar is semi transparent', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NavBarApp(),
);
final Finder navBarFinder = find.byType(CupertinoNavigationBar);
expect(navBarFinder, findsOneWidget);
final CupertinoNavigationBar cupertinoNavigationBar = tester.widget<CupertinoNavigationBar>(navBarFinder);
expect(cupertinoNavigationBar.backgroundColor, CupertinoColors.systemGrey.withOpacity(0.5));
});
}

View File

@@ -11,7 +11,7 @@ const Offset dragUp = Offset(0.0, -150.0);
void main() {
testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.SliverNavBarApp(),
);
// Large title is visible and at lower position.
@@ -25,7 +25,7 @@ void main() {
testWidgets('Middle widget is visible in both collapsed and expanded states', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.SliverNavBarApp(),
);
// Navigate to a page that has both middle and large titles.
@@ -48,7 +48,7 @@ void main() {
testWidgets('CupertinoSliverNavigationBar with previous route has back button', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.SliverNavBarApp(),
);
// Navigate to a page that has back button

View File

@@ -10,7 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() {
testWidgets('Change selected fruit using CupertinoPicker', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.CupertinoPickerApp(),
);
// Open the Cupertino picker.

View File

@@ -8,12 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can change a selected segmented control', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.SegmentControlApp(),
);
expect(find.text('Selected Segment: midnight'), findsOneWidget);
await tester.tap(find.text('Cerulean'));
await tester.pumpAndSettle();
expect(find.text('Selected Segment: cerulean'), findsOneWidget);
});
}

View File

@@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can change a selected segmented control', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.SegmentControlApp(),
);
expect(find.text('Selected Segment: midnight'), findsOneWidget);

View File

@@ -16,7 +16,7 @@ void main() {
testWidgets('Can change value using CupertinoSlider', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.CupertinoSliderApp(),
);
// Check for the initial slider value.

View File

@@ -2,15 +2,22 @@
// 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_api_samples/cupertino/text_field/cupertino_text_field.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoTextField has initial text', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
const example.CupertinoTextFieldApp(),
);
expect(find.byType(CupertinoTextField), findsOneWidget);
expect(find.text('initial text'), findsOneWidget);
await tester.enterText(find.byType(CupertinoTextField), 'new text');
await tester.pump();
expect(find.text('new text'), findsOneWidget);
});
}