Skip to content

Commit c1f7d92

Browse files
authored
[material_ui] Enable bottom_navigation_bar_test (#12005)
Port over `bottom_navigation_bar_test` from flutter/flutter#184279 * Ports over `feedback_tester.dart` * Ports over `bottom_navigation_bar_test` As part of this change, moved `_findByTooltip` (originally defined in `navigation_bar_test`) into new shared `test/finders.dart` (see flutter/flutter#186966 for details). Work towards flutter/flutter#182636 and flutter/flutter#188395 ## Pre-Review Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran [the auto-formatter]. - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1]. - [x] I updated/added any relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [the auto-formatter]: https://github.com/flutter/packages/blob/main/script/tool/README.md#format-code [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [the version and CHANGELOG instructions]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version-and-changelog-updates [semantic versioning]: https://dart.dev/tools/pub/versioning#semantic-versions [repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style [test exemption]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
1 parent 6ca02e8 commit c1f7d92

4 files changed

Lines changed: 105 additions & 49 deletions

File tree

packages/material_ui/temporarily_disabled_tests/bottom_navigation_bar_test.dart renamed to packages/material_ui/test/bottom_navigation_bar_test.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
@Skip(
6-
'This file is skipped due to a cross-import that needs to be fixed. Tracked in https://github.com/flutter/flutter/issues/177028.',
7-
)
85
// This file is run as part of a reduced test set in CI on Mac and Windows
96
// machines.
107
@Tags(<String>['reduced-test-set'])
@@ -13,13 +10,14 @@ library;
1310
import 'dart:math';
1411
import 'dart:ui';
1512

16-
import 'package:material_ui/material_ui.dart';
1713
import 'package:flutter/rendering.dart';
1814
import 'package:flutter_test/flutter_test.dart';
15+
import 'package:material_ui/material_ui.dart';
1916
import 'package:vector_math/vector_math_64.dart' show Vector3;
2017

21-
import '../widgets/feedback_tester.dart';
22-
import '../widgets/semantics_tester.dart';
18+
import 'feedback_tester.dart';
19+
import 'finders.dart';
20+
import 'semantics_tester.dart';
2321

2422
void main() {
2523
testWidgets('BottomNavigationBar callback test', (WidgetTester tester) async {
@@ -1716,15 +1714,15 @@ void main() {
17161714

17171715
expect(find.text('A'), findsOneWidget);
17181716
await tester.longPress(find.text('A'));
1719-
expect(find.byTooltip('A tooltip'), findsOneWidget);
1717+
expect(findByTooltip('A tooltip'), findsOneWidget);
17201718

17211719
expect(find.text('B'), findsOneWidget);
17221720
await tester.longPress(find.text('B'));
1723-
expect(find.byTooltip('B'), findsNothing);
1721+
expect(findByTooltip('B'), findsNothing);
17241722

17251723
expect(find.text('C'), findsOneWidget);
17261724
await tester.longPress(find.text('C'));
1727-
expect(find.byTooltip('C'), findsNothing);
1725+
expect(findByTooltip('C'), findsNothing);
17281726
});
17291727

17301728
testWidgets('BottomNavigationBar limits width of tiles with long labels', (
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/services.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
8+
/// Tracks how often feedback has been requested since its instantiation.
9+
///
10+
/// It replaces the MockMethodCallHandler of [SystemChannels.platform] and
11+
/// cannot be used in combination with other classes that do the same.
12+
class FeedbackTester {
13+
FeedbackTester() {
14+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
15+
SystemChannels.platform,
16+
_handler,
17+
);
18+
}
19+
20+
/// Number of times haptic feedback was requested (vibration).
21+
int get hapticCount => _hapticCount;
22+
int _hapticCount = 0;
23+
24+
/// Number of times the click sound was requested to play.
25+
int get clickSoundCount => _clickSoundCount;
26+
int _clickSoundCount = 0;
27+
28+
Future<void> _handler(MethodCall methodCall) async {
29+
if (methodCall.method == 'HapticFeedback.vibrate') {
30+
_hapticCount++;
31+
}
32+
if (methodCall.method == 'SystemSound.play' &&
33+
methodCall.arguments == SystemSoundType.click.toString()) {
34+
_clickSoundCount++;
35+
}
36+
}
37+
38+
/// Stops tracking.
39+
void dispose() {
40+
assert(
41+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(
42+
SystemChannels.platform.name,
43+
_handler,
44+
),
45+
);
46+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
47+
SystemChannels.platform,
48+
null,
49+
);
50+
}
51+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:material_ui/material_ui.dart';
7+
8+
/// Finds [RawTooltip] or [Tooltip] widgets with the given `message`.
9+
///
10+
/// ## Sample code
11+
///
12+
/// ```dart
13+
/// expect(find.byTooltip('Back'), findsOneWidget);
14+
/// expect(find.byTooltip(RegExp('Back.*')), findsNWidgets(2));
15+
/// ```
16+
///
17+
/// If the `skipOffstage` argument is true (the default), then this skips
18+
/// nodes that are [Offstage] or that are from inactive [Route]s.
19+
///
20+
/// This was copied from flutter_test, which uses flutter/material.dart.
21+
///
22+
// TODO(justinmc): Port flutter_test to material_ui, then delete this method and
23+
// use that one. See https://github.com/flutter/flutter/issues/186966
24+
Finder findByTooltip(Pattern message, {bool skipOffstage = true}) {
25+
return find.byWidgetPredicate((Widget widget) {
26+
// Compare RawTooltip's semantics tooltip with the given message.
27+
// However, Tooltip's message needs to be checked directly if:
28+
// 1. Tooltip.excludeFromSemantics is true, since in this case Tooltip
29+
// provides no semantics tooltip to the underlying RawTooltip.
30+
// 2. Tooltip.message and Tooltip.richMessage are empty, since in this
31+
// case no RawTooltip is created.
32+
if (widget is Tooltip) {
33+
final String tooltipMessage = widget.message ?? widget.richMessage!.toPlainText();
34+
if ((widget.excludeFromSemantics ?? false) || tooltipMessage.isEmpty) {
35+
return message is RegExp ? message.hasMatch(tooltipMessage) : tooltipMessage == message;
36+
}
37+
}
38+
return widget is RawTooltip &&
39+
(message is RegExp
40+
? message.hasMatch(widget.semanticsTooltip ?? '')
41+
: widget.semanticsTooltip == message);
42+
}, skipOffstage: skipOffstage);
43+
}

packages/material_ui/test/navigation_bar_test.dart

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:flutter/gestures.dart';
1414
import 'package:flutter/services.dart';
1515
import 'package:flutter_test/flutter_test.dart';
1616
import 'package:material_ui/material_ui.dart';
17+
import 'finders.dart';
1718

1819
void main() {
1920
testWidgets('Navigation bar updates destinations when tapped', (WidgetTester tester) async {
@@ -440,15 +441,15 @@ void main() {
440441

441442
expect(find.text('A'), findsOneWidget);
442443
await tester.longPress(find.text('A'));
443-
expect(_findByTooltip('A tooltip'), findsOneWidget);
444+
expect(findByTooltip('A tooltip'), findsOneWidget);
444445

445446
expect(find.text('B'), findsOneWidget);
446447
await tester.longPress(find.text('B'));
447-
expect(_findByTooltip('B'), findsOneWidget);
448+
expect(findByTooltip('B'), findsOneWidget);
448449

449450
expect(find.text('C'), findsOneWidget);
450451
await tester.longPress(find.text('C'));
451-
expect(_findByTooltip('C'), findsNothing);
452+
expect(findByTooltip('C'), findsNothing);
452453
});
453454

454455
testWidgets('Navigation bar semantics', (WidgetTester tester) async {
@@ -1814,40 +1815,3 @@ TextStyle _getLabelStyle(WidgetTester tester, String text) {
18141815
.text
18151816
.style!;
18161817
}
1817-
1818-
/// Finds [RawTooltip] or [Tooltip] widgets with the given `message`.
1819-
///
1820-
/// ## Sample code
1821-
///
1822-
/// ```dart
1823-
/// expect(find.byTooltip('Back'), findsOneWidget);
1824-
/// expect(find.byTooltip(RegExp('Back.*')), findsNWidgets(2));
1825-
/// ```
1826-
///
1827-
/// If the `skipOffstage` argument is true (the default), then this skips
1828-
/// nodes that are [Offstage] or that are from inactive [Route]s.
1829-
///
1830-
/// This was copied from flutter_test, which uses flutter/material.dart.
1831-
// TODO(justinmc): Port flutter_test to material_ui, then delete this method and
1832-
// use that one.
1833-
Finder _findByTooltip(Pattern message, {bool skipOffstage = true}) {
1834-
return find.byWidgetPredicate((Widget widget) {
1835-
// Compare RawTooltip's semantics tooltip with the given message.
1836-
// However, Tooltip's message needs to be checked directly if:
1837-
// 1. Tooltip.excludeFromSemantics is true, since in this case Tooltip
1838-
// provides no semantics tooltip to the underlying RawTooltip.
1839-
// 2. Tooltip.message and Tooltip.richMessage are empty, since in this
1840-
// case no RawTooltip is created.
1841-
if (widget is Tooltip) {
1842-
//if (widget.runtimeType == 'Tooltip') {
1843-
final String tooltipMessage = widget.message ?? widget.richMessage!.toPlainText();
1844-
if ((widget.excludeFromSemantics ?? false) || tooltipMessage.isEmpty) {
1845-
return message is RegExp ? message.hasMatch(tooltipMessage) : tooltipMessage == message;
1846-
}
1847-
}
1848-
return widget is RawTooltip &&
1849-
(message is RegExp
1850-
? message.hasMatch(widget.semanticsTooltip ?? '')
1851-
: widget.semanticsTooltip == message);
1852-
}, skipOffstage: skipOffstage);
1853-
}

0 commit comments

Comments
 (0)