Skip to content

Commit d1d2ed0

Browse files
committed
test(material/stepper): update tests based on new stepper aria-attributes
Updates stepper tests based on the new aria-attributes that were added to the stepper, particularly for the horizontal stepper.
1 parent 9250369 commit d1d2ed0

File tree

4 files changed

+27
-58
lines changed

4 files changed

+27
-58
lines changed

src/components-examples/material/stepper/stepper-harness/stepper-harness-example.spec.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,10 @@ describe('StepperHarnessExample', () => {
4747

4848
await secondStep.select();
4949

50-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
51-
false,
52-
true,
53-
false,
54-
]);
50+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, true, false]);
5551

5652
await nextButton.click();
5753

58-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
59-
false,
60-
false,
61-
true,
62-
]);
54+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, false, true]);
6355
});
6456
});

src/material/stepper/testing/step-harness-filters.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export enum StepperOrientation {
1717
export interface StepHarnessFilters extends BaseHarnessFilters {
1818
/** Only find instances whose label matches the given value. */
1919
label?: string | RegExp;
20-
/** Only find steps with the given expanded state. */
20+
/** Only find steps with the given expanded for Horizontal Stepper state. */
21+
pressed?: boolean;
22+
/** Only find steps with the given expanded for Vertical Stepper state. */
2123
expanded?: boolean;
2224
/** Only find completed steps. */
2325
completed?: boolean;

src/material/stepper/testing/step-harness.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export class MatStepHarness extends ContentContainerComponentHarness<string> {
2929
.addOption('label', options.label, (harness, label) =>
3030
HarnessPredicate.stringMatches(harness.getLabel(), label),
3131
)
32+
.addOption(
33+
'pressed',
34+
options.pressed,
35+
async (harness, pressed) => (await harness.isPressed()) === pressed,
36+
)
3237
.addOption(
3338
'expanded',
3439
options.expanded,
@@ -61,7 +66,13 @@ export class MatStepHarness extends ContentContainerComponentHarness<string> {
6166
return (await this.host()).getAttribute('aria-labelledby');
6267
}
6368

64-
/** Whether the step is expanded. */
69+
/** Whether the step of Horizontal Stepper is pressed. */
70+
async isPressed(): Promise<boolean> {
71+
const host = await this.host();
72+
return (await host.getAttribute('aria-pressed')) === 'true';
73+
}
74+
75+
/** Whether the step of Vertical Stepper is expanded. */
6576
async isExpanded(): Promise<boolean> {
6677
const host = await this.host();
6778
return (await host.getAttribute('aria-expanded')) === 'true';
@@ -70,7 +81,7 @@ export class MatStepHarness extends ContentContainerComponentHarness<string> {
7081
/** Whether the step has been filled out. */
7182
async isCompleted(): Promise<boolean> {
7283
const state = await this._getIconState();
73-
return state === 'done' || (state === 'edit' && !(await this.isExpanded()));
84+
return state === 'done' || (state === 'edit' && !(await this.isPressed()));
7485
}
7586

7687
/**

src/material/stepper/testing/stepper-harness.spec.ts

+9-45
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,11 @@ describe('MatStepperHarness', () => {
9292
const stepper = await loader.getHarness(MatStepperHarness.with({selector: '#two-stepper'}));
9393
const steps = await stepper.getSteps();
9494

95-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
96-
true,
97-
false,
98-
false,
99-
]);
95+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([true, false, false]);
10096

10197
await stepper.selectStep({label: 'Three'});
10298

103-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
104-
false,
105-
false,
106-
true,
107-
]);
99+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, false, true]);
108100
});
109101

110102
it('should be able to get the text-based label of a step', async () => {
@@ -167,11 +159,7 @@ describe('MatStepperHarness', () => {
167159
const stepper = await loader.getHarness(MatStepperHarness.with({selector: '#two-stepper'}));
168160
const steps = await stepper.getSteps();
169161

170-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
171-
true,
172-
false,
173-
false,
174-
]);
162+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([true, false, false]);
175163
});
176164

177165
it('should be able to select a step in a vertical stepper', async () => {
@@ -199,19 +187,11 @@ describe('MatStepperHarness', () => {
199187
const stepper = await loader.getHarness(MatStepperHarness.with({selector: '#two-stepper'}));
200188
const steps = await stepper.getSteps();
201189

202-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
203-
true,
204-
false,
205-
false,
206-
]);
190+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([true, false, false]);
207191

208192
await steps[2].select();
209193

210-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
211-
false,
212-
false,
213-
true,
214-
]);
194+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, false, true]);
215195
});
216196

217197
it('should get whether a step is optional', async () => {
@@ -265,19 +245,11 @@ describe('MatStepperHarness', () => {
265245

266246
await secondStep.select();
267247

268-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
269-
false,
270-
true,
271-
false,
272-
]);
248+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, true, false]);
273249

274250
await nextButton.click();
275251

276-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
277-
false,
278-
false,
279-
true,
280-
]);
252+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, false, true]);
281253
});
282254

283255
it('should go backward when pressing the previous button of a vertical stepper', async () => {
@@ -313,19 +285,11 @@ describe('MatStepperHarness', () => {
313285

314286
await secondStep.select();
315287

316-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
317-
false,
318-
true,
319-
false,
320-
]);
288+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, true, false]);
321289

322290
await previousButton.click();
323291

324-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
325-
true,
326-
false,
327-
false,
328-
]);
292+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([true, false, false]);
329293
});
330294

331295
it('should get whether a step has errors', async () => {

0 commit comments

Comments
 (0)