Skip to content

Commit a259b01

Browse files
committedAug 13, 2024
fix(material/radio): account for disabledInteractive in harness
Switches to using a CSS class to get the disabled state in the harness so it continues to work when `disabledInteractive` is set. (cherry picked from commit 002b054)
1 parent aaf0d51 commit a259b01

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed
 

‎src/material/radio/testing/radio-harness.spec.ts

+27-15
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,17 @@ describe('radio harness', () => {
4545
expect(await groups[0].getId()).toBe('my-group-1');
4646
});
4747

48-
it(
49-
'should throw when finding radio-group with specific name that has mismatched ' +
50-
'radio-button names',
51-
async () => {
52-
fixture.componentInstance.thirdGroupButtonName = 'other-name';
53-
fixture.changeDetectorRef.markForCheck();
54-
fixture.detectChanges();
55-
56-
await expectAsync(
57-
loader.getAllHarnesses(MatRadioGroupHarness.with({name: 'third-group-name'})),
58-
).toBeRejectedWithError(
59-
/locator found a radio-group with name "third-group-name".*have mismatching names/,
60-
);
61-
},
62-
);
48+
it('should throw when finding radio-group with specific name that has mismatched radio-button names', async () => {
49+
fixture.componentInstance.thirdGroupButtonName = 'other-name';
50+
fixture.changeDetectorRef.markForCheck();
51+
fixture.detectChanges();
52+
53+
await expectAsync(
54+
loader.getAllHarnesses(MatRadioGroupHarness.with({name: 'third-group-name'})),
55+
).toBeRejectedWithError(
56+
/locator found a radio-group with name "third-group-name".*have mismatching names/,
57+
);
58+
});
6359

6460
it('should get name of radio-group', async () => {
6561
const groups = await loader.getAllHarnesses(MatRadioGroupHarness);
@@ -214,6 +210,20 @@ describe('radio harness', () => {
214210
expect(await firstRadio.isDisabled()).toBe(true);
215211
});
216212

213+
it('should get the disabled state with disabledInteractive is enabled', async () => {
214+
fixture.componentInstance.disabledInteractive = true;
215+
fixture.changeDetectorRef.markForCheck();
216+
217+
const [firstRadio] = await loader.getAllHarnesses(MatRadioButtonHarness);
218+
expect(await firstRadio.isDisabled()).toBe(false);
219+
220+
fixture.componentInstance.disableAll = true;
221+
fixture.changeDetectorRef.markForCheck();
222+
fixture.detectChanges();
223+
224+
expect(await firstRadio.isDisabled()).toBe(true);
225+
});
226+
217227
it('should focus radio-button', async () => {
218228
const radioButton = await loader.getHarness(MatRadioButtonHarness.with({selector: '#opt2'}));
219229
expect(await radioButton.isFocused()).toBe(false);
@@ -272,6 +282,7 @@ describe('radio harness', () => {
272282
<mat-radio-button
273283
[name]="value === 'opt3' ? 'group2' : 'group1'"
274284
[disabled]="disableAll"
285+
[disabledInteractive]="disabledInteractive"
275286
[checked]="value === 'opt2'"
276287
[id]="value"
277288
[required]="value === 'opt2'"
@@ -307,6 +318,7 @@ describe('radio harness', () => {
307318
class MultipleRadioButtonsHarnessTest {
308319
values = ['opt1', 'opt2', 'opt3'];
309320
disableAll = false;
321+
disabledInteractive = false;
310322
secondGroupId = 'my-group-2';
311323
thirdGroupName: string = 'third-group-name';
312324
thirdGroupButtonName: string | undefined = undefined;

‎src/material/radio/testing/radio-harness.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,14 @@ export class MatRadioButtonHarness extends ComponentHarness {
205205

206206
/** Whether the radio-button is disabled. */
207207
async isDisabled(): Promise<boolean> {
208-
const disabled = (await this._input()).getAttribute('disabled');
209-
return coerceBooleanProperty(await disabled);
208+
const input = await this._input();
209+
const disabled = await input.getAttribute('disabled');
210+
211+
if (disabled !== null) {
212+
return coerceBooleanProperty(disabled);
213+
}
214+
215+
return (await input.getAttribute('aria-disabled')) === 'true';
210216
}
211217

212218
/** Whether the radio-button is required. */

0 commit comments

Comments
 (0)
Please sign in to comment.