Skip to content

feat(material-experimental): add test harness for radio-group #16609

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

Conversation

devversion
Copy link
Member

Follow-up for 583af19. This PR introduces a new test
harness for the mat-radio-group implementation.

Note that we can't provide harness methods for getting the selected
value because the selected value or the value of a radio-button are
part of the component-internal state (no way to determine from DOM)

@devversion devversion added pr: merge safe target: patch This PR is targeted for the next patch release labels Jul 25, 2019
@devversion devversion requested a review from mmalerba as a code owner July 25, 2019 17:37
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 25, 2019
@devversion devversion force-pushed the feat/experimental-radio-group-harness branch from 9fd3e0c to 3903848 Compare July 29, 2019 08:25
@@ -6,6 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/

export type RadioGroupHarnessFilters = {
Copy link
Contributor

Choose a reason for hiding this comment

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

It kind of feels like id and name should just be things you can do with normal selectors and shouldn't need a special filter option, e.g.

const myIdLoader = await loader.getChildLoader('#my-id')
const harness = myIdLoader.getHarness(RadioGroupHarness);

There is a problem with this currently though, which is that getHarness searches for the harness on an element under the root of the loader. So if my-id is the id of your radio group, it won't check that element, just the ones under it. Maybe getHarness should check the given element and anything under it? That would eliminate the need for these filters I think

Copy link
Member Author

@devversion devversion Jul 29, 2019

Choose a reason for hiding this comment

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

For this case it is a bit more special though because the name or id is not necessarily set on the radio-group or radio-button element, but rather on the underlying input.

So if someone queries a radio-group by name, we check if it has a DOM attribute or find the right group by respecting the name attribute for child radio-buttons in groups.

Another pain point here is that if someone sets the radio-group name through an input binding, the name attribute will not be set. There is no host-binding for that. That's why we need to respect the inputs of child radio-button's.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see that's a good point, I wonder if I should add similar ones for checkbox. It will probably have the same issue if people want to search by name...

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I will double-check on that and make a note.

Follow-up for 583af19. This commit
introduces a new test harness for the `mat-radio-group` implementation.

Note that we can't provide harness methods for getting the selected
value because the selected value or the value of a radio-button are
part of the component-internal state (no way to determine from DOM)
Currently a `mat-radio-button` does not respect the value binding that has
been set on the radio-button.

This is not ideal because in most cases the value is a primitive that can
be set as `value` for the underlying input element in order to ensure that
proper `FormData` can be retrieved when the form gets submitted.

Currently the form data will always have `on` as value because the selected
radio-button does not pass-through the value to the underlying input.
@devversion devversion force-pushed the feat/experimental-radio-group-harness branch from 3903848 to 6aa4ac2 Compare July 29, 2019 17:02
@devversion devversion added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Jul 29, 2019
@devversion
Copy link
Member Author

Caretaker note: we should preserve both commits in this PR.. as one commit changes the radio-button template to properly pass-through the value binding.

@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: merge safe labels Jul 29, 2019
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

devversion added a commit to devversion/material2 that referenced this pull request Aug 1, 2019
…by name

Adds an option to the checkbox harnesses that allows developers
to filter harnesses by checkbox names. This is helpful because
developers can not filter checkboxes by name using CSS selectors
because the `name` input binding is not bound to the host DOM element.

Similar to angular#16609 (comment)
devversion added a commit to devversion/material2 that referenced this pull request Aug 1, 2019
…by name

Adds an option to the checkbox harnesses that allows developers
to filter harnesses by checkbox names. This is helpful because
developers can not filter checkboxes by name using CSS selectors
because the `name` input binding is not bound to the host DOM element.

Similar to angular#16609 (comment)
devversion added a commit to devversion/material2 that referenced this pull request Aug 1, 2019
…by name

Adds an option to the checkbox harnesses that allows developers
to filter harnesses by checkbox names. This is helpful because
developers can not filter checkboxes by name using CSS selectors
because the `name` input binding is not bound to the host DOM element.

Similar to angular#16609 (comment)
devversion added a commit to devversion/material2 that referenced this pull request Aug 13, 2019
…by name

Adds an option to the checkbox harnesses that allows developers
to filter harnesses by checkbox names. This is helpful because
developers can not filter checkboxes by name using CSS selectors
because the `name` input binding is not bound to the host DOM element.

Similar to angular#16609 (comment)
mmalerba pushed a commit that referenced this pull request Aug 13, 2019
Adds an option to the checkbox harnesses that allows developers
to filter harnesses by checkbox names. This is helpful because
developers can not filter checkboxes by name using CSS selectors
because the `name` input binding is not bound to the host DOM element.

Similar to #16609 (comment)
mmalerba pushed a commit that referenced this pull request Aug 14, 2019
Adds an option to the checkbox harnesses that allows developers
to filter harnesses by checkbox names. This is helpful because
developers can not filter checkboxes by name using CSS selectors
because the `name` input binding is not bound to the host DOM element.

Similar to #16609 (comment)

(cherry picked from commit 2cbabf0)
@andrewseguin andrewseguin merged commit bd3bf09 into angular:master Aug 21, 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 Sep 21, 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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants