Skip to content

Commit aa50940

Browse files
authored
Fix issue 10 (#11)
- changed the interface WizardStep to an abstract class - changed some WizardStepComponent objects to WizardStep objects - fixed #10 - renamed file MovingDirection.ts to moving-direction.enum.ts - renamed StepOffset.ts to step-offset.interface.ts - renamed WizardStep.ts to wizard-step.interface.ts - fixed problem in the WizardComponent test - cleanup the TestBed configurations - remove property allSteps from WizardComponent - excluding the forRoot method in WizardModule from the coverage - excluding the constructor method of the abstract WizardStep class from the coverage
1 parent 07c6e38 commit aa50940

21 files changed

+211
-169
lines changed

src/components/components/wizard-completion-step.component.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
/**
22
* Created by marc on 20.05.17.
33
*/
4-
/* tslint:disable:no-unused-variable */
54
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
6-
import {WizardStepComponent} from './wizard-step.component';
75
import {WizardCompletionStepComponent} from './wizard-completion-step.component';
86
import {ViewChild, Component} from '@angular/core';
97
import {WizardComponent} from './wizard.component';
10-
import {MovingDirection} from '../util/MovingDirection';
11-
import {WizardNavigationBarComponent} from './wizard-navigation-bar.component';
12-
import {GoToStepDirective} from '../directives/go-to-step.directive';
8+
import {MovingDirection} from '../util/moving-direction.enum';
139
import {By} from '@angular/platform-browser';
14-
import {OptionalStepDirective} from '../directives/optional-step.directive';
10+
import {WizardModule} from '../wizard.module';
1511

1612
@Component({
1713
selector: 'test-wizard',
@@ -47,8 +43,8 @@ describe('WizardCompletionStepComponent', () => {
4743

4844
beforeEach(async(() => {
4945
TestBed.configureTestingModule({
50-
declarations: [WizardComponent, WizardStepComponent, WizardCompletionStepComponent, WizardNavigationBarComponent,
51-
WizardTestComponent, GoToStepDirective, OptionalStepDirective]
46+
declarations: [WizardTestComponent],
47+
imports: [WizardModule]
5248
}).compileComponents();
5349
}));
5450

src/components/components/wizard-completion-step.component.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* Created by marc on 20.05.17.
33
*/
44

5-
import {Component, ContentChild, EventEmitter, HostBinding, Input, Output} from '@angular/core';
6-
import {MovingDirection} from '../util/MovingDirection';
5+
import {Component, ContentChild, EventEmitter, forwardRef, HostBinding, Inject, Input, Output} from '@angular/core';
6+
import {MovingDirection} from '../util/moving-direction.enum';
77
import {WizardComponent} from './wizard.component';
8-
import {WizardStep} from '../util/WizardStep';
8+
import {WizardStep} from '../util/wizard-step.interface';
99
import {WizardStepTitleDirective} from '../directives/wizard-step-title.directive';
1010

1111
/**
@@ -47,9 +47,12 @@ import {WizardStepTitleDirective} from '../directives/wizard-step-title.directiv
4747
@Component({
4848
selector: 'wizard-completion-step',
4949
templateUrl: 'wizard-completion-step.component.html',
50-
styleUrls: ['wizard-completion-step.component.css']
50+
styleUrls: ['wizard-completion-step.component.css'],
51+
providers: [
52+
{ provide: WizardStep, useExisting: forwardRef(() => WizardCompletionStepComponent) }
53+
]
5154
})
52-
export class WizardCompletionStepComponent implements WizardStep {
55+
export class WizardCompletionStepComponent extends WizardStep {
5356
/**
5457
* @inheritDoc
5558
*/
@@ -126,7 +129,9 @@ export class WizardCompletionStepComponent implements WizardStep {
126129
* Constructor
127130
* @param wizard The [[WizardComponent]], this completion step is contained inside
128131
*/
129-
constructor(private wizard: WizardComponent) { }
132+
constructor(@Inject(forwardRef(() => WizardComponent)) private wizard: WizardComponent) {
133+
super();
134+
}
130135

131136
/**
132137
* @inheritDoc

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
/* tslint:disable:no-unused-variable */
21
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
32
import {ViewChild, Component} from '@angular/core';
43
import {WizardNavigationBarComponent} from './wizard-navigation-bar.component';
54
import {WizardComponent} from './wizard.component';
6-
import {WizardStepComponent} from './wizard-step.component';
7-
import {GoToStepDirective} from '../directives/go-to-step.directive';
85
import {By} from '@angular/platform-browser';
9-
import {OptionalStepDirective} from '../directives/optional-step.directive';
6+
import {WizardModule} from '../wizard.module';
107

118
@Component({
129
selector: 'test-wizard',
@@ -29,8 +26,8 @@ describe('WizardNavigationBarComponent', () => {
2926

3027
beforeEach(async(() => {
3128
TestBed.configureTestingModule({
32-
declarations: [ WizardComponent, WizardStepComponent, WizardNavigationBarComponent,
33-
WizardTestComponent, GoToStepDirective, OptionalStepDirective ]
29+
declarations: [WizardTestComponent],
30+
imports: [WizardModule]
3431
}).compileComponents();
3532
}));
3633

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component} from '@angular/core';
22
import {WizardComponent} from './wizard.component';
3-
import {WizardStep} from '../util/WizardStep';
3+
import {WizardStep} from '../util/wizard-step.interface';
44

55
/**
66
* The `wizard-navigation-bar` component contains the navigation bar inside a [[WizardComponent]].
@@ -34,7 +34,7 @@ export class WizardNavigationBarComponent {
3434
* @returns {Array<WizardStep>} An array containing all [[WizardStep]]s
3535
*/
3636
get wizardSteps(): Array<WizardStep> {
37-
return this.wizard.allSteps;
37+
return this.wizard.wizardSteps.toArray();
3838
}
3939

4040
/**
@@ -43,6 +43,6 @@ export class WizardNavigationBarComponent {
4343
* @returns {number} The number of wizard steps to be displayed
4444
*/
4545
get numberOfWizardSteps(): number {
46-
return this.wizard.allSteps.length;
46+
return this.wizard.wizardSteps.length;
4747
}
4848
}

src/components/components/wizard-step.component.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
/* tslint:disable:no-unused-variable */
21
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
32
import {WizardStepComponent} from './wizard-step.component';
43
import {ViewChild, Component} from '@angular/core';
54
import {WizardComponent} from './wizard.component';
6-
import {MovingDirection} from '../util/MovingDirection';
7-
import {WizardNavigationBarComponent} from './wizard-navigation-bar.component';
8-
import {GoToStepDirective} from '../directives/go-to-step.directive';
5+
import {MovingDirection} from '../util/moving-direction.enum';
96
import {By} from '@angular/platform-browser';
10-
import {OptionalStepDirective} from '../directives/optional-step.directive';
7+
import {WizardModule} from '../wizard.module';
118

129
@Component({
1310
selector: 'test-wizard',
@@ -43,8 +40,8 @@ describe('WizardStepComponent', () => {
4340

4441
beforeEach(async(() => {
4542
TestBed.configureTestingModule({
46-
declarations: [WizardComponent, WizardStepComponent, WizardNavigationBarComponent,
47-
WizardTestComponent, GoToStepDirective, OptionalStepDirective]
43+
declarations: [WizardTestComponent],
44+
imports: [WizardModule]
4845
}).compileComponents();
4946
}));
5047

src/components/components/wizard-step.component.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {Component, ContentChild, EventEmitter, HostBinding, Input, Output} from '@angular/core';
2-
import {MovingDirection} from '../util/MovingDirection';
3-
import {WizardStep} from '../util/WizardStep';
1+
import {Component, ContentChild, EventEmitter, forwardRef, HostBinding, Input, Output} from '@angular/core';
2+
import {MovingDirection} from '../util/moving-direction.enum';
3+
import {WizardStep} from '../util/wizard-step.interface';
44
import {WizardStepTitleDirective} from '../directives/wizard-step-title.directive';
55

66
/**
@@ -54,9 +54,12 @@ import {WizardStepTitleDirective} from '../directives/wizard-step-title.directiv
5454
@Component({
5555
selector: 'wizard-step',
5656
templateUrl: 'wizard-step.component.html',
57-
styleUrls: ['wizard-step.component.css']
57+
styleUrls: ['wizard-step.component.css'],
58+
providers: [
59+
{ provide: WizardStep, useExisting: forwardRef(() => WizardStepComponent) }
60+
]
5861
})
59-
export class WizardStepComponent implements WizardStep {
62+
export class WizardStepComponent extends WizardStep {
6063
/**
6164
* @inheritDoc
6265
*/
@@ -135,6 +138,7 @@ export class WizardStepComponent implements WizardStep {
135138
* Constructor
136139
*/
137140
constructor() {
141+
super();
138142
}
139143

140144
/**

src/components/components/wizard.component.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/* tslint:disable:no-unused-variable */
21
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
32
import {QueryList, Component, ViewChild} from '@angular/core';
43
import {WizardComponent} from './wizard.component';
5-
import {WizardStepComponent} from './wizard-step.component';
6-
import {WizardNavigationBarComponent} from './wizard-navigation-bar.component';
7-
import {GoToStepDirective} from '../directives/go-to-step.directive';
84
import {By} from '@angular/platform-browser';
5+
import {WizardStep} from '../util/wizard-step.interface';
6+
import {WizardModule} from '../wizard.module';
97

108
@Component({
119
selector: 'test-wizard',
@@ -22,7 +20,7 @@ class WizardTestComponent {
2220
public wizard: WizardComponent;
2321
}
2422

25-
function checkWizardSteps(steps: QueryList<WizardStepComponent>, selectedStepIndex: number) {
23+
function checkWizardSteps(steps: QueryList<WizardStep>, selectedStepIndex: number) {
2624
steps.forEach((step, index, array) => {
2725
// Only the selected step should be selected
2826
if (index === selectedStepIndex) {
@@ -48,8 +46,8 @@ describe('WizardComponent', () => {
4846

4947
beforeEach(async(() => {
5048
TestBed.configureTestingModule({
51-
declarations: [ WizardComponent, WizardStepComponent, WizardNavigationBarComponent,
52-
WizardTestComponent, GoToStepDirective ]
49+
declarations: [WizardTestComponent],
50+
imports: [WizardModule]
5351
}).compileComponents();
5452
}));
5553

src/components/components/wizard.component.ts

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import {
2-
AfterContentInit, Component, ContentChild, ContentChildren, forwardRef, HostBinding, Input,
3-
QueryList
4-
} from '@angular/core';
5-
import {WizardStepComponent} from './wizard-step.component';
6-
import {MovingDirection} from '../util/MovingDirection';
7-
import {WizardCompletionStepComponent} from './wizard-completion-step.component';
8-
import {WizardStep} from '../util/WizardStep';
1+
import {AfterContentInit, Component, ContentChildren, HostBinding, Input, QueryList} from '@angular/core';
2+
import {MovingDirection} from '../util/moving-direction.enum';
3+
import {WizardStep} from '../util/wizard-step.interface';
94
import {isBoolean} from 'util';
105

116
/**
@@ -52,32 +47,8 @@ export class WizardComponent implements AfterContentInit {
5247
/**
5348
* A QueryList containing all WizardSteps in this Wizard
5449
*/
55-
@ContentChildren(WizardStepComponent)
56-
public wizardSteps: QueryList<WizardStepComponent>;
57-
58-
/**
59-
* An optional step, which is always the last step in the wizard and should be entered
60-
* when the wizard has been successfully completed
61-
*/
62-
@ContentChild(forwardRef(() => WizardCompletionStepComponent))
63-
public completionStep: WizardCompletionStepComponent;
64-
65-
/**
66-
* Returns a list containing all steps inside this [[WizardComponent]].
67-
* This list contains both the normal [[WizardStepComponent]] inside `wizardSteps` and the optional [[WizardCompletionStepComponent]]
68-
* inside `completionStep`
69-
*
70-
* @returns {Array<WizardStep>} A list containing all steps inside this wizard
71-
*/
72-
public get allSteps(): Array<WizardStep> {
73-
const steps: Array<WizardStep> = this.wizardSteps.toArray();
74-
75-
if (this.completionStep) {
76-
steps.push(this.completionStep);
77-
}
78-
79-
return steps;
80-
}
50+
@ContentChildren(WizardStep)
51+
public wizardSteps: QueryList<WizardStep>;
8152

8253
/**
8354
* The location of the navigation bar inside the wizard.
@@ -160,7 +131,7 @@ export class WizardComponent implements AfterContentInit {
160131
* @returns {boolean} True if the given `stepIndex` is contained inside this wizard, false otherwise
161132
*/
162133
hasStep(stepIndex: number): boolean {
163-
return this.allSteps.length > 0 && 0 <= stepIndex && stepIndex < this.allSteps.length;
134+
return this.wizardSteps.length > 0 && 0 <= stepIndex && stepIndex < this.wizardSteps.length;
164135
}
165136

166137
/**
@@ -187,7 +158,7 @@ export class WizardComponent implements AfterContentInit {
187158
* @returns {boolean} True if the wizard is currently inside its last step
188159
*/
189160
isLastStep(): boolean {
190-
return this.allSteps.length > 0 && this.currentStepIndex === this.allSteps.length - 1;
161+
return this.wizardSteps.length > 0 && this.currentStepIndex === this.wizardSteps.length - 1;
191162
}
192163

193164
/**
@@ -203,7 +174,7 @@ export class WizardComponent implements AfterContentInit {
203174
throw new Error(`Expected a known step, but got stepIndex: ${stepIndex}.`);
204175
}
205176

206-
return this.allSteps.find((item, index, array) => index === stepIndex);
177+
return this.wizardSteps.find((item, index, array) => index === stepIndex);
207178
}
208179

209180
/**
@@ -216,7 +187,7 @@ export class WizardComponent implements AfterContentInit {
216187
getIndexOfStep(step: WizardStep): number {
217188
let stepIndex: number = -1;
218189

219-
this.allSteps.forEach((item, index, array) => {
190+
this.wizardSteps.forEach((item, index, array) => {
220191
if (item === step) {
221192
stepIndex = index;
222193
}
@@ -295,7 +266,7 @@ export class WizardComponent implements AfterContentInit {
295266
let result: boolean =
296267
this.canExitStep(this.currentStep, this.getMovingDirection(stepIndex)) && this.hasStep(stepIndex);
297268

298-
this.allSteps.forEach((wizardStep, index, array) => {
269+
this.wizardSteps.forEach((wizardStep, index, array) => {
299270
if (index < stepIndex && index !== this.currentStepIndex) {
300271
// all steps before the next step, that aren't the current step, must be completed or optional
301272
result = result && (wizardStep.completed || wizardStep.optional);
@@ -319,7 +290,7 @@ export class WizardComponent implements AfterContentInit {
319290

320291
if (this.canExitStep(this.currentStep, movingDirection)) {
321292
// is it possible to leave the current step in the given direction?
322-
this.allSteps.forEach((wizardStep, index, array) => {
293+
this.wizardSteps.forEach((wizardStep, index, array) => {
323294
if (index === this.currentStepIndex) {
324295
// finish processing old step
325296
wizardStep.completed = true;
@@ -354,7 +325,7 @@ export class WizardComponent implements AfterContentInit {
354325
*/
355326
reset(): void {
356327
// reset the step internal state
357-
this.allSteps.forEach((step, index) => {
328+
this.wizardSteps.forEach((step, index) => {
358329
step.completed = false;
359330
step.selected = false;
360331
});

0 commit comments

Comments
 (0)