From a92155864528d5b09aa454fd219e78d0e6d4dd7b Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 19 May 2019 21:12:43 +0200 Subject: [PATCH 1/3] Fix eslint errors --- test/unit/specs/FormWizard.spec.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/unit/specs/FormWizard.spec.js b/test/unit/specs/FormWizard.spec.js index f09c99a..6d02bd7 100644 --- a/test/unit/specs/FormWizard.spec.js +++ b/test/unit/specs/FormWizard.spec.js @@ -20,7 +20,6 @@ const router = new VueRouter({ ] }) - const startIndex = 0 let validationMethod = sinon.stub() validationMethod.returns(true) @@ -407,7 +406,7 @@ describe('FormWizard.vue', () => { `, methods: { - validationMethod, + validationMethod } } }) @@ -428,14 +427,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) }) @@ -446,14 +445,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() }) - - }) }) }) From 48e4df5da59dac926c65041a534347cb2b3fd71e Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 19 May 2019 21:15:14 +0200 Subject: [PATCH 2/3] Extend unit test for wrapped slot to check for order of internal tabs --- test/unit/specs/FormWizard.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unit/specs/FormWizard.spec.js b/test/unit/specs/FormWizard.spec.js index 6d02bd7..7af38d1 100644 --- a/test/unit/specs/FormWizard.spec.js +++ b/test/unit/specs/FormWizard.spec.js @@ -129,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() }) }) From ae796e780b2b840b23f527b24bf81f0f6e1b85fb Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 19 May 2019 21:17:10 +0200 Subject: [PATCH 3/3] Add tabs without broken index lookup - call addTab() as soon as components are created to be more consistent --- src/components/FormWizard.vue | 5 +++-- src/components/TabContent.vue | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/FormWizard.vue b/src/components/FormWizard.vue index 41badb4..bb0a47a 100644 --- a/src/components/FormWizard.vue +++ b/src/components/FormWizard.vue @@ -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 diff --git a/src/components/TabContent.vue b/src/components/TabContent.vue index c8b61ae..f18ea89 100644 --- a/src/components/TabContent.vue +++ b/src/components/TabContent.vue @@ -65,7 +65,7 @@ return this.$parent.errorColor } }, - mounted () { + created () { this.addTab(this) }, destroyed () {