Skip to content

feat(multiple): Add a harness filter option for checked checkboxes, radios, and slide-toggles #24625

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 2 commits into from
Mar 22, 2022
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 @@ -35,6 +35,11 @@ export class MatCheckboxHarness extends _MatCheckboxHarnessBase {
options.name,
async (harness, name) => (await harness.getName()) === name,
)
.addOption(
'checked',
options.checked,
async (harness, checked) => (await harness.isChecked()) == checked,
)
);
}

Expand Down
7 changes: 6 additions & 1 deletion src/material-experimental/mdc-radio/testing/radio-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ export class MatRadioButtonHarness extends _MatRadioButtonHarnessBase {
.addOption('label', options.label, (harness, label) =>
HarnessPredicate.stringMatches(harness.getLabelText(), label),
)
.addOption('name', options.name, async (harness, name) => (await harness.getName()) === name);
.addOption('name', options.name, async (harness, name) => (await harness.getName()) === name)
.addOption(
'checked',
options.checked,
async (harness, checked) => (await harness.isChecked()) == checked,
);
}

protected _textLabel = this.locatorFor('label');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export class MatSlideToggleHarness extends _MatSlideToggleHarnessBase {
options.name,
async (harness, name) => (await harness.getName()) === name,
)
.addOption(
'checked',
options.checked,
async (harness, checked) => (await harness.isChecked()) == checked,
)
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/material/checkbox/testing/checkbox-harness-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export interface CheckboxHarnessFilters extends BaseHarnessFilters {
label?: string | RegExp;
/** Only find instances whose name attribute is the given value. */
name?: string;
/** Only find instances with the given checked value. */
checked?: boolean;
}
5 changes: 5 additions & 0 deletions src/material/checkbox/testing/checkbox-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ export class MatCheckboxHarness extends _MatCheckboxHarnessBase {
options.name,
async (harness, name) => (await harness.getName()) === name,
)
.addOption(
'checked',
options.checked,
async (harness, checked) => (await harness.isChecked()) == checked,
)
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/material/radio/testing/radio-harness-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export interface RadioButtonHarnessFilters extends BaseHarnessFilters {
label?: string | RegExp;
/** Only find instances whose name attribute is the given value. */
name?: string;
/** Only find instances with the given checked value. */
checked?: boolean;
}
7 changes: 6 additions & 1 deletion src/material/radio/testing/radio-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ export class MatRadioButtonHarness extends _MatRadioButtonHarnessBase {
.addOption('label', options.label, (harness, label) =>
HarnessPredicate.stringMatches(harness.getLabelText(), label),
)
.addOption('name', options.name, async (harness, name) => (await harness.getName()) === name);
.addOption('name', options.name, async (harness, name) => (await harness.getName()) === name)
.addOption(
'checked',
options.checked,
async (harness, checked) => (await harness.isChecked()) == checked,
);
}

protected _textLabel = this.locatorFor('.mat-radio-label-content');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export interface SlideToggleHarnessFilters extends BaseHarnessFilters {
label?: string | RegExp;
/** Only find instances whose name is the given value. */
name?: string;
/** Only find instances with the given checked value. */
checked?: boolean;
}
5 changes: 5 additions & 0 deletions src/material/slide-toggle/testing/slide-toggle-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export class MatSlideToggleHarness extends _MatSlideToggleHarnessBase {
options.name,
async (harness, name) => (await harness.getName()) === name,
)
.addOption(
'checked',
options.checked,
async (harness, checked) => (await harness.isChecked()) == checked,
)
);
}

Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/checkbox-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TestElement } from '@angular/cdk/testing';

// @public
export interface CheckboxHarnessFilters extends BaseHarnessFilters {
checked?: boolean;
label?: string | RegExp;
name?: string;
}
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/radio-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export abstract class _MatRadioGroupHarnessBase<ButtonType extends ComponentHarn

// @public
export interface RadioButtonHarnessFilters extends BaseHarnessFilters {
checked?: boolean;
label?: string | RegExp;
name?: string;
}
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/slide-toggle-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export abstract class _MatSlideToggleHarnessBase extends ComponentHarness {

// @public
export interface SlideToggleHarnessFilters extends BaseHarnessFilters {
checked?: boolean;
label?: string | RegExp;
name?: string;
}
Expand Down