Skip to content

Commit f504fae

Browse files
authored
test(material/button): add disabled harness filter (#26138)
* test(material/button): add disabled harness filter * fixup! test(material/button): add disabled harness filter * test(material/legacy-button): add disabled harness filter
1 parent 39afd3e commit f504fae

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

src/material/button/testing/button-harness-filters.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ export interface ButtonHarnessFilters extends BaseHarnessFilters {
1818

1919
/** Only find instances with a variant. */
2020
variant?: ButtonVariant;
21+
22+
/** Only find instances which match the given disabled state. */
23+
disabled?: boolean;
2124
}

src/material/button/testing/button-harness.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export class MatButtonHarness extends ContentContainerComponentHarness {
3838
)
3939
.addOption('variant', options.variant, (harness, variant) =>
4040
HarnessPredicate.stringMatches(harness.getVariant(), variant),
41-
);
41+
)
42+
.addOption('disabled', options.disabled, async (harness, disabled) => {
43+
return (await harness.isDisabled()) === disabled;
44+
});
4245
}
4346

4447
/**

src/material/button/testing/shared.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export function runHarnessTests(
5050
expect(await buttons[1].getText()).toBe('Basic anchor');
5151
});
5252

53+
it('should filter by whether a button is disabled', async () => {
54+
const enabledButtons = await loader.getAllHarnesses(buttonHarness.with({disabled: false}));
55+
const disabledButtons = await loader.getAllHarnesses(buttonHarness.with({disabled: true}));
56+
expect(enabledButtons.length).toBe(13);
57+
expect(disabledButtons.length).toBe(2);
58+
});
59+
5360
it('should get disabled state', async () => {
5461
// Grab each combination of [enabled, disabled] ⨯ [button, anchor]
5562
const [disabledFlatButton, enabledFlatAnchor] = await loader.getAllHarnesses(

src/material/legacy-button/testing/button-harness.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export class MatLegacyButtonHarness extends ContentContainerComponentHarness {
3434
)
3535
.addOption('variant', options.variant, (harness, variant) =>
3636
HarnessPredicate.stringMatches(harness.getVariant(), variant),
37-
);
37+
)
38+
.addOption('disabled', options.disabled, async (harness, disabled) => {
39+
return (await harness.isDisabled()) === disabled;
40+
});
3841
}
3942

4043
/**

tools/public_api_guard/material/button-testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { HarnessPredicate } from '@angular/cdk/testing';
1111

1212
// @public
1313
export interface ButtonHarnessFilters extends BaseHarnessFilters {
14+
disabled?: boolean;
1415
text?: string | RegExp;
1516
variant?: ButtonVariant;
1617
}

0 commit comments

Comments
 (0)