-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
src/material-experimental/form-field/testing/form-field-harness.ts
Outdated
Show resolved
Hide resolved
2cec4d3
to
205f500
Compare
205f500
to
97eb522
Compare
97eb522
to
6d0da76
Compare
src/material-experimental/form-field/testing/form-field-harness.ts
Outdated
Show resolved
Hide resolved
} else if (isWarn) { | ||
return 'warn'; | ||
} | ||
return 'primary'; |
There was a problem hiding this comment.
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';
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
src/material-experimental/form-field/testing/form-field-harness.spec.ts
Outdated
Show resolved
Hide resolved
src/material-experimental/form-field/testing/form-field-harness.ts
Outdated
Show resolved
Hide resolved
7d7d7b0
to
f864665
Compare
* 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 {} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
src/material-experimental/form-field/testing/form-field-harness.ts
Outdated
Show resolved
Hide resolved
} else if (isWarn) { | ||
return 'warn'; | ||
} | ||
return 'primary'; |
There was a problem hiding this comment.
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
f864665
to
d675652
Compare
d675652
to
f1503c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(cherry picked from commit 7464d4b)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.