Test of AppBarMediumApp and AppBarLargeApp (#153973)

Part of https://github.com/flutter/flutter/issues/130459

This are tests of snippets used in [SliverAppBar.medium const constructor](https://api.flutter.dev/flutter/material/SliverAppBar/SliverAppBar.medium.html) and [SliverAppBar.large const constructor](https://api.flutter.dev/flutter/material/SliverAppBar/SliverAppBar.large.html) Flutter API reference documentation.

The only way I've found to distinguish the SliverAppBar.medium and SliverAppBar.large constructors from the regular SliverAppBar is to check if the title is styled according to the [Material Design 3](https://m3.material.io/components/top-app-bar/specs) specification.
This commit is contained in:
miechoo 2024-09-04 21:46:16 +02:00 committed by GitHub
parent b99322ef66
commit 6d38831fc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 84 additions and 2 deletions

View File

@ -319,8 +319,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
'examples/api/test/material/platform_menu_bar/platform_menu_bar.0_test.dart',
'examples/api/test/material/flexible_space_bar/flexible_space_bar.0_test.dart',
'examples/api/test/material/app_bar/sliver_app_bar.2_test.dart',
'examples/api/test/material/app_bar/sliver_app_bar.3_test.dart',
'examples/api/test/material/navigation_rail/navigation_rail.extended_animation.0_test.dart',
'examples/api/test/painting/star_border/star_border.0_test.dart',
'examples/api/test/widgets/navigator/navigator.restorable_push_and_remove_until.0_test.dart',

View File

@ -0,0 +1,42 @@
// 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/app_bar/sliver_app_bar.2.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Visibility and interaction of crucial widgets', (WidgetTester tester) async {
await tester.pumpWidget(const example.AppBarMediumApp());
const String title = 'Medium App Bar';
expect(find.descendant(
of: find.byType(CustomScrollView),
matching: find.widgetWithText(SliverAppBar, title),
), findsOne);
expect(find.descendant(
of: find.byType(SliverAppBar),
matching: find.byType(IconButton),
), findsExactly(2));
// Based on https://m3.material.io/components/top-app-bar/specs the title of
// the SliverAppBar.medium widget is formatted with the headlineSmall style.
final BuildContext context = tester.element(find.byType(MaterialApp));
final TextStyle expectedTitleStyle = Theme.of(context).textTheme.headlineSmall!;
// There are two Text widgets: expanded and collapsed. The expanded is first.
final Finder titleFinder = find.text(title).first;
final TextStyle actualTitleStyle = DefaultTextStyle.of(tester.element(titleFinder)).style;
expect(actualTitleStyle, expectedTitleStyle);
// Scrolling the screen moves the title up.
expect(tester.getBottomLeft(titleFinder).dy, 96.0);
await tester.drag(titleFinder, const Offset(0.0, -200.0));
await tester.pump();
expect(tester.getBottomLeft(titleFinder).dy, 48.0);
});
}

View File

@ -0,0 +1,42 @@
// 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/app_bar/sliver_app_bar.3.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Visibility and interaction of crucial widgets', (WidgetTester tester) async {
await tester.pumpWidget(const example.AppBarLargeApp());
const String title = 'Large App Bar';
expect(find.descendant(
of: find.byType(CustomScrollView),
matching: find.widgetWithText(SliverAppBar, title),
), findsOne);
expect(find.descendant(
of: find.byType(SliverAppBar),
matching: find.byType(IconButton),
), findsExactly(2));
// Based on https://m3.material.io/components/top-app-bar/specs the title of
// the SliverAppBar.large widget is formatted with the headlineMedium style.
final BuildContext context = tester.element(find.byType(MaterialApp));
final TextStyle expectedTitleStyle = Theme.of(context).textTheme.headlineMedium!;
// There are two Text widgets: expanded and collapsed. The expanded is first.
final Finder titleFinder = find.text(title).first;
final TextStyle actualTitleStyle = DefaultTextStyle.of(tester.element(titleFinder)).style;
expect(actualTitleStyle, expectedTitleStyle);
// Scrolling the screen moves the title up.
expect(tester.getBottomLeft(titleFinder).dy, 124.0);
await tester.drag(titleFinder, const Offset(0.0, -200.0));
await tester.pump();
expect(tester.getBottomLeft(titleFinder).dy, 36.0);
});
}