Skip to content

Commit 73def2a

Browse files
authored
Apply the [stepId] field from the WizardSteps at ids in the navigation bar (#186)
- fix #183 - provide a description for the new usecase of the stepId input
1 parent df00edd commit 73def2a

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ One of these two ways is by using the `<aw-wizard-step>` component.
145145
#### \[stepId\]
146146
A wizard step can have its own unique id.
147147
This id can then be used to navigate to the step.
148+
In addition the `[stepId]` of a wizard step is used as the `id` of the `li` element for the wizard step in the navigation bar.
148149

149150
#### \[stepTitle\]
150151
A wizard step needs to contain a title, which is shown in the navigation bar of the wizard.

src/lib/components/wizard-navigation-bar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ul class="steps-indicator steps-{{numberOfWizardSteps}}">
2-
<li *ngFor="let step of wizardSteps"
2+
<li [attr.id]="step.stepId" *ngFor="let step of wizardSteps"
33
[ngClass]="{
44
default: isDefault(step),
55
current: isCurrent(step),

src/lib/components/wizard-navigation-bar.component.spec.ts

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
2-
import {Component, ViewChild} from '@angular/core';
2+
import {Component, DebugElement, ViewChild} from '@angular/core';
33
import {WizardNavigationBarComponent} from './wizard-navigation-bar.component';
44
import {WizardComponent} from './wizard.component';
55
import {By} from '@angular/platform-browser';
@@ -11,15 +11,17 @@ import {WizardState} from '../navigation/wizard-state.model';
1111
selector: 'aw-test-wizard',
1212
template: `
1313
<aw-wizard>
14-
<aw-wizard-step stepTitle='Steptitle 1'>Step 1</aw-wizard-step>
14+
<aw-wizard-step stepTitle='Steptitle 1' [stepId]="firstStepId">Step 1</aw-wizard-step>
1515
<aw-wizard-step stepTitle='Steptitle 2' awOptionalStep>Step 2</aw-wizard-step>
1616
<aw-wizard-step stepTitle='Steptitle 3'>Step 3</aw-wizard-step>
1717
</aw-wizard>
1818
`
1919
})
2020
class WizardTestComponent {
21+
public firstStepId = 'step1';
22+
2123
@ViewChild(WizardComponent)
22-
wizard: WizardComponent;
24+
public wizard: WizardComponent;
2325
}
2426

2527
describe('WizardNavigationBarComponent', () => {
@@ -459,8 +461,10 @@ describe('WizardNavigationBarComponent', () => {
459461
it('should use the \"small\" layout when no navigation bar layout is specified', () => {
460462
const navBar = wizardTestFixture.debugElement.query(By.css('aw-wizard-navigation-bar'));
461463

462-
expect(navBar.classes).toEqual({ 'horizontal': true, 'vertical': false, 'small': true,
463-
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false });
464+
expect(navBar.classes).toEqual({
465+
'horizontal': true, 'vertical': false, 'small': true,
466+
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false
467+
});
464468
});
465469

466470
it('should use the \"small\" layout when it is specified', () => {
@@ -469,8 +473,10 @@ describe('WizardNavigationBarComponent', () => {
469473
wizardTest.wizard.navBarLayout = 'small';
470474
wizardTestFixture.detectChanges();
471475

472-
expect(navBar.classes).toEqual({ 'horizontal': true, 'vertical': false, 'small': true,
473-
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false });
476+
expect(navBar.classes).toEqual({
477+
'horizontal': true, 'vertical': false, 'small': true,
478+
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false
479+
});
474480
});
475481

476482
it('should use the \"large-filled\" layout when it is specified', () => {
@@ -479,8 +485,10 @@ describe('WizardNavigationBarComponent', () => {
479485
wizardTest.wizard.navBarLayout = 'large-filled';
480486
wizardTestFixture.detectChanges();
481487

482-
expect(navBar.classes).toEqual({ 'horizontal': true, 'vertical': false, 'small': false,
483-
'large-filled': true, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false });
488+
expect(navBar.classes).toEqual({
489+
'horizontal': true, 'vertical': false, 'small': false,
490+
'large-filled': true, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': false
491+
});
484492
});
485493

486494
it('should use the \"large-empty\" layout when it is specified', () => {
@@ -489,8 +497,10 @@ describe('WizardNavigationBarComponent', () => {
489497
wizardTest.wizard.navBarLayout = 'large-empty';
490498
wizardTestFixture.detectChanges();
491499

492-
expect(navBar.classes).toEqual({ 'horizontal': true, 'vertical': false, 'small': false,
493-
'large-filled': false, 'large-filled-symbols': false, 'large-empty': true, 'large-empty-symbols': false });
500+
expect(navBar.classes).toEqual({
501+
'horizontal': true, 'vertical': false, 'small': false,
502+
'large-filled': false, 'large-filled-symbols': false, 'large-empty': true, 'large-empty-symbols': false
503+
});
494504
});
495505

496506
it('should use the \"large-filled-symbols\" layout when it is specified', () => {
@@ -499,8 +509,10 @@ describe('WizardNavigationBarComponent', () => {
499509
wizardTest.wizard.navBarLayout = 'large-filled-symbols';
500510
wizardTestFixture.detectChanges();
501511

502-
expect(navBar.classes).toEqual({ 'horizontal': true, 'vertical': false, 'small': false,
503-
'large-filled': false, 'large-filled-symbols': true, 'large-empty': false, 'large-empty-symbols': false });
512+
expect(navBar.classes).toEqual({
513+
'horizontal': true, 'vertical': false, 'small': false,
514+
'large-filled': false, 'large-filled-symbols': true, 'large-empty': false, 'large-empty-symbols': false
515+
});
504516
});
505517

506518
it('should use the \"large-empty-symbols\" layout when it is specified', () => {
@@ -509,8 +521,10 @@ describe('WizardNavigationBarComponent', () => {
509521
wizardTest.wizard.navBarLayout = 'large-empty-symbols';
510522
wizardTestFixture.detectChanges();
511523

512-
expect(navBar.classes).toEqual({ 'horizontal': true, 'vertical': false, 'small': false,
513-
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': true });
524+
expect(navBar.classes).toEqual({
525+
'horizontal': true, 'vertical': false, 'small': false,
526+
'large-filled': false, 'large-filled-symbols': false, 'large-empty': false, 'large-empty-symbols': true
527+
});
514528
});
515529

516530
it('should show the correct step titles', () => {
@@ -533,4 +547,25 @@ describe('WizardNavigationBarComponent', () => {
533547
expect(navigationLinks[1].nativeElement.innerText).toBe('STEPTITLE 2');
534548
expect(navigationLinks[2].nativeElement.innerText).toBe('STEPTITLE 1');
535549
});
550+
551+
it('should have the correct stepId', () => {
552+
const navigationLiElements = wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-navigation-bar ul li'));
553+
554+
expect(navigationLiElements.length).toBe(3);
555+
expect(navigationLiElements[0].nativeElement.id).toBe('step1');
556+
expect(navigationLiElements[1].nativeElement.id).toBe('');
557+
expect(navigationLiElements[2].nativeElement.id).toBe('');
558+
});
559+
560+
it('should change the stepId correctly', () => {
561+
wizardTest.firstStepId = null;
562+
wizardTestFixture.detectChanges();
563+
564+
const navigationLiElements = wizardTestFixture.debugElement.queryAll(By.css('aw-wizard-navigation-bar ul li'));
565+
566+
expect(navigationLiElements.length).toBe(3);
567+
expect(navigationLiElements[0].nativeElement.id).toBe('');
568+
expect(navigationLiElements[1].nativeElement.id).toBe('');
569+
expect(navigationLiElements[2].nativeElement.id).toBe('');
570+
});
536571
});

0 commit comments

Comments
 (0)