refactor: remove material import froma sliver_main_axis_group_test, sliver_semantics_test, semantics_role_checks_test, sliver_fill_remaining_test, tap_region_test#185567
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors several widget tests to eliminate dependencies on the Material library, replacing components like MaterialApp, Scaffold, and SliverAppBar with TestWidgetsApp and custom SliverPersistentHeader implementations. It also replaces Material-specific widgets such as ElevatedButton and Radio with basic widgets or test-specific wrappers like TestButton and RawRadio. Feedback identifies several opportunities to further optimize the code by using ColoredBox instead of Container when only a background color is required.
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; |
There was a problem hiding this comment.
@rkishan516 Nice to see that you're trying to tackle this test.
I do have some feedback on this specific one, though.
IIRC the last time I looked at it, there were some issues:
- There is also
sliversemantics_test.dart
I don't recall if that test had duplicated stuff between itself and sliver_semantics_test.dart - Both of these test files do get large (especially if you consider them both)
We should split these tests off into sliver_semantics_1_test.dart etc. Smaller test files are easier to post to the test runner, too - I think there was some usage of group(), together with a
_testFoo()helper method, both seemed redundant (why not put the body of that method in void main() ?)
There was a problem hiding this comment.
Hey, sure. I think sliversemantics_test.dart and sliver_semantics_test.dart have different scope. Will try to migrate that also.
I think there was some usage of group(), together with a _testFoo() helper method, both seemed redundant (why not put the body of that method in void main() ?)
Yes, this pattern still exist, we can drop group() + _tests() indirection.
There was a problem hiding this comment.
nvm, that was already migrated.
There was a problem hiding this comment.
I agree about the 3 points above. Possibly could be done in another PR though.
@Renzo-Olivares Do you know the history of sliver_semantics_test.dart and sliversemantics_test.dart? #167300
There was a problem hiding this comment.
sliversemantics_test.dart tests the recent SliverSemantics widget which is a Sliver variant of the Semantics widget. It is essentially a duplicate of semantics_test.dart but for SliverSemantics.
Not as familiar with sliver_semantics_test.dart, but generally it just holds different integration tests for semantics and sliver components.
sliversemantics_test.dart and sliver_semantics_test.dart are definitely different in scope and should not be considered the same.
I'm not against splitting these files up, but it should be clear what the file is testing.
There was a problem hiding this comment.
I can do a follow up MR with proper naming and split.
a14852a to
743ebf2
Compare
| 'SliverAppBar with floating: true, pinned: true, snap: true is painted within bounds of SliverMainAxisGroup', | ||
| 'SliverPersistentHeader with floating: true, pinned: true, snap: true is painted within bounds of SliverMainAxisGroup', |
There was a problem hiding this comment.
It looks like there's no reason to duplicate these SliverAppBar tests in Material, right? I guess it wouldn't test anything that these are not already testing at the widgets level.
There was a problem hiding this comment.
Yup, we don't need in Material.
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; |
There was a problem hiding this comment.
I agree about the 3 points above. Possibly could be done in another PR though.
@Renzo-Olivares Do you know the history of sliver_semantics_test.dart and sliversemantics_test.dart? #167300
9006266 to
89cc75a
Compare
victorsanni
left a comment
There was a problem hiding this comment.
LGTM with some nits.
| // Push the second page so tapRegion2 is on top of tapRegion1. | ||
| Navigator.of(tester.element(find.byKey(tapRegion1Key))).pushNamed('/second'); |
There was a problem hiding this comment.
Why do we need to do this?
There was a problem hiding this comment.
We want second page to be on top when doing tap outside assertion.
There was a problem hiding this comment.
SGTM. Previously this was done in onGenerateInitialRoutes.
| }, | ||
| child: Container(width: 250.0, height: 250.0, color: Colors.blue), | ||
| ), | ||
| ).createRoute(context), |
There was a problem hiding this comment.
Since we are using TestPage, to createPageRouteBuilder we are calling this.
89cc75a to
3a0b1e2
Compare
3a0b1e2 to
1238b57
Compare
1238b57 to
56ae0e5
Compare
…liver_semantics_test, semantics_role_checks_test, sliver_fill_remaining_test, tap_region_test
… based on feedback
| // Push the second page so tapRegion2 is on top of tapRegion1. | ||
| Navigator.of(tester.element(find.byKey(tapRegion1Key))).pushNamed('/second'); |
There was a problem hiding this comment.
SGTM. Previously this was done in onGenerateInitialRoutes.
Master (flutter#185567) already merged the move/refactor of TapRegion navigation tests off Material. This merge adopts that version of test/widgets/tap_region_test.dart and re-applies the small robustness improvement on top: * Replace the two duplicated `Future<void> tapOutside(...)` local closures with a single top-level `_tapOutside(tester, regionKey)` helper that locates the visible region's RenderBox dynamically (renderBox.localToGlobal(Offset.zero) + Offset(200, 200)) instead of using a hardcoded global coordinate. This addresses @justinmc's review feedback that the original material/-based tapOutside was more robust than the closure with hardcoded coords.
This PR is follow up to flutter#185567 (comment) conversation where we want to properly name and split test files. part of: flutter#177415 # Current Status - Renamed `sliversemantics_test.dart` to `sliver_semantics_widget_test.dart` ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Renzo Olivares <rmolivares@renzo-olivares.dev>
This PR removes Material imports from
part of: #177415
Pre-launch Checklist
///).