Skip to content

feat(material-experimental): add test harness for form-field #17138

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
Sep 23, 2019

Conversation

devversion
Copy link
Member

No description provided.

@devversion devversion added needs: discussion Further discussion with the team is needed before proceeding pr: merge safe target: patch This PR is targeted for the next patch release labels Sep 18, 2019
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 18, 2019
@devversion devversion force-pushed the feat/harness-form-field branch from 2cec4d3 to 205f500 Compare September 18, 2019 19:25
@devversion devversion requested a review from a team as a code owner September 18, 2019 19:25
@devversion devversion force-pushed the feat/harness-form-field branch from 205f500 to 97eb522 Compare September 18, 2019 20:02
@devversion devversion force-pushed the feat/harness-form-field branch from 97eb522 to 6d0da76 Compare September 18, 2019 20:09
} else if (isWarn) {
return 'warn';
}
return 'primary';
Copy link
Member

Choose a reason for hiding this comment

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

A bit more concise?

const hostClass = await (await this.host()).getAttribute('class');
for (const palette of ['accent', 'warn']) {
  if (hostClass.includes(palette)) {
    return palette;
  }
}

return 'primary';

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll actually keep it like that as otherwise we'd need to handle more things (i.e. spaces to separate classes in the class attribute). The current implementation is quite reasonable but just looks weird due to the Promise all for concurrency.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could maybe use getProperty('classList') for this, now that we have separate methods for attributes and properties

Copy link
Member

Choose a reason for hiding this comment

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

I don't follow what you mean by handing more things. Checking for the absence/presence of "accent" or "warn" is enough, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

My thinking is that class can contain more classes and that just checking using includes is not working 100%. e.g. class attribute could be: custom-mat-accent mat-primary-field.

So we need to ensure that there is a space before/after the class we check for, or that it is at the start/end of the class attribute value. or just split the class attribute by space.. Surely these cases are extremely rare but I don't think there is a benefit in making these things less robust if we can just simply use the public robust hasClass methods.

The current implementation basically checks for existence of the theme classes. It just uses the intended APIs but unfortunately looks kind of dirty (to me at least)

@devversion devversion force-pushed the feat/harness-form-field branch 2 times, most recently from 7d7d7b0 to f864665 Compare September 20, 2019 17:15
@devversion
Copy link
Member Author

@mmalerba @jelbourn Addressed feedback. please have another look.

* Base class for custom form-field control harnesses. Harnesses for
* custom controls with form-fields need to implement this interface.
*/
export interface CustomFormFieldControlHarness extends ComponentHarness {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's call it MatFormFieldControlHarness and have MatInputHarness and MatSelectHarness extend it as well. It might need to go in its own file & build rule to make that work though.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mmalerba done. I had to introduce another nested entry-point so that default controls which are also referenced in the MatFormFieldHarness can import the base control harness without introducing a circular dependency. For public consumers there is no change. They can still import through form-field/testing.

} else if (isWarn) {
return 'warn';
}
return 'primary';
Copy link
Contributor

Choose a reason for hiding this comment

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

You could maybe use getProperty('classList') for this, now that we have separate methods for attributes and properties

@devversion devversion force-pushed the feat/harness-form-field branch from f864665 to d675652 Compare September 23, 2019 10:53
@devversion
Copy link
Member Author

@mmalerba @jelbourn Addressed most of the feedback. The discussion for the getThemeColor is still open. let me know if I should change it or not. I don't feel too strong about it.

@devversion devversion force-pushed the feat/harness-form-field branch from d675652 to f1503c6 Compare September 23, 2019 10:57
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed needs: discussion Further discussion with the team is needed before proceeding labels Sep 23, 2019
@mmalerba mmalerba self-requested a review September 23, 2019 22:50
@jelbourn jelbourn merged commit 7464d4b into angular:master Sep 23, 2019
jelbourn pushed a commit to jelbourn/components that referenced this pull request Sep 24, 2019
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants