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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export interface ChipOptionHarnessFilters extends ChipHarnessFilters {}
export interface ChipRowHarnessFilters extends ChipHarnessFilters {}

export interface ChipSetHarnessFilters extends BaseHarnessFilters {}

export interface ChipRemoveHarnessFilters extends BaseHarnessFilters {}
18 changes: 15 additions & 3 deletions src/material-experimental/mdc-chips/testing/chip-harness.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('MatChipHarness', () => {

it('should get correct number of chip harnesses', async () => {
const harnesses = await loader.getAllHarnesses(MatChipHarness);
expect(harnesses.length).toBe(4);
expect(harnesses.length).toBe(5);
});

it('should get the chip text content', async () => {
Expand All @@ -31,6 +31,16 @@ describe('MatChipHarness', () => {
expect(await harnesses[1].getText()).toBe('Chip');
expect(await harnesses[2].getText()).toBe('Chip with avatar');
expect(await harnesses[3].getText()).toBe('Disabled Chip');
expect(await harnesses[4].getText()).toBe('Chip Row');
});

it('should be able to remove a mat-chip-row', async () => {
const removeChipSpy = spyOn(fixture.componentInstance, 'removeChip');

const harnesses = await loader.getAllHarnesses(MatChipHarness);
await harnesses[4].remove();

expect(removeChipSpy).toHaveBeenCalledTimes(1);
});
});

Expand All @@ -40,7 +50,9 @@ describe('MatChipHarness', () => {
<mat-chip>Chip <span matChipTrailingIcon>trailing_icon</span></mat-chip>
<mat-chip><mat-chip-avatar>B</mat-chip-avatar>Chip with avatar</mat-chip>
<mat-chip disabled>Disabled Chip <span matChipRemove>remove_icon</span></mat-chip>
<mat-chip-row (removed)="removeChip()">Chip Row</mat-chip-row>
`
})
class ChipHarnessTest {}

class ChipHarnessTest {
removeChip() {}
}
9 changes: 8 additions & 1 deletion src/material-experimental/mdc-chips/testing/chip-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
import {ComponentHarness, HarnessPredicate, TestKey} from '@angular/cdk/testing';
import {ChipHarnessFilters} from './chip-harness-filters';

/** Harness for interacting with a mat-chip in tests. */
Expand All @@ -30,4 +30,11 @@ export class MatChipHarness extends ComponentHarness {
exclude: '.mat-mdc-chip-avatar, .mat-mdc-chip-trailing-icon, .mat-icon'
});
}

/** Delete a chip from the set. */
async remove(): Promise<void> {
const hostEl = await this.host();
await hostEl.sendKeys!(TestKey.DELETE);
await hostEl.dispatchEvent!('transitionend', {propertyName: 'width'});
}
}