Remove Material Dependency from semantics_debugger_test#181722
Remove Material Dependency from semantics_debugger_test#181722rizwan-saleem wants to merge 12 commits into
semantics_debugger_test#181722Conversation
This change refactors `semantics_debugger_test.dart` to eliminate its dependency on **Material** widgets, as part of the test reorganization effort to ensure tests only depend on the library code they are testing. --- ## Changes - Replace `Material` import with `widgets` import in `semantics_debugger_test.dart` - Replace `ElevatedButton` with `TestButton` (2 tests) - Replace `Slider` with `TestSlider` (1 test) - Replace `Checkbox` with `TestCheckbox` (2 tests) - Replace `TextField` with `TestTextField` (1 test) - Replace `MaterialApp` with `TestWidgetsApp` (2 tests) - Remove `Material` wrapper widgets throughout tests - Replace `Colors` constants with explicit `Color` values --- ## New Test Widgets Created ### `TestSlider` A minimal slider with semantics support for testing. - Implements `onIncrease` / `onDecrease` semantic actions - Supports min/max range and divisions - Uses a **10% adjustment unit** for continuous sliders ### `TestCheckbox` A minimal checkbox with semantics support for testing. - Implements checked state and `onTap` semantic action - Supports enabled and disabled states --- ## Enhanced Existing Test Widget ### `TestTextField` Updated to better match the Material `TextField` semantics structure. - Added a `Semantics` wrapper - Provides enabled state and `onTap` action - Allows tests to find `Semantics` descendants as expected --- ## Test Results All **21 tests pass** successfully with the new test widget
There was a problem hiding this comment.
Code Review
This pull request successfully refactors semantics_debugger_test.dart to eliminate its dependency on Material widgets, which is a great improvement for test modularity. The introduction of minimal test widgets like TestSlider and TestCheckbox is well-executed. My review includes a few suggestions to simplify the implementation of these new test widgets by removing some redundant null checks, which will improve code conciseness.
|
@justinmc can you please review the changes in the PR to eliminate its dependency on Material widgets ? |
justinmc
left a comment
There was a problem hiding this comment.
Thanks for jumping in and helping here! This wasn't a super easy one but I think you just about got it.
| showCursor: widget.showCursor, | ||
| style: widget.style ?? const TextStyle(), // required by editable text. | ||
| controller: _effectiveController, // required by editable text. | ||
| return Semantics( |
There was a problem hiding this comment.
Are you able to do this via EditableText which has a Semantics inside of it? @Renzo-Olivares I wonder what you think about this.
There was a problem hiding this comment.
@Renzo-Olivares pointed out to me that EditableText actually does not have onTap in its Semantics:
flutter/packages/flutter/lib/src/widgets/editable_text.dart
Lines 5800 to 5805 in 018a571
That is handled in TextField and in CupertinoTextField. We should probably move that semantics logic to EditableText, but after this PR. I'll create an issue.
In the meantime, I think we should move the test "SemanticsDebugger textfield" to material, and keep TestTextField as-is.
There was a problem hiding this comment.
Issue: #181873
@rizwan-saleem When you move the test to Material, please add a TODO that references this issue.
| /// This widget provides minimal slider functionality without depending on | ||
| /// Material Design components. It only handles semantic actions for testing | ||
| /// purposes and does not render any visual elements. | ||
| class TestSlider extends StatelessWidget { |
There was a problem hiding this comment.
Can you add a TODO like this for each of these two new Test classes you wrote?
flutter/packages/flutter/test/widgets/widgets_app_tester.dart
Lines 34 to 35 in 9b30164
There was a problem hiding this comment.
Also, I think we should move these classes to their own files, like slider_tester.dart and checkbox_tester.dart. I should probably move TestButton in another PR too, sorry for the misleading example here.
CC @Renzo-Olivares for thoughts.
| 2000.0, | ||
| warnIfMissed: false, | ||
| ); // hitting the debugger | ||
| switch (defaultTargetPlatform) { |
There was a problem hiding this comment.
This test looks like it's testing some specific platform logic based on this switch. I wonder if we should duplicate it in Material.
There was a problem hiding this comment.
Good catch, yes I would copy the original test to Material and keep the version you have now here.
| Directionality( | ||
| textDirection: TextDirection.ltr, | ||
| child: SemanticsDebugger( | ||
| child: Material( |
There was a problem hiding this comment.
I think this test might also be a good candidate to duplicate or outright move to Material since it seems to be specifically testing Checkbox and not just the general functionality.
Unlike SemanticsDebugger interaction test earlier in this file which uses the buttons as a means to add logs to a list, this is testing the Checkbox functionality.
| textDirection: TextDirection.ltr, | ||
| child: SemanticsDebugger( | ||
| key: debugger, | ||
| child: Material( |
There was a problem hiding this comment.
|
Thank you @justinmc @Renzo-Olivares for all the valuable comments on the PR. It really helped to understand how things need to be done for other cross import files too. I will tag you guys again once I have made the changes. 🙏 |
…" (#182406) <!-- start_original_pr_link --> Reverts: #182395 <!-- end_original_pr_link --> <!-- start_initiating_author --> Initiated by: gaaclarke <!-- end_initiating_author --> <!-- start_revert_reason --> Reason for reverting: this is causing breakages on the dashboard example: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8689933991528003217/+/u/run_test.dart_for_framework_tests_shard_and_subshard_libraries/stdout ``` 10:36 +9458 ~24: /b/s/w/ir/x/w/flutter/packages/flutter/test/material/dialog_test.dart: Dialog children padding is correct AlertDialog padding is correct when only icon, title a <!-- end_revert_reason --> <!-- start_original_pr_author --> Original PR Author: justinmc <!-- end_original_pr_author --> <!-- start_reviewers --> Reviewed By: {Renzo-Olivares, victorsanni, navaronbracke} <!-- end_reviewers --> <!-- start_revert_body --> This change reverts the following previous change: This PR moves: * TestTextField from editable_text_utils.dart to editable_text_tester.dart * TestListTile from list_tile_test_utils.dart to list_tile_tester.dart * TestButton from utils.dart to button_tester.dart The purpose is to align with other Test* widgets, such as TestWidgetsApp in [widgets_app_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/widgets_app_tester.dart) and TestSemantics in [semantics_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/semantics_tester.dart). We should continue to follow this pattern in the future, such as in #181722. <!-- end_revert_body --> Co-authored-by: auto-submit[bot] <[email protected]>
…#182395)" (flutter#182406) <!-- start_original_pr_link --> Reverts: flutter#182395 <!-- end_original_pr_link --> <!-- start_initiating_author --> Initiated by: gaaclarke <!-- end_initiating_author --> <!-- start_revert_reason --> Reason for reverting: this is causing breakages on the dashboard example: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8689933991528003217/+/u/run_test.dart_for_framework_tests_shard_and_subshard_libraries/stdout ``` 10:36 +9458 ~24: /b/s/w/ir/x/w/flutter/packages/flutter/test/material/dialog_test.dart: Dialog children padding is correct AlertDialog padding is correct when only icon, title a <!-- end_revert_reason --> <!-- start_original_pr_author --> Original PR Author: justinmc <!-- end_original_pr_author --> <!-- start_reviewers --> Reviewed By: {Renzo-Olivares, victorsanni, navaronbracke} <!-- end_reviewers --> <!-- start_revert_body --> This change reverts the following previous change: This PR moves: * TestTextField from editable_text_utils.dart to editable_text_tester.dart * TestListTile from list_tile_test_utils.dart to list_tile_tester.dart * TestButton from utils.dart to button_tester.dart The purpose is to align with other Test* widgets, such as TestWidgetsApp in [widgets_app_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/widgets_app_tester.dart) and TestSemantics in [semantics_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/semantics_tester.dart). We should continue to follow this pattern in the future, such as in flutter#181722. <!-- end_revert_body --> Co-authored-by: auto-submit[bot] <[email protected]>
|
Hi @rizwan-saleem, just checking in on how it's going with this pull request. Let me know if you have any questions, happy to help! |
| // TODO(rizwan-saleem): Move this to material package. | ||
| // Tracking issue: https://github.com/flutter/flutter/issues/177414 |
There was a problem hiding this comment.
Was this added by mistake or am I misunderstanding? Seems like this file is in the right spot.
There was a problem hiding this comment.
I think maybe you misread my comment (#181722 (comment)). I meant that you should move this test into test/material/semantics_debugger_test.dart, and then add a comment with a TODO linking to #181873.
I think this test is fundamentally testing logic that is currently inside of TextField in the Material library, so the test should go in the Material library tool.
|
@rizwan-saleem Are you still planning to return to this PR and get it ready to merge? |
|
@justinmc sorry for the delay, I am on it, finishing the work this weekend |
# Conflicts: # dev/bots/check_tests_cross_imports.dart # packages/flutter/test/widgets/editable_text_utils.dart
The `SemanticsDebugger` tests for `Slider`, `Checkbox`, and `TextField` have been moved from the `widgets` package to the `material` package. This change ensures that tests for Material-specific implementations of these widgets are located alongside their respective package.
…#182395)" (flutter#182406) <!-- start_original_pr_link --> Reverts: flutter#182395 <!-- end_original_pr_link --> <!-- start_initiating_author --> Initiated by: gaaclarke <!-- end_initiating_author --> <!-- start_revert_reason --> Reason for reverting: this is causing breakages on the dashboard example: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8689933991528003217/+/u/run_test.dart_for_framework_tests_shard_and_subshard_libraries/stdout ``` 10:36 +9458 ~24: /b/s/w/ir/x/w/flutter/packages/flutter/test/material/dialog_test.dart: Dialog children padding is correct AlertDialog padding is correct when only icon, title a <!-- end_revert_reason --> <!-- start_original_pr_author --> Original PR Author: justinmc <!-- end_original_pr_author --> <!-- start_reviewers --> Reviewed By: {Renzo-Olivares, victorsanni, navaronbracke} <!-- end_reviewers --> <!-- start_revert_body --> This change reverts the following previous change: This PR moves: * TestTextField from editable_text_utils.dart to editable_text_tester.dart * TestListTile from list_tile_test_utils.dart to list_tile_tester.dart * TestButton from utils.dart to button_tester.dart The purpose is to align with other Test* widgets, such as TestWidgetsApp in [widgets_app_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/widgets_app_tester.dart) and TestSemantics in [semantics_tester.dart](https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/semantics_tester.dart). We should continue to follow this pattern in the future, such as in flutter#181722. <!-- end_revert_body --> Co-authored-by: auto-submit[bot] <[email protected]>
|
Here's a reminder that there are still analyzer issues. (from triage) |
# Conflicts: # dev/bots/check_tests_cross_imports.dart # packages/flutter/test/widgets/checkbox_tester.dart # packages/flutter/test/widgets/semantics_debugger_test.dart
|
All comments addressed. Code freeze check is there |
|
Closing this PR, as semantics_debugger_test is handled in another PR. |
This change refactors
semantics_debugger_test.dartto eliminate its dependency on Material widgets, as part of the test reorganization effort to ensure tests only depend on the library code they are testing.Changes
Materialimport withwidgetsimport insemantics_debugger_test.dartElevatedButtonwithTestButton(2 tests)SliderwithTestSlider(1 test)CheckboxwithTestCheckbox(2 tests)TextFieldwithTestTextField(1 test)MaterialAppwithTestWidgetsApp(2 tests)Materialwrapper widgets throughout testsColorsconstants with explicitColorvaluesNew Test Widgets Created
TestSliderA minimal slider with semantics support for testing.
onIncrease/onDecreasesemantic actionsTestCheckboxA minimal checkbox with semantics support for testing.
onTapsemantic actionEnhanced Existing Test Widget
TestTextFieldUpdated to better match the Material
TextFieldsemantics structure.SemanticswrapperonTapactionSemanticsdescendants as expectedTest Results
All 21 tests pass successfully with the new test widget
Part of #177414
Pre-launch Checklist
///).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. Comments from the
gemini-code-assistbot 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.