Skip to content

Commit fa3e5cc

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 8a8a38d commit fa3e5cc

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,10 @@ describe('StepperHarnessExample', () => {
4343

4444
await secondStep.select();
4545

46-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
47-
false,
48-
true,
49-
false,
50-
]);
46+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, true, false]);
5147

5248
await nextButton.click();
5349

54-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
55-
false,
56-
false,
57-
true,
58-
]);
50+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, false, true]);
5951
});
6052
});

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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 13 additions & 2 deletions
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

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,11 @@ describe('MatStepperHarness', () => {
9090
const stepper = await loader.getHarness(MatStepperHarness.with({selector: '#two-stepper'}));
9191
const steps = await stepper.getSteps();
9292

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

9995
await stepper.selectStep({label: 'Three'});
10096

101-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
102-
false,
103-
false,
104-
true,
105-
]);
97+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, false, true]);
10698
});
10799

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

168-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
169-
true,
170-
false,
171-
false,
172-
]);
160+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([true, false, false]);
173161
});
174162

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

200-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
201-
true,
202-
false,
203-
false,
204-
]);
188+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([true, false, false]);
205189

206190
await steps[2].select();
207191

208-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
209-
false,
210-
false,
211-
true,
212-
]);
192+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, false, true]);
213193
});
214194

215195
it('should get whether a step is optional', async () => {
@@ -263,19 +243,11 @@ describe('MatStepperHarness', () => {
263243

264244
await secondStep.select();
265245

266-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
267-
false,
268-
true,
269-
false,
270-
]);
246+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, true, false]);
271247

272248
await nextButton.click();
273249

274-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
275-
false,
276-
false,
277-
true,
278-
]);
250+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, false, true]);
279251
});
280252

281253
it('should go backward when pressing the previous button of a vertical stepper', async () => {
@@ -311,19 +283,11 @@ describe('MatStepperHarness', () => {
311283

312284
await secondStep.select();
313285

314-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
315-
false,
316-
true,
317-
false,
318-
]);
286+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([false, true, false]);
319287

320288
await previousButton.click();
321289

322-
expect(await parallel(() => steps.map(step => step.isExpanded()))).toEqual([
323-
true,
324-
false,
325-
false,
326-
]);
290+
expect(await parallel(() => steps.map(step => step.isPressed()))).toEqual([true, false, false]);
327291
});
328292

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

0 commit comments

Comments
 (0)