Skip to content

Commit 14f412a

Browse files
committed
add edit harness
1 parent d5b2141 commit 14f412a

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import {
10+
ComponentHarness,
11+
ComponentHarnessConstructor,
12+
HarnessPredicate,
13+
} from '@angular/cdk/testing';
14+
import {ChipEditHarnessFilters} from './chip-harness-filters';
15+
16+
/** Harness for interacting with a standard Material chip edit button in tests. */
17+
export class MatChipEditHarness extends ComponentHarness {
18+
static hostSelector = '.mat-mdc-chip-edit';
19+
20+
/**
21+
* Gets a `HarnessPredicate` that can be used to search for a chip edit with specific
22+
* attributes.
23+
* @param options Options for filtering which input instances are considered a match.
24+
* @return a `HarnessPredicate` configured with the given options.
25+
*/
26+
static with<T extends MatChipEditHarness>(
27+
this: ComponentHarnessConstructor<T>,
28+
options: ChipEditHarnessFilters = {},
29+
): HarnessPredicate<T> {
30+
return new HarnessPredicate(this, options);
31+
}
32+
33+
/** Clicks the edit button. */
34+
async click(): Promise<void> {
35+
return (await this.host()).click();
36+
}
37+
}

src/material/chips/testing/chip-harness-filters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export interface ChipRowHarnessFilters extends ChipHarnessFilters {}
4343

4444
export interface ChipSetHarnessFilters extends BaseHarnessFilters {}
4545

46+
export interface ChipEditHarnessFilters extends BaseHarnessFilters {}
47+
4648
export interface ChipRemoveHarnessFilters extends BaseHarnessFilters {}
4749

4850
export interface ChipAvatarHarnessFilters extends BaseHarnessFilters {}

src/material/chips/testing/chip-harness.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import {
1515
import {MatChipAvatarHarness} from './chip-avatar-harness';
1616
import {
1717
ChipAvatarHarnessFilters,
18+
ChipEditHarnessFilters,
1819
ChipHarnessFilters,
1920
ChipRemoveHarnessFilters,
2021
} from './chip-harness-filters';
22+
import {MatChipEditHarness} from './chip-edit-harness';
2123
import {MatChipRemoveHarness} from './chip-remove-harness';
2224

2325
/** Harness for interacting with a mat-chip in tests. */
@@ -62,6 +64,14 @@ export class MatChipHarness extends ContentContainerComponentHarness {
6264
await hostEl.sendKeys(TestKey.DELETE);
6365
}
6466

67+
/**
68+
* Gets the edit button inside of a chip.
69+
* @param filter Optionally filters which chips are included.
70+
*/
71+
async geEditButton(filter: ChipEditHarnessFilters = {}): Promise<MatChipEditHarness> {
72+
return this.locatorFor(MatChipEditHarness.with(filter))();
73+
}
74+
6575
/**
6676
* Gets the remove button inside of a chip.
6777
* @param filter Optionally filters which chips are included.

0 commit comments

Comments
 (0)