Skip to content

Commit ef9b66c

Browse files
authored
[cupertino_ui] Create util files. Remove widgets import in adaptive_text_selection_toolbar_test.dart and text_selection_test.dart (#12023)
Part of flutter/flutter#182636 and flutter/flutter#188395 This PR: * Removed the cross-import of `widgets/clipboard_utils.dart` and `widgets/text_selection_toolbar_utils.dart`. * Removed @Skip tag, all tests in this file has passed. Created util files for `clipboard_utils.dart` and `text_selection_toolbar_utils.dart` * Moved the files to `test/` folder. This is to port changes in flutter/flutter#184278 ## Pre-Review Checklist
1 parent e727677 commit ef9b66c

4 files changed

Lines changed: 58 additions & 9 deletions

File tree

packages/cupertino_ui/temporarily_disabled_tests/adaptive_text_selection_toolbar_test.dart renamed to packages/cupertino_ui/test/adaptive_text_selection_toolbar_test.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
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
import 'package:cupertino_ui/cupertino_ui.dart';
96
import 'package:flutter/foundation.dart';
107
import 'package:flutter/services.dart';
118
import 'package:flutter_test/flutter_test.dart';
129

13-
import '../widgets/clipboard_utils.dart';
14-
import '../widgets/text_selection_toolbar_utils.dart';
10+
import 'clipboard_utils.dart';
1511
import 'live_text_utils.dart';
12+
import 'text_selection_toolbar_utils.dart';
1613

1714
void main() {
1815
final mockClipboard = MockClipboard();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
7+
class MockClipboard {
8+
MockClipboard({this.hasStringsThrows = false});
9+
10+
final bool hasStringsThrows;
11+
12+
dynamic clipboardData = <String, dynamic>{'text': null};
13+
14+
Future<Object?> handleMethodCall(MethodCall methodCall) async {
15+
switch (methodCall.method) {
16+
case 'Clipboard.getData':
17+
return clipboardData;
18+
case 'Clipboard.hasStrings':
19+
if (hasStringsThrows) {
20+
throw Exception();
21+
}
22+
final clipboardDataMap = clipboardData as Map<String, dynamic>?;
23+
final text = clipboardDataMap?['text'] as String?;
24+
return <String, bool>{'value': text != null && text.isNotEmpty};
25+
case 'Clipboard.setData':
26+
clipboardData = methodCall.arguments;
27+
}
28+
return null;
29+
}
30+
}

packages/cupertino_ui/temporarily_disabled_tests/text_selection_test.dart renamed to packages/cupertino_ui/test/text_selection_test.dart

Lines changed: 1 addition & 4 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'])
@@ -18,7 +15,7 @@ import 'package:flutter/rendering.dart';
1815
import 'package:flutter/services.dart';
1916
import 'package:flutter_test/flutter_test.dart';
2017

21-
import '../widgets/clipboard_utils.dart';
18+
import 'clipboard_utils.dart';
2219
import 'editable_text_utils.dart' show findRenderEditable, textOffsetToPosition;
2320

2421
class _LongCupertinoLocalizationsDelegate extends LocalizationsDelegate<CupertinoLocalizations> {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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:cupertino_ui/cupertino_ui.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
8+
Finder findCupertinoOverflowNextButton() {
9+
return find.byWidgetPredicate((Widget widget) {
10+
return widget is CustomPaint &&
11+
'${widget.painter?.runtimeType}' == '_RightCupertinoChevronPainter';
12+
});
13+
}
14+
15+
Finder findCupertinoOverflowBackButton() {
16+
return find.byWidgetPredicate((Widget widget) {
17+
return widget is CustomPaint &&
18+
'${widget.painter?.runtimeType}' == '_LeftCupertinoChevronPainter';
19+
});
20+
}
21+
22+
Future<void> tapCupertinoOverflowNextButton(WidgetTester tester) async {
23+
await tester.tapAt(tester.getCenter(findCupertinoOverflowNextButton()));
24+
await tester.pumpAndSettle();
25+
}

0 commit comments

Comments
 (0)