Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make chip test not depend on child order #94624

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

Merged
merged 1 commit into from
Dec 3, 2021

Conversation

goderbauer
Copy link
Member

@goderbauer goderbauer commented Dec 3, 2021

The current implementation of Chip has a subtle bug where the during initial build the child elements are ordered avatar, deleteIcon, label:

_mountChild(widget.theme.avatar, _ChipSlot.avatar);
_mountChild(widget.theme.deleteIcon, _ChipSlot.deleteIcon);
_mountChild(widget.theme.label, _ChipSlot.label);

During subsequent builds, the order is changed to label, avatar, deleteIcon:

_updateChild(widget.theme.label, _ChipSlot.label);
_updateChild(widget.theme.avatar, _ChipSlot.avatar);
_updateChild(widget.theme.deleteIcon, _ChipSlot.deleteIcon);

However, in chip_test.dart the getLabelStyle method is assuming that the label is always the last child:

DefaultTextStyle getLabelStyle(WidgetTester tester) {
return tester.widget(
find.descendant(
of: find.byType(RawChip),
matching: find.byType(DefaultTextStyle),
).last,
);
}

This is only true after initial build. If a test rebuilds the chip, the label is the middle child and getLabelStyle returns the incorrect style of the deleteIcon. This PR fixes getLabelStyle to no longer rely on the child order of Chip. As it turns out, one of the test cases introduced in #94179 was making incorrect assumptions about the label style because of this bug. That assumption is fixed as well.

The bug was discovered when #94077 unified the child order of first and subsequent builds.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Dec 3, 2021
@google-cla google-cla bot added the cla: yes label Dec 3, 2021
@@ -307,7 +307,7 @@ void main() {
expect(getIconData(tester).color?.value, 0xffffffff);
expect(getIconData(tester).opacity, null);
expect(getIconData(tester).size, null);
expect(getLabelStyle(tester).style.color?.value, 0xffffffff);
expect(getLabelStyle(tester, 'Chip A').style.color?.value, 0xdeffffff);
Copy link
Member Author

Choose a reason for hiding this comment

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

@HansMuller Can you double-check that this is actually what the color should be in this case? It matches what the ChoiceChip already asserts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it's correct.

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -307,7 +307,7 @@ void main() {
expect(getIconData(tester).color?.value, 0xffffffff);
expect(getIconData(tester).opacity, null);
expect(getIconData(tester).size, null);
expect(getLabelStyle(tester).style.color?.value, 0xffffffff);
expect(getLabelStyle(tester, 'Chip A').style.color?.value, 0xdeffffff);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it's correct.

find.descendant(
of: find.byType(RawChip),
find.ancestor(
of: find.text(labelText),
Copy link
Contributor

Choose a reason for hiding this comment

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

NICE

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants