Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Feature/allow nested tab components #299

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/FormWizard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@
this.$emit('update:startIndex', nextIndex)
},
addTab (item) {
const index = this.$slots.default.indexOf(item.$vnode)
const index = this.tabs.length
item.tabId = `${item.title.replace(/ /g, '')}${index}`
this.tabs.splice(index, 0, item)
this.tabs.push(item)

// if a step is added before the current one, go to it
if (index < this.activeTabIndex + 1) {
this.maxStep = index
Expand Down
2 changes: 1 addition & 1 deletion src/components/TabContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
return this.$parent.errorColor
}
},
mounted () {
created () {
this.addTab(this)
},
destroyed () {
Expand Down
16 changes: 8 additions & 8 deletions test/unit/specs/FormWizard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const router = new VueRouter({
]
})


const startIndex = 0
let validationMethod = sinon.stub()
validationMethod.returns(true)
Expand Down Expand Up @@ -130,6 +129,9 @@ describe('FormWizard.vue', () => {
Vue.nextTick(() => {
const tabs = wizard.findAll(WizardTab)
expect(tabs.length).to.equal(3)
expect(wizard.vm.tabs[0].title).to.equal('Personal details')
expect(wizard.vm.tabs[1].title).to.equal('Additional Info')
expect(wizard.vm.tabs[2].title).to.equal('Last step')
done()
})
})
Expand Down Expand Up @@ -407,7 +409,7 @@ describe('FormWizard.vue', () => {
</tab-content>
</form-wizard>`,
methods: {
validationMethod,
validationMethod
}
}
})
Expand All @@ -428,14 +430,14 @@ describe('FormWizard.vue', () => {
wizardInstance.vm.nextTab()
wizardInstance.vm.prevTab()
expect(threeStepWizard.methods.validationMethod.should.have.been.called)
})
})
})
describe('with vue-router', ()=> {
describe('with vue-router', () => {
it('renders correct tab contents', () => {
const wizard = mount(routerWizard, {localVue, router})
const wizardInstance = wizard.find(FormWizard)
let tabs = wizardInstance.findAll(WizardTab)
let firstTab = tabs.at(0)
let firstTab = tabs.at(0)
expect(tabs.length).to.equal(3)
expect(firstTab.vm.route).to.equal(wizardInstance.vm.$route.path)
})
Expand All @@ -446,14 +448,12 @@ describe('FormWizard.vue', () => {
let tabs = wizardInstance.findAll(WizardTab)
wizardInstance.vm.activateAll()
wizardInstance.vm.$router.push('/second')
Vue.nextTick(()=> {
Vue.nextTick(() => {
let secondTab = tabs.at(1)
expect(secondTab.vm.route).to.equal(wizardInstance.vm.$route.path)
expect(secondTab.vm.active).to.equal(true)
done()
})


})
})
})