Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

import 'package:material_ui/material_ui.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';
import 'package:vector_math/vector_math_64.dart' show Vector3;

import '../widgets/feedback_tester.dart';
import '../widgets/semantics_tester.dart';
import 'feedback_tester.dart';
import 'finders.dart';
import 'semantics_tester.dart';

void main() {
testWidgets('BottomNavigationBar callback test', (WidgetTester tester) async {
Expand Down Expand Up @@ -1716,15 +1714,15 @@ void main() {

expect(find.text('A'), findsOneWidget);
await tester.longPress(find.text('A'));
expect(find.byTooltip('A tooltip'), findsOneWidget);
expect(findByTooltip('A tooltip'), findsOneWidget);

expect(find.text('B'), findsOneWidget);
await tester.longPress(find.text('B'));
expect(find.byTooltip('B'), findsNothing);
expect(findByTooltip('B'), findsNothing);

expect(find.text('C'), findsOneWidget);
await tester.longPress(find.text('C'));
expect(find.byTooltip('C'), findsNothing);
expect(findByTooltip('C'), findsNothing);
});

testWidgets('BottomNavigationBar limits width of tiles with long labels', (
Expand Down
51 changes: 51 additions & 0 deletions packages/material_ui/test/feedback_tester.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2013 The Flutter Authors
// 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_test/flutter_test.dart';

/// Tracks how often feedback has been requested since its instantiation.
///
/// It replaces the MockMethodCallHandler of [SystemChannels.platform] and
/// cannot be used in combination with other classes that do the same.
class FeedbackTester {
FeedbackTester() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
_handler,
);
}

/// Number of times haptic feedback was requested (vibration).
int get hapticCount => _hapticCount;
int _hapticCount = 0;

/// Number of times the click sound was requested to play.
int get clickSoundCount => _clickSoundCount;
int _clickSoundCount = 0;

Future<void> _handler(MethodCall methodCall) async {
if (methodCall.method == 'HapticFeedback.vibrate') {
_hapticCount++;
}
if (methodCall.method == 'SystemSound.play' &&
methodCall.arguments == SystemSoundType.click.toString()) {
_clickSoundCount++;
}
}

/// Stops tracking.
void dispose() {
assert(
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(
SystemChannels.platform.name,
_handler,
),
);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
);
}
}
43 changes: 43 additions & 0 deletions packages/material_ui/test/finders.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';

/// Finds [RawTooltip] or [Tooltip] widgets with the given `message`.
///
/// ## Sample code
///
/// ```dart
/// expect(find.byTooltip('Back'), findsOneWidget);
/// expect(find.byTooltip(RegExp('Back.*')), findsNWidgets(2));
/// ```
///
/// If the `skipOffstage` argument is true (the default), then this skips
/// nodes that are [Offstage] or that are from inactive [Route]s.
///
/// This was copied from flutter_test, which uses flutter/material.dart.
///
// TODO(justinmc): Port flutter_test to material_ui, then delete this method and
// use that one. See https://github.com/flutter/flutter/issues/186966
Finder findByTooltip(Pattern message, {bool skipOffstage = true}) {
return find.byWidgetPredicate((Widget widget) {
// Compare RawTooltip's semantics tooltip with the given message.
// However, Tooltip's message needs to be checked directly if:
// 1. Tooltip.excludeFromSemantics is true, since in this case Tooltip
// provides no semantics tooltip to the underlying RawTooltip.
// 2. Tooltip.message and Tooltip.richMessage are empty, since in this
// case no RawTooltip is created.
if (widget is Tooltip) {
final String tooltipMessage = widget.message ?? widget.richMessage!.toPlainText();
if ((widget.excludeFromSemantics ?? false) || tooltipMessage.isEmpty) {
Comment thread
elliette marked this conversation as resolved.
return message is RegExp ? message.hasMatch(tooltipMessage) : tooltipMessage == message;
}
}
return widget is RawTooltip &&
(message is RegExp
? message.hasMatch(widget.semanticsTooltip ?? '')
: widget.semanticsTooltip == message);
}, skipOffstage: skipOffstage);
}
44 changes: 4 additions & 40 deletions packages/material_ui/test/navigation_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:material_ui/material_ui.dart';
import 'finders.dart';

void main() {
testWidgets('Navigation bar updates destinations when tapped', (WidgetTester tester) async {
Expand Down Expand Up @@ -440,15 +441,15 @@ void main() {

expect(find.text('A'), findsOneWidget);
await tester.longPress(find.text('A'));
expect(_findByTooltip('A tooltip'), findsOneWidget);
expect(findByTooltip('A tooltip'), findsOneWidget);

expect(find.text('B'), findsOneWidget);
await tester.longPress(find.text('B'));
expect(_findByTooltip('B'), findsOneWidget);
expect(findByTooltip('B'), findsOneWidget);

expect(find.text('C'), findsOneWidget);
await tester.longPress(find.text('C'));
expect(_findByTooltip('C'), findsNothing);
expect(findByTooltip('C'), findsNothing);
});

testWidgets('Navigation bar semantics', (WidgetTester tester) async {
Expand Down Expand Up @@ -1814,40 +1815,3 @@ TextStyle _getLabelStyle(WidgetTester tester, String text) {
.text
.style!;
}

/// Finds [RawTooltip] or [Tooltip] widgets with the given `message`.
///
/// ## Sample code
///
/// ```dart
/// expect(find.byTooltip('Back'), findsOneWidget);
/// expect(find.byTooltip(RegExp('Back.*')), findsNWidgets(2));
/// ```
///
/// If the `skipOffstage` argument is true (the default), then this skips
/// nodes that are [Offstage] or that are from inactive [Route]s.
///
/// This was copied from flutter_test, which uses flutter/material.dart.
// TODO(justinmc): Port flutter_test to material_ui, then delete this method and
// use that one.
Finder _findByTooltip(Pattern message, {bool skipOffstage = true}) {
return find.byWidgetPredicate((Widget widget) {
// Compare RawTooltip's semantics tooltip with the given message.
// However, Tooltip's message needs to be checked directly if:
// 1. Tooltip.excludeFromSemantics is true, since in this case Tooltip
// provides no semantics tooltip to the underlying RawTooltip.
// 2. Tooltip.message and Tooltip.richMessage are empty, since in this
// case no RawTooltip is created.
if (widget is Tooltip) {
//if (widget.runtimeType == 'Tooltip') {
final String tooltipMessage = widget.message ?? widget.richMessage!.toPlainText();
if ((widget.excludeFromSemantics ?? false) || tooltipMessage.isEmpty) {
return message is RegExp ? message.hasMatch(tooltipMessage) : tooltipMessage == message;
}
}
return widget is RawTooltip &&
(message is RegExp
? message.hasMatch(widget.semanticsTooltip ?? '')
: widget.semanticsTooltip == message);
}, skipOffstage: skipOffstage);
}
Loading