Add tests for search anchor examples (#152659)
Contributes to https://github.com/flutter/flutter/issues/130459 It adds a test for - `examples/api/lib/material/search_anchor/search_anchor.1.dart` - `examples/api/lib/material/search_anchor/search_anchor.2.dart`
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// 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 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_api_samples/material/search_anchor/search_anchor.1.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('The SearchAnchor should be floating', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.PinnedSearchBarApp());
|
||||
|
||||
await tester.tap(find.byIcon(Icons.search));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
expect(find.widgetWithText(ListTile, 'Initial list item $i'), findsOne);
|
||||
}
|
||||
|
||||
await tester.tap(find.backButton());
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(SearchBar), findsOne);
|
||||
|
||||
final double searchBarHeight = tester.getSize(find.byType(SearchBar)).height;
|
||||
final TestPointer testPointer = TestPointer(1, ui.PointerDeviceKind.mouse);
|
||||
testPointer.hover(tester.getCenter(find.byType(CustomScrollView)));
|
||||
await tester.sendEventToBinding(testPointer.scroll(Offset(0.0, 2 * searchBarHeight)));
|
||||
await tester.pump();
|
||||
expect(find.byType(SearchBar), findsNothing);
|
||||
|
||||
await tester.sendEventToBinding(testPointer.scroll(Offset(0.0, -0.5 * searchBarHeight)));
|
||||
await tester.pump();
|
||||
expect(find.byType(SearchBar), findsOne);
|
||||
|
||||
await tester.sendEventToBinding(testPointer.scroll(Offset(0.0, 0.5 * searchBarHeight)));
|
||||
await tester.pump();
|
||||
expect(find.byType(SearchBar), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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/material/search_anchor/search_anchor.2.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Suggestion of the search bar can be selected', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.SearchBarApp());
|
||||
|
||||
expect(find.widgetWithText(AppBar, 'Search Anchor Sample'), findsOne);
|
||||
expect(find.text('No item selected'), findsOne);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.search));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
expect(find.widgetWithText(ListTile, 'item $i'), findsOne);
|
||||
}
|
||||
|
||||
await tester.tap(find.text('item 2'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Selected item: item 2'), findsOne);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.search));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.widgetWithText(ListTile, 'item 3'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Selected item: item 3'), findsOne);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user