MCPcopy Create free account
hub / github.com/angular/components / MatChipHarness

Class MatChipHarness

src/material/chips/testing/chip-harness.ts:26–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25/** Harness for interacting with a mat-chip in tests. */
26export class MatChipHarness extends ContentContainerComponentHarness {
27 protected _primaryAction = this.locatorFor('.mdc-evolution-chip__action--primary');
28
29 static hostSelector = '.mat-mdc-basic-chip, .mat-mdc-chip';
30
31 /**
32 * Gets a `HarnessPredicate` that can be used to search for a chip with specific attributes.
33 * @param options Options for narrowing the search.
34 * @return a `HarnessPredicate` configured with the given options.
35 */
36 static with<T extends MatChipHarness>(
37 this: ComponentHarnessConstructor<T>,
38 options: ChipHarnessFilters = {},
39 ): HarnessPredicate<T> {
40 return new HarnessPredicate(this, options)
41 .addOption('text', options.text, (harness, label) => {
42 return HarnessPredicate.stringMatches(harness.getText(), label);
43 })
44 .addOption('disabled', options.disabled, async (harness, disabled) => {
45 return (await harness.isDisabled()) === disabled;
46 });
47 }
48
49 /** Gets a promise for the text content the option. */
50 async getText(): Promise<string> {
51 return (await this.host()).text({
52 exclude: '.mat-mdc-chip-avatar, .mat-mdc-chip-trailing-icon, .mat-icon',
53 });
54 }
55
56 /** Whether the chip is disabled. */
57 async isDisabled(): Promise<boolean> {
58 return (await this.host()).hasClass('mat-mdc-chip-disabled');
59 }
60
61 /** Delete a chip from the set. */
62 async remove(): Promise<void> {
63 const hostEl = await this.host();
64 await hostEl.sendKeys(TestKey.DELETE);
65 }
66
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
75 /**
76 * Gets the remove button inside of a chip.
77 * @param filter Optionally filters which chips are included.
78 */
79 async getRemoveButton(filter: ChipRemoveHarnessFilters = {}): Promise<MatChipRemoveHarness> {
80 return this.locatorFor(MatChipRemoveHarness.with(filter))();
81 }
82
83 /**

Callers

nothing calls this directly

Calls 1

locatorForMethod · 0.80

Tested by

no test coverage detected