Fix some issues with samples (#95044)

This commit is contained in:
Greg Spencer
2021-12-13 09:29:09 -08:00
committed by GitHub
parent 77d6e96083
commit bbc21fe3ed
10 changed files with 125 additions and 47 deletions

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/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_api_samples/services/mouse_cursor/mouse_cursor.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Uses Text Cursor', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
);
expect(find.byType(MouseRegion), findsNWidgets(2)); // There's one in the MaterialApp
final Finder mouseRegionFinder = find.ancestor(of: find.byType(Container), matching: find.byType(MouseRegion));
expect(mouseRegionFinder, findsOneWidget);
expect((tester.widget(mouseRegionFinder) as MouseRegion).cursor, equals(SystemMouseCursors.text));
});
}

View File

@@ -0,0 +1,32 @@
// 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_api_samples/widgets/will_pop_scope/will_pop_scope.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('pressing shouldPop button changes shouldPop', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
);
final Finder buttonFinder = find.text('shouldPop: true');
expect(buttonFinder, findsOneWidget);
await tester.tap(buttonFinder);
await tester.pump();
expect(find.text('shouldPop: false'), findsOneWidget);
});
testWidgets('pressing Push button pushes route', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
);
final Finder buttonFinder = find.text('Push');
expect(buttonFinder, findsOneWidget);
expect(find.byType(example.MyStatefulWidget), findsOneWidget);
await tester.tap(buttonFinder);
await tester.pumpAndSettle();
expect(find.byType(example.MyStatefulWidget, skipOffstage: false), findsNWidgets(2));
});
}