mirror of
https://github.com/tenrok/vue-form-wizard.git
synced 2026-06-23 21:00:33 +03:00
Use provide/inject to register tabs for layout flexibility
This commit is contained in:
@@ -7,8 +7,6 @@
|
|||||||
<form-wizard @on-complete="onComplete"
|
<form-wizard @on-complete="onComplete"
|
||||||
@on-change="handleChange"
|
@on-change="handleChange"
|
||||||
:start-index.sync="activeIndex"
|
:start-index.sync="activeIndex"
|
||||||
layout="vertical"
|
|
||||||
steps-classes="steps-size"
|
|
||||||
color="#e74c3c">
|
color="#e74c3c">
|
||||||
<tab-content v-for="tab in tabs" :title="tab" :key="tab">{{tab}}</tab-content>
|
<tab-content v-for="tab in tabs" :title="tab" :key="tab">{{tab}}</tab-content>
|
||||||
<transition name="fade" mode="out-in">
|
<transition name="fade" mode="out-in">
|
||||||
|
|||||||
@@ -157,6 +157,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
provide () {
|
||||||
|
return {
|
||||||
|
addTab: this.addTab,
|
||||||
|
removeTab: this.removeTab
|
||||||
|
}
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
activeTabIndex: 0,
|
activeTabIndex: 0,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
default: () => {}
|
default: () => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
inject: ['addTab', 'removeTab'],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
active: false,
|
active: false,
|
||||||
@@ -57,13 +58,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.$parent.addTab(this)
|
this.addTab(this)
|
||||||
},
|
},
|
||||||
destroyed () {
|
destroyed () {
|
||||||
if (this.$el && this.$el.parentNode) {
|
if (this.$el && this.$el.parentNode) {
|
||||||
this.$el.parentNode.removeChild(this.$el)
|
this.$el.parentNode.removeChild(this.$el)
|
||||||
}
|
}
|
||||||
this.$parent.removeTab(this)
|
this.removeTab(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import VueFormWizard from './../../../src/index'
|
import VueFormWizard, {TabContent as WizardTab, WizardStep, FormWizard} from './../../../src/index'
|
||||||
import {TabContent as WizardTab, WizardStep, FormWizard} from './../../../src/index'
|
|
||||||
import {mount, createLocalVue} from 'vue-test-utils'
|
import {mount, createLocalVue} from 'vue-test-utils'
|
||||||
import sinon from 'sinon'
|
import sinon from 'sinon'
|
||||||
import Vue from "vue";
|
import Vue from 'vue'
|
||||||
|
|
||||||
const localVue = createLocalVue()
|
const localVue = createLocalVue()
|
||||||
localVue.use(VueFormWizard)
|
localVue.use(VueFormWizard)
|
||||||
@@ -28,14 +27,30 @@ const twoStepWizard = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const divSlot = `<div>
|
||||||
|
<tab-content title="Personal details"
|
||||||
|
icon="ti-user">
|
||||||
|
First
|
||||||
|
</tab-content>
|
||||||
|
<tab-content title="Additional Info"
|
||||||
|
icon="ti-settings">
|
||||||
|
Second
|
||||||
|
</tab-content>
|
||||||
|
<tab-content title="Last step"
|
||||||
|
icon="ti-settings">
|
||||||
|
Third
|
||||||
|
</tab-content>
|
||||||
|
</div>`
|
||||||
|
|
||||||
describe('FormWizard.vue', () => {
|
describe('FormWizard.vue', () => {
|
||||||
it('contains wizard class', () => {
|
it('contains wizard class', () => {
|
||||||
const wizard = mount(twoStepWizard, {localVue})
|
const wizard = mount(twoStepWizard, {localVue})
|
||||||
wizard.hasClass('vue-form-wizard')
|
wizard.hasClass('vue-form-wizard')
|
||||||
})
|
})
|
||||||
it('renders steps', () => {
|
it('renders steps', (done) => {
|
||||||
const wizard = mount(twoStepWizard, {localVue})
|
const wizard = mount(twoStepWizard, {localVue})
|
||||||
Vue.nextTick(()=>{
|
Vue.nextTick(() => {
|
||||||
const steps = wizard.findAll(WizardStep)
|
const steps = wizard.findAll(WizardStep)
|
||||||
const firsStep = steps.at(0)
|
const firsStep = steps.at(0)
|
||||||
expect(steps.length).to.equal(3)
|
expect(steps.length).to.equal(3)
|
||||||
@@ -44,8 +59,8 @@ describe('FormWizard.vue', () => {
|
|||||||
expect(stepTitle.is('span')).to.equal(true)
|
expect(stepTitle.is('span')).to.equal(true)
|
||||||
const stepText = stepTitle.text().trim()
|
const stepText = stepTitle.text().trim()
|
||||||
expect(stepText).to.equal('Personal details')
|
expect(stepText).to.equal('Personal details')
|
||||||
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
it('renders tabs', () => {
|
it('renders tabs', () => {
|
||||||
const wizard = mount(twoStepWizard, {localVue})
|
const wizard = mount(twoStepWizard, {localVue})
|
||||||
@@ -81,4 +96,17 @@ describe('FormWizard.vue', () => {
|
|||||||
expect(nextTabHandler.called).to.equal(true)
|
expect(nextTabHandler.called).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('renders tab wrapped in another element', done => {
|
||||||
|
const wizard = mount(FormWizard, {
|
||||||
|
localVue,
|
||||||
|
slots: {
|
||||||
|
default: divSlot
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
const tabs = wizard.findAll(WizardTab)
|
||||||
|
expect(tabs.length).to.equal(3)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user