Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a basic golden test for CupertinoTextSelectionToolbar #135267

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions packages/flutter/test/cupertino/text_selection_toolbar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])
library;

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -493,4 +498,51 @@ void main() {
),
);
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.

testWidgetsWithLeakTracking('Basic golden tests', (WidgetTester tester) async {
final Key key = UniqueKey();
Widget buildToolbar(Brightness brightness, Offset offset) {
final Widget toolbar = CupertinoTextSelectionToolbar(
anchorAbove: offset,
anchorBelow: offset,
children: <Widget>[
CupertinoTextSelectionToolbarButton.text(onPressed: () {}, text: 'Lorem ipsum'),
CupertinoTextSelectionToolbarButton.text(onPressed: () {}, text: 'dolor sit amet'),
CupertinoTextSelectionToolbarButton.text(onPressed: () {}, text: 'Lorem ipsum \ndolor sit amet'),
CupertinoTextSelectionToolbarButton.buttonItem(buttonItem: ContextMenuButtonItem(onPressed: () {}, type: ContextMenuButtonType.copy)),
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw in a CupertinoTextSelectionToolbarButton.buttonItem maybe as it's the other button type used on iOS?

);
return CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: Center(
child: SizedBox(
height: 200,
child: RepaintBoundary(key: key, child: toolbar),
),
),
);
}

// The String describes the location of the toolbar in relation to the
// content the arrow points to.
const List<(String, Offset)> toolbarLocation = <(String, Offset)>[
('BottomRight', Offset.zero),
('BottomLeft', Offset(100000, 0)),
('TopRight', Offset(0, 100)),
('TopLeft', Offset(100000, 100)),
];

debugDisableShadows = false;
addTearDown(() => debugDisableShadows = true);
for (final Brightness brightness in Brightness.values) {
for (final (String location, Offset offset) in toolbarLocation) {
await tester.pumpWidget(buildToolbar(brightness, offset));
await expectLater(
find.byKey(key),
matchesGoldenFile('cupertino_selection_toolbar.$location.$brightness.png'),
);
}
}
debugDisableShadows = true;
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
}