@@ -69,10 +69,11 @@ describe('WizardNavigationBarComponent', () => {
6969 expect ( navBar . query ( By . css ( 'li.optional' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
7070 expect ( navBar . queryAll ( By . css ( 'li.optional' ) ) . length ) . toBe ( 1 ) ;
7171
72- // only the third step is marked as default (neither done, current or optional )
72+ // the second and third step is marked as default (neither done or current )
7373 expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBeTruthy ( ) ;
74- expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(3)' ) ) ) ;
75- expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 1 ) ;
74+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) [ 0 ] ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
75+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) [ 1 ] ) . toBe ( navBar . query ( By . css ( 'li:nth-child(3)' ) ) ) ;
76+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 2 ) ;
7677 } ) ;
7778
7879 it ( 'should show the second step correctly' , ( ) => {
@@ -98,7 +99,7 @@ describe('WizardNavigationBarComponent', () => {
9899 // no step is marked as optional, because the optional step is the current step
99100 expect ( navBar . query ( By . css ( 'li.optional' ) ) ) . toBeNull ( ) ;
100101
101- // only the third step is marked as default (neither done, current or optional )
102+ // only the third step is marked as default (neither done or current )
102103 expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBeTruthy ( ) ;
103104 expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(3)' ) ) ) ;
104105 expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 1 ) ;
@@ -120,8 +121,8 @@ describe('WizardNavigationBarComponent', () => {
120121
121122 // the first and second step should be marked as done
122123 expect ( navBar . query ( By . css ( 'li.done' ) ) ) . toBeTruthy ( ) ;
123- expect ( navBar . query ( By . css ( 'li.done:first-child ' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(1)' ) ) ) ;
124- expect ( navBar . query ( By . css ( 'li.done:nth-child(2) ' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
124+ expect ( navBar . queryAll ( By . css ( 'li.done' ) ) [ 0 ] ) . toBe ( navBar . query ( By . css ( 'li:nth-child(1)' ) ) ) ;
125+ expect ( navBar . queryAll ( By . css ( 'li.done' ) ) [ 1 ] ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
125126 expect ( navBar . queryAll ( By . css ( 'li.done' ) ) . length ) . toBe ( 2 ) ;
126127
127128 // no step is marked as editing
@@ -159,8 +160,10 @@ describe('WizardNavigationBarComponent', () => {
159160 expect ( navBar . query ( By . css ( 'li.optional' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
160161 expect ( navBar . queryAll ( By . css ( 'li.optional' ) ) . length ) . toBe ( 1 ) ;
161162
162- // no step is marked as default (neither done, current or optional)
163- expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBeNull ( ) ;
163+ // the second step is marked as default (neither done nor current)
164+ expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBeTruthy ( ) ;
165+ expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
166+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 1 ) ;
164167 } ) ;
165168
166169 it ( 'should show the first step correctly, after going back from the second step to the first step' , ( ) => {
@@ -188,10 +191,11 @@ describe('WizardNavigationBarComponent', () => {
188191 expect ( navBar . query ( By . css ( 'li.optional' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
189192 expect ( navBar . queryAll ( By . css ( 'li.optional' ) ) . length ) . toBe ( 1 ) ;
190193
191- // no step is marked as default (neither done, current or optional )
194+ // the second and third step is marked as default (neither done or current )
192195 expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBeTruthy ( ) ;
193- expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(3)' ) ) ) ;
194- expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 1 ) ;
196+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) [ 0 ] ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
197+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) [ 1 ] ) . toBe ( navBar . query ( By . css ( 'li:nth-child(3)' ) ) ) ;
198+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 2 ) ;
195199 } ) ;
196200
197201 it ( 'should show the first step correctly, after first jumping from the first to the third step and then back from the third step to the first step' , ( ) => {
@@ -219,10 +223,11 @@ describe('WizardNavigationBarComponent', () => {
219223 expect ( navBar . query ( By . css ( 'li.optional' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
220224 expect ( navBar . queryAll ( By . css ( 'li.optional' ) ) . length ) . toBe ( 1 ) ;
221225
222- // the third step is marked as default (neither done, current or optional )
226+ // the second and third step is marked as default (neither done or current )
223227 expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBeTruthy ( ) ;
224- expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(3)' ) ) ) ;
225- expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 1 ) ;
228+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) [ 0 ] ) . toBe ( navBar . query ( By . css ( 'li:nth-child(2)' ) ) ) ;
229+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) [ 1 ] ) . toBe ( navBar . query ( By . css ( 'li:nth-child(3)' ) ) ) ;
230+ expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 2 ) ;
226231 } ) ;
227232
228233 it ( 'should show the second step correctly, after first jumping from the first to the third step and then back from the third step to the second step' , ( ) => {
@@ -250,9 +255,69 @@ describe('WizardNavigationBarComponent', () => {
250255 // no step is marked as optional, because the optional step is the current step
251256 expect ( navBar . query ( By . css ( 'li.optional' ) ) ) . toBeNull ( ) ;
252257
253- // the third step is marked as default (neither done, current or optional )
258+ // the third step is marked as default (neither done or current )
254259 expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBeTruthy ( ) ;
255260 expect ( navBar . query ( By . css ( 'li.default' ) ) ) . toBe ( navBar . query ( By . css ( 'li:nth-child(3)' ) ) ) ;
256261 expect ( navBar . queryAll ( By . css ( 'li.default' ) ) . length ) . toBe ( 1 ) ;
257262 } ) ;
263+
264+ it ( 'should move back to the first step from the second step, after clicking on the corresponding link' , ( ) => {
265+ const goToFirstStepLink = wizardTestFixture . debugElement . query ( By . css ( 'li:nth-child(1) > a' ) ) . nativeElement ;
266+
267+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
268+
269+ // go to the second step
270+ wizardTest . wizard . goToNextStep ( ) ;
271+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 1 ) ;
272+
273+ // go back to the first step
274+ goToFirstStepLink . click ( ) ;
275+ wizardTestFixture . detectChanges ( ) ;
276+
277+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
278+ } ) ;
279+
280+ it ( 'should move back to the first step from the third step, after clicking on the corresponding link' , ( ) => {
281+ const goToFirstStepLink = wizardTestFixture . debugElement . query ( By . css ( 'li:nth-child(1) > a' ) ) . nativeElement ;
282+
283+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
284+
285+ // go to the second step
286+ wizardTest . wizard . goToStep ( 2 ) ;
287+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 2 ) ;
288+
289+ // go back to the first step
290+ goToFirstStepLink . click ( ) ;
291+ wizardTestFixture . detectChanges ( ) ;
292+
293+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
294+ } ) ;
295+
296+ it ( 'should move back to the second step from the third step, after clicking on the corresponding link' , ( ) => {
297+ const goToSecondStepLink = wizardTestFixture . debugElement . query ( By . css ( 'li:nth-child(2) > a' ) ) . nativeElement ;
298+
299+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
300+
301+ // go to the second step
302+ wizardTest . wizard . goToStep ( 2 ) ;
303+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 2 ) ;
304+
305+ // go back to the first step
306+ goToSecondStepLink . click ( ) ;
307+ wizardTestFixture . detectChanges ( ) ;
308+
309+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 1 ) ;
310+ } ) ;
311+
312+ it ( 'should not move to the second step from the first step, after clicking on the corresponding link' , ( ) => {
313+ const goToFirstStepLink = wizardTestFixture . debugElement . query ( By . css ( 'li:nth-child(1)' ) ) ;
314+ const goToSecondStepLink = wizardTestFixture . debugElement . query ( By . css ( 'li:nth-child(2)' ) ) ;
315+ const goToThirdStepLink = wizardTestFixture . debugElement . query ( By . css ( 'li:nth-child(3)' ) ) ;
316+
317+ expect ( wizardTest . wizard . currentStepIndex ) . toBe ( 0 ) ;
318+ // links contain a class that is not clickable (contains "pointer-events: none;")
319+ expect ( goToFirstStepLink . classes . hasOwnProperty ( 'current' ) ) . toBeTruthy ( 'First step label is clickable' ) ;
320+ expect ( goToSecondStepLink . classes . hasOwnProperty ( 'default' ) ) . toBeTruthy ( 'Second step label is clickable' ) ;
321+ expect ( goToThirdStepLink . classes . hasOwnProperty ( 'default' ) ) . toBeTruthy ( 'Third step label is clickable' ) ;
322+ } ) ;
258323} ) ;
0 commit comments