Remove trivial test utility cross-imports from material and cupertino…#184295
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces several new test utility files and relocates existing ones within the packages/flutter/test directory to improve test organization. Specifically, it adds list_tile_tester.dart, process_text_utils.dart, sliver_test_utils.dart, and test_border.dart, while updating relevant import statements in existing test files. Review feedback highlights multiple instances where new public members—including classes, constants, and fields—lack the documentation required by the repository's style guide.
victorsanni
left a comment
There was a problem hiding this comment.
Should these duplicated classes have duplicated tests as well?
| /// A minimal ListTile widget for testing purposes to avoid relying on | ||
| /// widgets from material.dart. |
There was a problem hiding this comment.
| /// A minimal ListTile widget for testing purposes to avoid relying on | |
| /// widgets from material.dart. | |
| /// A minimal ListTile widget for testing purposes. |
There was a problem hiding this comment.
Isn't ListTile a Material widget? Should the equivalent in Cupertino be based on CupertinoListTile instead?
There was a problem hiding this comment.
Done, simplified the doc comment. Thank you!
There was a problem hiding this comment.
Good question! TestListTile is not actually a Material ListTile — it is a minimal widget (only depends on package:flutter/widgets.dart) that was created specifically as a lightweight tap target for semantics testing (see #177415). The test here checks MergeSemantics + CupertinoSwitch behavior, not list tile behavior itself.
Replacing it with CupertinoListTile would introduce a heavier StatefulWidget with animations and background color changes, which could make this unrelated semantics test more fragile. So I think keeping the minimal TestListTile is the safer choice here.
There was a problem hiding this comment.
I think you should replace the words "ListTile" with "CupertinoListTile" here in the docs, even though it's not based on either. That's what this class should be approximating here in Cupertino.
|
Hi @xfce0, this PR is currently targeting |
d7b7f4b to
55060f9
Compare
|
Done, retargeted to |
|
Rebased onto the latest master. |
55060f9 to
0973b99
Compare
justinmc
left a comment
There was a problem hiding this comment.
LGTM with a nit about saying "CupertinoListTile" instead of "ListTile".
|
This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled. |
07afa50 to
d0e7dcc
Compare
justinmc
left a comment
There was a problem hiding this comment.
LGTM 👍 . Thanks for adding all of the docs even though they didn't exist before.
|
|
||
| import 'package:flutter/widgets.dart'; | ||
|
|
||
| /// A minimal CupertinoListTile widget for testing purposes. |
There was a problem hiding this comment.
Nit: Link [CupertinoListTile].
|
@xfce0 Heads up there is an analyzer failure. |
|
Thanks for the work here. This PR is blocked by the Material/Cupertino code freeze: #184093. I will convert it to a draft to take it off our review queue, and when the code freeze is over, find a way to port it to the new packages. Thanks once again! |
|
Actually @justinmc just let me know we will be able to land this with an exception label. So we can go ahead here. |
There was a problem hiding this comment.
Code Review
This pull request adds TestListTile, MockProcessTextHandler, and TestBorder testing utilities and updates related imports across several test files. Feedback recommends using Dart 3 pattern matching in MockProcessTextHandler for safer argument extraction and adding logging to the scale method in TestBorder to maintain consistency with other methods.
| final args = call.arguments as List<dynamic>; | ||
| final actionId = args[0] as String; | ||
| final textToProcess = args[1] as String; | ||
| lastCalledActionId = actionId; | ||
| lastTextToProcess = textToProcess; | ||
|
|
||
| if (actionId == fakeAction1Id) { | ||
| // Simulates an action that returns a transformed text. | ||
| return '$textToProcess!!!'; | ||
| } | ||
| // Simulates an action that failed or does not transform text. | ||
| return null; |
There was a problem hiding this comment.
The current implementation uses unsafe casts which could throw a TypeError or RangeError if the MethodCall arguments do not match the expected structure. Using Dart 3 pattern matching provides a more robust and readable way to extract these arguments, adhering to the principle of optimizing for readability.
| final args = call.arguments as List<dynamic>; | |
| final actionId = args[0] as String; | |
| final textToProcess = args[1] as String; | |
| lastCalledActionId = actionId; | |
| lastTextToProcess = textToProcess; | |
| if (actionId == fakeAction1Id) { | |
| // Simulates an action that returns a transformed text. | |
| return '$textToProcess!!!'; | |
| } | |
| // Simulates an action that failed or does not transform text. | |
| return null; | |
| if (call.arguments case [final String actionId, final String textToProcess]) { | |
| lastCalledActionId = actionId; | |
| lastTextToProcess = textToProcess; | |
| if (actionId == fakeAction1Id) { | |
| // Simulates an action that returns a transformed text. | |
| return '$textToProcess!!!'; | |
| } | |
| } | |
| // Simulates an action that failed or does not transform text. | |
| return null; |
References
- Optimize for readability: Code is read more often than it is written. (link)
| EdgeInsetsGeometry get dimensions => const EdgeInsetsDirectional.only(start: 1.0); | ||
|
|
||
| @override | ||
| ShapeBorder scale(double t) => TestBorder(onLog); |
There was a problem hiding this comment.
To be consistent with other methods in TestBorder (like getInnerPath, getOuterPath, and paint), the scale method should log its call. This ensures that tests can verify if the border was scaled as expected, following the principle of doing things right when they are written.
ShapeBorder scale(double t) {
onLog('scale $t');
return TestBorder(onLog);
}References
- Write what you need and no more, but when you write it, do it right. (link)
|
autosubmit label was removed for flutter/flutter/184295, because - The status or check suite Check Code Freeze has failed. Please fix the issues identified (or deflake) before re-applying this label. |
ed7a6e2 to
0cad5d4
Compare
Removes cross-directory test imports of four trivial test utilities from material and cupertino tests.
Part of #182636.
All four utilities are small (20-40 lines) with trivial implementations, so duplication is the appropriate strategy per the issue guidelines:
test_border.dart(36 lines) →test/material/(1 file updated)sliver_test_utils.dart(20 lines) →test/material/(1 file updated)process_text_utils.dart(40 lines) →test/material/(2 files updated)list_tile_tester.dart(30 lines) →test/cupertino/(1 file updated)Pre-launch Checklist
///).