Skip to content
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
1 change: 1 addition & 0 deletions goldens/material/button/testing/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ButtonHarnessFilters extends BaseHarnessFilters {
appearance?: ButtonAppearance;
buttonType?: ButtonType;
disabled?: boolean;
iconName?: string | RegExp;
text?: string | RegExp;
variant?: ButtonVariant;
}
Expand Down
1 change: 1 addition & 0 deletions src/material/button/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ts_project(
deps = [
"//:node_modules/@angular/core",
"//src/cdk/testing",
"//src/material/icon/testing",
],
)

Expand Down
3 changes: 3 additions & 0 deletions src/material/button/testing/button-harness-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ export interface ButtonHarnessFilters extends BaseHarnessFilters {

/** Only find instances with the specified type. */
buttonType?: ButtonType;

/** Only find instances that contain an icon whose name matches the given value. */
iconName?: string | RegExp;
}
7 changes: 7 additions & 0 deletions src/material/button/testing/button-harness.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ describe('MatButtonHarness', () => {
expect(await favIcon.getName()).toBe('favorite');
});

it('should be able to filter buttons containing a named icon', async () => {
const favBtn = await loader.getHarness(MatButtonHarness.with({iconName: 'favorite'}));

expect(await (await favBtn.host()).getAttribute('id')).toBe('favorite-icon');
expect(await (await favBtn.getHarness(MatIconHarness)).getName()).toBe('favorite');
});

it('should be able to ge the type variant of the button', async () => {
const buttons = await loader.getAllHarnesses(MatButtonHarness);
const variants = await parallel(() => buttons.map(button => button.getVariant()));
Expand Down
6 changes: 5 additions & 1 deletion src/material/button/testing/button-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ContentContainerComponentHarness,
HarnessPredicate,
} from '@angular/cdk/testing';
import {MatIconHarness} from '@angular/material/icon/testing';
import {
ButtonAppearance,
ButtonHarnessFilters,
Expand Down Expand Up @@ -58,7 +59,10 @@ export class MatButtonHarness extends ContentContainerComponentHarness {
})
.addOption('buttonType', options.buttonType, (harness, buttonType) =>
HarnessPredicate.stringMatches(harness.getType(), buttonType),
);
)
.addOption('iconName', options.iconName, (harness, iconName) => {
return harness.hasHarness(MatIconHarness.with({name: iconName}));
});
}

/**
Expand Down
Loading