@@ -8,6 +8,7 @@ import {ComponentFixture, async, TestBed} from "@angular/core/testing";
88import { WizardStepComponent } from "../components/wizard-step.component" ;
99import { WizardNavigationBarComponent } from "../components/wizard-navigation-bar.component" ;
1010import { By } from "@angular/platform-browser" ;
11+ import { OptionalStepDirective } from "./optional-step.directive" ;
1112
1213@Component ( {
1314 selector : 'test-wizard' ,
@@ -16,10 +17,15 @@ import {By} from "@angular/platform-browser";
1617 <wizard-step title='Steptitle 1'>
1718 Step 1
1819 <button type="button" goToStep="1" (finalize)="finalizeStep(1)">Go to second step</button>
20+ <button type="button" goToStep="2" (finalize)="finalizeStep(1)">Go to third step</button>
1921 </wizard-step>
20- <wizard-step title='Steptitle 2'>
22+ <wizard-step title='Steptitle 2' optionalStep >
2123 Step 2
22- <button type="button" goToStep="0" (finalize)="finalizeStep(2)">Go to first step</button>
24+ <button type="button" goToStep="2" (finalize)="finalizeStep(2)">Go to third step</button>
25+ </wizard-step>
26+ <wizard-step title='Steptitle 3'>
27+ Step 3
28+ <button type="button" goToStep="0" (finalize)="finalizeStep(3)">Go to first step</button>
2329 </wizard-step>
2430 </wizard>
2531 `
@@ -41,7 +47,7 @@ describe('GoToStepDirective', () => {
4147
4248 beforeEach ( async ( ( ) => {
4349 TestBed . configureTestingModule ( {
44- declarations : [ WizardComponent , WizardStepComponent , WizardNavigationBarComponent , WizardTestComponent , GoToStepDirective ]
50+ declarations : [ WizardComponent , WizardStepComponent , WizardNavigationBarComponent , WizardTestComponent , GoToStepDirective , OptionalStepDirective ]
4551 } ) . compileComponents ( ) ;
4652 } ) ) ;
4753
@@ -52,36 +58,61 @@ describe('GoToStepDirective', () => {
5258 } ) ;
5359
5460 it ( 'should create an instance' , ( ) => {
55- expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 1"] > button[goToStep]' ) ) ) . toBeTruthy ( ) ;
61+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 1"] > button[goToStep]:first-child' ) ) ) . toBeTruthy ( ) ;
62+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 1"] > button[goToStep]:nth-child(2)' ) ) ) . toBeTruthy ( ) ;
5663 expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 2"] > button[goToStep]' ) ) ) . toBeTruthy ( ) ;
57- expect ( wizardTestFixture . debugElement . queryAll ( By . css ( 'wizard-step > button[goToStep]' ) ) . length ) . toBe ( 2 ) ;
64+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 3"] > button[goToStep]' ) ) ) . toBeTruthy ( ) ;
65+ expect ( wizardTestFixture . debugElement . queryAll ( By . css ( 'wizard-step > button[goToStep]' ) ) . length ) . toBe ( 4 ) ;
5866 } ) ;
5967
6068 it ( 'should move to step correctly' , ( ) => {
61- const firstStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 1"] > button[goToStep]' ) ) . nativeElement ;
69+ const firstStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 1"] > button[goToStep]:first-child ' ) ) . nativeElement ;
6270 const secondStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 2"] > button[goToStep]' ) ) . nativeElement ;
6371
6472 expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
65- expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard > wizard -step .current' ) ) ) . toBe ( wizardTestFixture . debugElement . query ( By . css ( 'wizard > wizard-step:first-child' ) ) ) ;
73+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step.current' ) ) . nativeElement . title ) . toBe ( "Steptitle 1" ) ;
6674
6775 // click button
6876 firstStepGoToButton . click ( ) ;
6977 wizardTestFixture . detectChanges ( ) ;
7078
7179 expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 1 ) ;
72- expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard > wizard -step .current' ) ) ) . toBe ( wizardTestFixture . debugElement . query ( By . css ( 'wizard > wizard-step :nth-child(2)' ) ) ) ;
80+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step.current' ) ) . nativeElement . title ) . toBe ( "Steptitle 2" ) ;
7381
7482 // click button
7583 secondStepGoToButton . click ( ) ;
7684 wizardTestFixture . detectChanges ( ) ;
7785
86+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 2 ) ;
87+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step.current' ) ) . nativeElement . title ) . toBe ( "Steptitle 3" ) ;
88+ } ) ;
89+
90+ it ( 'should jump over an optional step correctly' , ( ) => {
91+ const firstStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 1"] > button[goToStep]:nth-child(2)' ) ) . nativeElement ;
92+ const thirdStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 3"] > button[goToStep]' ) ) . nativeElement ;
93+
7894 expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
79- expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard > wizard-step .current' ) ) ) . toBe ( wizardTestFixture . debugElement . query ( By . css ( 'wizard > wizard-step:first-child' ) ) ) ;
95+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step.current' ) ) . nativeElement . title ) . toBe ( "Steptitle 1" ) ;
96+
97+ // click button
98+ firstStepGoToButton . click ( ) ;
99+ wizardTestFixture . detectChanges ( ) ;
100+
101+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 2 ) ;
102+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step.current' ) ) . nativeElement . title ) . toBe ( "Steptitle 3" ) ;
103+
104+ // click button
105+ thirdStepGoToButton . click ( ) ;
106+ wizardTestFixture . detectChanges ( ) ;
107+
108+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
109+ expect ( wizardTestFixture . debugElement . query ( By . css ( 'wizard-step.current' ) ) . nativeElement . title ) . toBe ( "Steptitle 1" ) ;
80110 } ) ;
81111
112+
82113 it ( 'should finalize step correctly' , ( ) => {
83- const firstStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 1"] > button[goToStep]' ) ) . nativeElement ;
84- const secondStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 2 "] > button[goToStep]' ) ) . nativeElement ;
114+ const firstStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 1"] > button[goToStep]:nth-child(2) ' ) ) . nativeElement ;
115+ const thirdStepGoToButton = wizardTestFixture . debugElement . query ( By . css ( 'wizard-step[title="Steptitle 3 "] > button[goToStep]' ) ) . nativeElement ;
85116
86117 expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
87118 expect ( wizardTest . eventLog ) . toEqual ( [ ] ) ;
@@ -90,14 +121,14 @@ describe('GoToStepDirective', () => {
90121 firstStepGoToButton . click ( ) ;
91122 wizardTestFixture . detectChanges ( ) ;
92123
93- expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 1 ) ;
124+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 2 ) ;
94125 expect ( wizardTest . eventLog ) . toEqual ( [ 'finalize 1' ] ) ;
95126
96127 // click button
97- secondStepGoToButton . click ( ) ;
128+ thirdStepGoToButton . click ( ) ;
98129 wizardTestFixture . detectChanges ( ) ;
99130
100131 expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
101- expect ( wizardTest . eventLog ) . toEqual ( [ 'finalize 1' , 'finalize 2 ' ] ) ;
132+ expect ( wizardTest . eventLog ) . toEqual ( [ 'finalize 1' , 'finalize 3 ' ] ) ;
102133 } ) ;
103134} ) ;
0 commit comments