@@ -2,9 +2,25 @@ import VueFormWizard, {TabContent as WizardTab, WizardStep, FormWizard} from './
2
2
import { mount , createLocalVue } from 'vue-test-utils'
3
3
import sinon from 'sinon'
4
4
import Vue from 'vue'
5
+ import VueRouter from 'vue-router'
5
6
6
7
const localVue = createLocalVue ( )
7
8
localVue . 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
+
8
24
const startIndex = 0
9
25
let validationMethod = sinon . stub ( )
10
26
validationMethod . returns ( true )
@@ -16,6 +32,7 @@ let initialWizard = {
16
32
My first tab content
17
33
</tab-content>
18
34
<tab-content title="Additional Info"
35
+ v-if="showSecondStep"
19
36
icon="ti-settings">
20
37
My second tab content
21
38
</tab-content>
@@ -27,12 +44,31 @@ let initialWizard = {
27
44
data ( ) {
28
45
return {
29
46
startIndex : startIndex ,
30
- showLastStep : true
47
+ showLastStep : true ,
48
+ showSecondStep : true
31
49
}
32
50
}
33
51
}
34
52
let threeStepWizard = initialWizard
35
53
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
+
36
72
const divSlot = `<div>
37
73
<tab-content title="Personal details"
38
74
icon="ti-user">
@@ -108,6 +144,25 @@ describe('FormWizard.vue', () => {
108
144
done ( )
109
145
} )
110
146
} )
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
+ } )
111
166
} )
112
167
113
168
it ( 'warns when start index is incorrect' , ( ) => {
@@ -137,6 +192,25 @@ describe('FormWizard.vue', () => {
137
192
expect ( wizardInstance . vm . activeTabIndex ) . to . equal ( 0 )
138
193
} )
139
194
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
+
140
214
describe ( 'navigation' , ( ) => {
141
215
it ( 'next tab is called' , ( ) => {
142
216
const wizard = mount ( threeStepWizard , { localVue} )
@@ -194,7 +268,7 @@ describe('FormWizard.vue', () => {
194
268
it ( 'active tab is prev when current active tab is removed' , ( done ) => {
195
269
const wizard = mount ( threeStepWizard , { localVue} )
196
270
const wizardInstance = wizard . find ( FormWizard )
197
- //navigate to last tab
271
+ // navigate to last tab
198
272
wizardInstance . vm . nextTab ( )
199
273
wizardInstance . vm . nextTab ( )
200
274
const tabs = wizard . findAll ( WizardTab )
@@ -218,8 +292,8 @@ describe('FormWizard.vue', () => {
218
292
wizard . trigger ( 'keyup.left' )
219
293
expect ( wizardInstance . vm . activeTabIndex ) . to . equal ( 2 )
220
294
} )
221
-
222
295
} )
296
+
223
297
describe ( 'emits' , ( ) => {
224
298
it ( 'on-complete upon last step' , ( ) => {
225
299
const wizard = mount ( threeStepWizard , { localVue} )
@@ -232,8 +306,6 @@ describe('FormWizard.vue', () => {
232
306
expect ( wizardInstance . emitted ( ) [ 'on-complete' ] . length ) . to . equal ( 1 )
233
307
} )
234
308
} )
235
-
236
-
237
309
describe ( 'validation with' , ( ) => {
238
310
beforeEach ( ( ) => {
239
311
threeStepWizard = {
@@ -314,6 +386,30 @@ describe('FormWizard.vue', () => {
314
386
} )
315
387
} )
316
388
} )
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
+ } )
317
411
318
412
413
+ } )
414
+ } )
319
415
} )
0 commit comments