@@ -2,9 +2,25 @@ import VueFormWizard, {TabContent as WizardTab, WizardStep, FormWizard} from './
22import { mount , createLocalVue } from 'vue-test-utils'
33import sinon from 'sinon'
44import Vue from 'vue'
5+ import VueRouter from 'vue-router'
56
67const localVue = createLocalVue ( )
78localVue . use ( VueFormWizard )
9+ localVue . use ( VueRouter )
10+
11+ const First = { template : '<div>First page</div>' }
12+ const Second = { template : '<div>Second page</div>' }
13+ const Third = { template : '<div>Third page</div>' }
14+
15+ const router = new VueRouter ( {
16+ routes : [
17+ { path : '/first' , component : First } ,
18+ { path : '/second' , component : Second } ,
19+ { path : '/third' , component : Third }
20+ ]
21+ } )
22+
23+
824const startIndex = 0
925let validationMethod = sinon . stub ( )
1026validationMethod . returns ( true )
@@ -16,6 +32,7 @@ let initialWizard = {
1632 My first tab content
1733 </tab-content>
1834 <tab-content title="Additional Info"
35+ v-if="showSecondStep"
1936 icon="ti-settings">
2037 My second tab content
2138 </tab-content>
@@ -27,12 +44,31 @@ let initialWizard = {
2744 data ( ) {
2845 return {
2946 startIndex : startIndex ,
30- showLastStep : true
47+ showLastStep : true ,
48+ showSecondStep : true
3149 }
3250 }
3351}
3452let threeStepWizard = initialWizard
3553
54+ let routerWizard = {
55+ template : `<form-wizard>
56+ <tab-content title="Personal details"
57+ route="/first"
58+ icon="ti-user">
59+ </tab-content>
60+ <tab-content title="Additional Info"
61+ route="/second"
62+ icon="ti-settings">
63+ </tab-content>
64+ <tab-content title="Last step"
65+ route="/third"
66+ icon="ti-check">
67+ </tab-content>
68+ <router-view></router-view>
69+ </form-wizard>`
70+ }
71+
3672const divSlot = `<div>
3773 <tab-content title="Personal details"
3874 icon="ti-user">
@@ -108,6 +144,25 @@ describe('FormWizard.vue', () => {
108144 done ( )
109145 } )
110146 } )
147+ it ( 'tabs in the same order when a tab before the active tab is removed' , ( done ) => {
148+ const wizard = mount ( threeStepWizard , { localVue} )
149+ const wizardInstance = wizard . find ( FormWizard )
150+ const tabs = wizard . findAll ( WizardTab )
151+ expect ( tabs . length ) . to . equal ( 3 )
152+ // navigate to last step
153+ wizardInstance . vm . nextTab ( )
154+ wizardInstance . vm . nextTab ( )
155+ // remove second step
156+ wizard . setData ( { showSecondStep : false } )
157+ Vue . nextTick ( ( ) => {
158+ const newTabs = wizard . findAll ( WizardTab )
159+ expect ( newTabs . length ) . to . equal ( 2 )
160+ const lastTab = newTabs . at ( 1 )
161+ expect ( lastTab . vm . active ) . to . equal ( true )
162+ expect ( lastTab . vm . title ) . to . equal ( 'Last step' )
163+ done ( )
164+ } )
165+ } )
111166 } )
112167
113168 it ( 'warns when start index is incorrect' , ( ) => {
@@ -137,6 +192,25 @@ describe('FormWizard.vue', () => {
137192 expect ( wizardInstance . vm . activeTabIndex ) . to . equal ( 0 )
138193 } )
139194
195+ it ( 'activates all steps' , ( done ) => {
196+ const wizard = mount ( threeStepWizard , { localVue} )
197+ const wizardInstance = wizard . find ( FormWizard )
198+ let tabs = wizard . findAll ( WizardTab )
199+ let maxStepIndex = tabs . length - 1
200+ wizardInstance . vm . activateAll ( )
201+
202+ Vue . nextTick ( ( ) => {
203+ expect ( wizardInstance . vm . activeTabIndex ) . to . equal ( 0 )
204+ expect ( wizardInstance . vm . maxStep ) . to . equal ( maxStepIndex )
205+ // direct navigation should be available
206+ wizardInstance . vm . navigateToTab ( maxStepIndex )
207+ expect ( wizardInstance . vm . activeTabIndex ) . to . equal ( maxStepIndex )
208+ let steps = wizardInstance . findAll ( '.wizard-icon-circle' )
209+ expect ( steps . hasClass ( 'checked' ) ) . to . equal ( true )
210+ done ( )
211+ } )
212+ } )
213+
140214 describe ( 'navigation' , ( ) => {
141215 it ( 'next tab is called' , ( ) => {
142216 const wizard = mount ( threeStepWizard , { localVue} )
@@ -194,7 +268,7 @@ describe('FormWizard.vue', () => {
194268 it ( 'active tab is prev when current active tab is removed' , ( done ) => {
195269 const wizard = mount ( threeStepWizard , { localVue} )
196270 const wizardInstance = wizard . find ( FormWizard )
197- //navigate to last tab
271+ // navigate to last tab
198272 wizardInstance . vm . nextTab ( )
199273 wizardInstance . vm . nextTab ( )
200274 const tabs = wizard . findAll ( WizardTab )
@@ -218,8 +292,8 @@ describe('FormWizard.vue', () => {
218292 wizard . trigger ( 'keyup.left' )
219293 expect ( wizardInstance . vm . activeTabIndex ) . to . equal ( 2 )
220294 } )
221-
222295 } )
296+
223297 describe ( 'emits' , ( ) => {
224298 it ( 'on-complete upon last step' , ( ) => {
225299 const wizard = mount ( threeStepWizard , { localVue} )
@@ -232,8 +306,6 @@ describe('FormWizard.vue', () => {
232306 expect ( wizardInstance . emitted ( ) [ 'on-complete' ] . length ) . to . equal ( 1 )
233307 } )
234308 } )
235-
236-
237309 describe ( 'validation with' , ( ) => {
238310 beforeEach ( ( ) => {
239311 threeStepWizard = {
@@ -314,6 +386,30 @@ describe('FormWizard.vue', () => {
314386 } )
315387 } )
316388 } )
389+ describe ( 'with vue-router' , ( ) => {
390+ it ( 'renders correct tab contents' , ( ) => {
391+ const wizard = mount ( routerWizard , { localVue, router} )
392+ const wizardInstance = wizard . find ( FormWizard )
393+ let tabs = wizardInstance . findAll ( WizardTab )
394+ let firstTab = tabs . at ( 0 )
395+ expect ( tabs . length ) . to . equal ( 3 )
396+ expect ( firstTab . vm . route ) . to . equal ( wizardInstance . vm . $route . path )
397+ } )
398+
399+ it ( 'adapts to valid route changes when steps are visited' , ( done ) => {
400+ const wizard = mount ( routerWizard , { localVue, router} )
401+ const wizardInstance = wizard . find ( FormWizard )
402+ let tabs = wizardInstance . findAll ( WizardTab )
403+ wizardInstance . vm . activateAll ( )
404+ wizardInstance . vm . $router . push ( '/second' )
405+ Vue . nextTick ( ( ) => {
406+ let secondTab = tabs . at ( 1 )
407+ expect ( secondTab . vm . route ) . to . equal ( wizardInstance . vm . $route . path )
408+ expect ( secondTab . vm . active ) . to . equal ( true )
409+ done ( )
410+ } )
317411
318412
413+ } )
414+ } )
319415} )
0 commit comments