mirror of
https://github.com/tenrok/vue-form-wizard.git
synced 2026-06-22 17:00:32 +03:00
Simplify some unit tests
Get rid of useless nextticks
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import VueFormWizard from './../../../src/index'
|
import VueFormWizard from './../../../src/index'
|
||||||
import {TabContent as WizardTab, WizardStep, FormWizard} from './../../../src/index'
|
import {TabContent as WizardTab, WizardStep, FormWizard} from './../../../src/index'
|
||||||
import {mount} from 'vue-test-utils'
|
import {mount, createLocalVue} from 'vue-test-utils'
|
||||||
import sinon from 'sinon'
|
import sinon from 'sinon'
|
||||||
|
import Vue from "vue";
|
||||||
|
|
||||||
Vue.use(VueFormWizard)
|
const localVue = createLocalVue()
|
||||||
|
localVue.use(VueFormWizard)
|
||||||
const startIndex = 0
|
const startIndex = 0
|
||||||
const twoStepWizard = {
|
const twoStepWizard = {
|
||||||
template: `<form-wizard :start-index="startIndex">
|
template: `<form-wizard :start-index="startIndex">
|
||||||
@@ -29,12 +30,12 @@ const twoStepWizard = {
|
|||||||
}
|
}
|
||||||
describe('FormWizard.vue', () => {
|
describe('FormWizard.vue', () => {
|
||||||
it('contains wizard class', () => {
|
it('contains wizard class', () => {
|
||||||
const wizard = mount(twoStepWizard)
|
const wizard = mount(twoStepWizard, {localVue})
|
||||||
wizard.hasClass('vue-form-wizard')
|
wizard.hasClass('vue-form-wizard')
|
||||||
})
|
})
|
||||||
it('renders steps', (done) => {
|
it('renders steps', () => {
|
||||||
const wizard = mount(twoStepWizard)
|
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)
|
||||||
@@ -43,53 +44,41 @@ 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', (done) => {
|
|
||||||
const wizard = mount(twoStepWizard)
|
|
||||||
Vue.nextTick(() => {
|
|
||||||
const tabs = wizard.findAll(WizardTab)
|
|
||||||
expect(tabs.length).to.equal(3)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('displays only one tab', (done) => {
|
|
||||||
const wizard = mount(twoStepWizard)
|
|
||||||
Vue.nextTick(() => {
|
|
||||||
const tabs = wizard.findAll(WizardTab).wrappers
|
|
||||||
const activeTabs = tabs.filter((tab) => tab.vm.active)
|
|
||||||
const inactiveTabs = tabs.filter((tab) => !tab.vm.active)
|
|
||||||
expect(activeTabs.length).to.equal(1)
|
|
||||||
|
|
||||||
inactiveTabs.forEach((tab) => {
|
})
|
||||||
expect(tab.hasStyle('display', 'none')).to.equal(true)
|
it('renders tabs', () => {
|
||||||
})
|
const wizard = mount(twoStepWizard, {localVue})
|
||||||
done()
|
const tabs = wizard.findAll(WizardTab)
|
||||||
|
expect(tabs.length).to.equal(3)
|
||||||
|
})
|
||||||
|
it('displays only one tab', () => {
|
||||||
|
const wizard = mount(twoStepWizard, {localVue})
|
||||||
|
const tabs = wizard.findAll(WizardTab).wrappers
|
||||||
|
const activeTabs = tabs.filter((tab) => tab.vm.active)
|
||||||
|
const inactiveTabs = tabs.filter((tab) => !tab.vm.active)
|
||||||
|
expect(activeTabs.length).to.equal(1)
|
||||||
|
|
||||||
|
inactiveTabs.forEach((tab) => {
|
||||||
|
expect(tab.hasStyle('display', 'none')).to.equal(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('starts at a given index', (done) => {
|
it('starts at a given index', () => {
|
||||||
const wizard = mount(twoStepWizard)
|
const wizard = mount(twoStepWizard, {localVue})
|
||||||
Vue.nextTick(() => {
|
const tabs = wizard.findAll(WizardTab)
|
||||||
const tabs = wizard.findAll(WizardTab)
|
const activeTab = tabs.at(startIndex)
|
||||||
const activeTab = tabs.at(startIndex)
|
expect(activeTab.vm.active).to.equal(true)
|
||||||
expect(activeTab.vm.active).to.equal(true)
|
const formWizard = wizard.find(FormWizard)
|
||||||
const formWizard = wizard.find(FormWizard)
|
expect(formWizard.vm.activeTabIndex).to.equal(startIndex)
|
||||||
expect(formWizard.vm.activeTabIndex).to.equal(startIndex)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
it('next tab is called', (done) => {
|
it('next tab is called', () => {
|
||||||
const wizard = mount(twoStepWizard)
|
const wizard = mount(twoStepWizard, {localVue})
|
||||||
const nextTabHandler = sinon.stub()
|
const nextTabHandler = sinon.stub()
|
||||||
const formWizard = wizard.find(FormWizard)
|
const formWizard = wizard.find(FormWizard)
|
||||||
formWizard.setMethods({nextTab: nextTabHandler})
|
formWizard.setMethods({nextTab: nextTabHandler})
|
||||||
Vue.nextTick(() => {
|
const nextButton = wizard.find('.wizard-footer-right span')
|
||||||
const nextButton = wizard.find('.wizard-footer-right span')
|
nextButton.trigger('click')
|
||||||
nextButton.trigger('click')
|
expect(nextTabHandler.called).to.equal(true)
|
||||||
expect(nextTabHandler.called).to.equal(true)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user