Update Cupertino examples and add missing tests (#103128)

This commit is contained in:
Taha Tesser
2022-05-07 10:29:10 +03:00
committed by GitHub
parent b05b44e88a
commit 803f9959d8
30 changed files with 493 additions and 235 deletions

View File

@@ -0,0 +1,26 @@
// 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/material.dart';
import 'package:flutter_api_samples/cupertino/context_menu/cupertino_context_menu.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can open cupertino context menu', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ContextMenuApp(),
);
final Offset logo = tester.getCenter(find.byType(FlutterLogo));
expect(find.text('Favorite'), findsNothing);
await tester.startGesture(logo);
await tester.pumpAndSettle();
expect(find.text('Favorite'), findsOneWidget);
await tester.tap(find.text('Favorite'));
await tester.pumpAndSettle();
expect(find.text('Favorite'), findsNothing);
});
}

View File

@@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
const Offset dragUp = Offset(0.0, -150.0);
void main() {
testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (WidgetTester tester) async {
testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
@@ -23,7 +23,7 @@ void main() {
expect(tester.getBottomLeft(find.text('Contacts').first).dy, 36.0);
});
testWidgets('Middle widget is visible in both collapsed and expanded states', (WidgetTester tester) async {
testWidgets('Middle widget is visible in both collapsed and expanded states', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
@@ -46,7 +46,7 @@ void main() {
expect(tester.getBottomLeft(find.text('Family').first).dy, 36.0);
});
testWidgets('CupertinoSliverNavigationBar with previous route has back button', (WidgetTester tester) async {
testWidgets('CupertinoSliverNavigationBar with previous route has back button', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);

View File

@@ -0,0 +1,21 @@
// 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/page_scaffold/cupertino_page_scaffold.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can increment counter', (WidgetTester tester) async {
await tester.pumpWidget(
const example.PageScaffoldApp(),
);
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
expect(find.text('You have pressed the button 0 times.'), findsOneWidget);
await tester.tap(find.byType(CupertinoButton));
await tester.pumpAndSettle();
expect(find.text('You have pressed the button 1 times.'), findsOneWidget);
});
}

View File

@@ -0,0 +1,26 @@
// 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/refresh/cupertino_sliver_refresh_control.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can pull down to reveal CupertinoSliverRefreshControl', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RefreshControlApp(),
);
expect(find.byType(CupertinoSliverRefreshControl), findsNothing);
expect(find.byType(Container), findsNWidgets(3));
final Finder firstItem = find.byType(Container).first;
await tester.drag(firstItem, const Offset(0.0, 150.0), touchSlopY: 0);
await tester.pump();
expect(find.byType(CupertinoSliverRefreshControl), findsOneWidget);
await tester.pumpAndSettle();
expect(find.byType(CupertinoSliverRefreshControl), findsNothing);
expect(find.byType(Container), findsNWidgets(4));
});
}

View File

@@ -0,0 +1,26 @@
// 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/route/show_cupertino_dialog.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tap on button displays cupertino dialog', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoDialogApp(),
);
final Finder dialogTitle = find.text('Title');
expect(dialogTitle, findsNothing);
await tester.tap(find.byType(CupertinoButton));
await tester.pumpAndSettle();
expect(dialogTitle, findsOneWidget);
await tester.tap(find.text('Yes'));
await tester.pumpAndSettle();
expect(dialogTitle, findsNothing);
});
}

View File

@@ -0,0 +1,26 @@
// 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/route/show_cupertino_modal_popup.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tap on button displays cupertino modal dialog', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ModalPopupApp(),
);
final Finder actionOne = find.text('Action One');
expect(actionOne, findsNothing);
await tester.tap(find.byType(CupertinoButton));
await tester.pumpAndSettle();
expect(actionOne, findsOneWidget);
await tester.tap(find.text('Action One'));
await tester.pumpAndSettle();
expect(actionOne, findsNothing);
});
}

View File

@@ -0,0 +1,26 @@
// 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/scrollbar/cupertino_scrollbar.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('List view displays CupertinoScrollbar', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ScrollbarApp(),
);
expect(find.text('Item 0'), findsOneWidget);
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));
await gesture.moveBy(const Offset(0.0, -100.0));
await tester.pumpAndSettle();
expect(find.text('Item 0'), findsNothing);
final Finder scrollbar = find.byType(CupertinoScrollbar);
expect(scrollbar, findsOneWidget);
expect(tester.getTopLeft(scrollbar).dy, 0.0);
expect(tester.getBottomLeft(scrollbar).dy, 600.0);
});
}

View File

@@ -0,0 +1,26 @@
// 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/scrollbar/cupertino_scrollbar.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('List view displays CupertinoScrollbar', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ScrollbarApp(),
);
expect(find.text('Item 0'), findsOneWidget);
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));
await gesture.moveBy(const Offset(0.0, -100.0));
await tester.pumpAndSettle();
expect(find.text('Item 0'), findsNothing);
final Finder scrollbar = find.byType(CupertinoScrollbar);
expect(scrollbar, findsOneWidget);
expect(tester.getTopLeft(scrollbar).dy, 0.0);
expect(tester.getBottomLeft(scrollbar).dy, 600.0);
});
}

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.SegmentControlApp(),
const example.SegmentedControlApp(),
);
expect(find.text('Selected Segment: midnight'), 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.SegmentControlApp(),
const example.SegmentedControlApp(),
);
expect(find.text('Selected Segment: midnight'), findsOneWidget);

View File

@@ -0,0 +1,24 @@
// 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/text_form_field_row/cupertino_text_form_field_row.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can enter text in CupertinoTextFormFieldRow', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FormSectionApp(),
);
expect(find.byType(CupertinoFormSection), findsOneWidget);
expect(find.byType(CupertinoTextFormFieldRow), findsNWidgets(5));
expect(find.widgetWithText(CupertinoTextFormFieldRow, 'abcd'), findsNothing);
await tester.enterText(find.byType(CupertinoTextFormFieldRow).first, 'abcd');
await tester.pump();
expect(find.widgetWithText(CupertinoTextFormFieldRow, 'abcd'), findsOneWidget);
});
}