Skip to content

feat(material-experimental/mdc-chips): add remove method to MDC chip harness #20831

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
Nov 4, 2020

Conversation

MatteoVH
Copy link
Contributor

This allows MDC chips to be removed in testing environments.

Note that the harness must not only click on the remove button, but also dispatch a transitionend event. Without the dispatch of this event, the chip would not fire it's removed output.

This PR also includes a basic MDC ChipRemoveHarness that mirrors the non-MDC version. This was necessary to find the ChipRemove button in the chip harness' remove method.

@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 19, 2020
@MatteoVH MatteoVH marked this pull request as ready for review October 19, 2020 20:04
@MatteoVH MatteoVH requested a review from mmalerba as a code owner October 19, 2020 20:04
@MatteoVH
Copy link
Contributor Author

This works towards fixing #20826

@jelbourn jelbourn requested a review from crisbeto October 19, 2020 20:14
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.

Could you add a unit test for the remove functionality?

@jelbourn jelbourn added area: material/chips G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround labels Oct 19, 2020
@MatteoVH
Copy link
Contributor Author

Of course, looking into a unit test now.

@jelbourn jelbourn added the target: minor This PR is targeted for the next minor release label Oct 19, 2020
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

Also blocked on #20764 based on the discussion in #20826.

if (!isRemovable) {
throw new Error('This chip is not removable');
}

Copy link
Member

Choose a reason for hiding this comment

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

I think that we should implement this by dispatching a "delete" keydown event, instead of going through the remove button since a chip can be removable without having a remove button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying it that way, but the delete doesn't actually seem to trigger correctly from a 'keydown' event. Any ideas?

I can debug more easily once this gets synced into our repo.


/** Indicates if this chip can be deleted. */
async isRemovable(): Promise<boolean> {
const removeHarness = await this.locatorForOptional(MatChipRemoveHarness)();
Copy link
Member

@crisbeto crisbeto Oct 20, 2020

Choose a reason for hiding this comment

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

The presence of a remove button doesn't determine whether a chip is removable, but rather the removable input. Is there a use case for this method, aside from throwing the error inside remove? If not, I think that we can get rid of this method since we don't have it on the non-MDC harness either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, I'll remove this method.

import {ChipRemoveHarnessFilters} from './chip-harness-filters';

/** Harness for interacting with a mat-chip removal button in tests. */
export class MatChipRemoveHarness extends ComponentHarness {
Copy link
Member

Choose a reason for hiding this comment

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

The non-MDC harness has a click method so we should probably add it to this one too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, that's outside the scope of what I'd like to accomplish here.

@crisbeto
Copy link
Member

Also I'm not sure why the CI checks aren't running against this PR.

@crisbeto crisbeto added the blocked This issue is blocked by some external factor, such as a prerequisite PR label Oct 20, 2020
@jelbourn
Copy link
Member

@MatteoVH you wouldn't happen to have CircleCI set up on your fork, would you?

@MatteoVH
Copy link
Contributor Author

I don't believe I do, checking my github integrations on CircleCI doesn't show any.

@MatteoVH MatteoVH force-pushed the mat-chip-harness-remove branch from eb0f2d3 to a9ffa7a Compare October 28, 2020 19:29
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

The recent changes LGTM once the CI is green.

@MatteoVH
Copy link
Contributor Author

Hey @crisbeto, The 'transitionend' event doesn't seem to be firing correctly when I use a delete 'keydown' vs. clicking on a MatChipRemove element. Specifically, this @HostListener isn't being triggered. Any ideas why that might be?

@crisbeto
Copy link
Member

Without having dived into it, here are a couple of things that you can try:

  1. Using TestElement.sendKeys to dispatch the keyboard event.
  2. Adding a await this.forceStabilize() before and after the transitionend event to make sure that we've waited to all the change detection-related events have finished.

@mmalerba mmalerba removed the blocked This issue is blocked by some external factor, such as a prerequisite PR label Oct 30, 2020
@MatteoVH MatteoVH changed the title add remove API to MDC chip harness feat(material-experimental/mdc-chips): add remove method to MDC chip harness Nov 3, 2020
@MatteoVH MatteoVH force-pushed the mat-chip-harness-remove branch 5 times, most recently from 3f2299a to c702990 Compare November 3, 2020 23:55
…p harness

This allows MDC chips to be removed in testing environments.

Note that the harness must not only click on the remove button, but also dispatch a `transitionend` event. Without the
dispatch of this event, the chip would not fire it's `removed` output.

This PR also includes a basic MDC ChipRemoveHarness that mirrors the non-MDC version. This was necessary to find the
ChipRemove button in the chip harness' `remove` method.
@MatteoVH MatteoVH force-pushed the mat-chip-harness-remove branch from 83a26eb to e6cb039 Compare November 4, 2020 00:01
@MatteoVH
Copy link
Contributor Author

MatteoVH commented Nov 4, 2020

@crisbeto, looks like I was misspelling the event type. Should be all good now.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker merge safe labels Nov 4, 2020
@annieyw annieyw merged commit d29ef76 into angular:master Nov 4, 2020
@MatteoVH MatteoVH deleted the mat-chip-harness-remove branch November 4, 2020 22:36
@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 Dec 5, 2020
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 area: material/chips cla: yes PR author has agreed to Google's Contributor License Agreement G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants