import { createVue, triggerEvent, destroyVM } from '../util'; describe('Tooltip', () => { let vm; afterEach(() => { destroyVM(vm); }); it('create', done => { vm = createVue(` `); vm.$nextTick(_ => { expect(vm.$refs.tooltip.popperVM.$el).to.have.property('textContent', '提示文字'); done(); }); }); it('custom popper class', done => { vm = createVue(` `); vm.$nextTick(_ => { expect(vm.$refs.tooltip.popperVM.$el.classList.contains('custom-popper')).to.true; done(); }); }); describe('manual', () => { const vm = createVue({ template: ` `, data() { return { show: false }; } }, true); const tooltip = vm.$refs.tooltip; it('showPopper is false', () => { triggerEvent(tooltip.$el, 'mouseenter'); expect(tooltip.showPopper).to.false; }); it('show', done => { vm.show = true; vm.$nextTick(_ => { expect(tooltip.showPopper).to.true; done(); }); }); it('still show when trigger mouseleave', () => { triggerEvent(tooltip.$el, 'mouseleave'); expect(tooltip.showPopper).to.true; }); it('hidden', done => { vm.show = false; vm.$nextTick(_ => { expect(tooltip.showPopper).to.false; done(); }); }); }); describe('hover', () => { const vm = createVue(` `); const tooltip = vm.$refs.tooltip; triggerEvent(tooltip.$el, 'mouseenter'); it('popperElm is exist', () => expect(tooltip.popperElm).to.exist); it('showPopper is true', () => expect(tooltip.showPopper).to.true); it('close popper', done => { triggerEvent(tooltip.$el, 'mouseleave'); setTimeout(() => { expect(tooltip.showPopper).to.false; done(); }, 300); }); }); it('light mode', done => { vm = createVue(` `); vm.$nextTick(_ => { expect(vm.$refs.tooltip.popperVM.$el.classList.contains('is-light')).to.exist; done(); }); }); it('hide after', done => { vm = createVue(` `); const tooltip = vm.$refs.tooltip; vm.$nextTick(_ => { triggerEvent(tooltip.$el, 'mouseenter'); setTimeout(() => { expect(tooltip.showPopper).to.be.true; setTimeout(() => { expect(tooltip.showPopper).to.be.false; done(); }, 300); }, 100); }); }); it('remove focus', done => { vm = createVue(` `); const tooltip = vm.$refs.tooltip; vm.$nextTick(_ => { triggerEvent(tooltip.$el, 'mouseenter'); setTimeout(() => { tooltip.focusing = true; tooltip.$el.click(); setTimeout(() => { expect(tooltip.showPopper).to.be.false; done(); }, 300); }, 100); }); }); it('reference element focus', done => { vm = createVue(` `); const tooltip = vm.$refs.tooltip; vm.$nextTick(_ => { triggerEvent(tooltip.$el, 'focus'); setTimeout(() => { expect(tooltip.showPopper).to.be.true; expect(tooltip.focusing).to.be.true; triggerEvent(tooltip.$el, 'blur'); setTimeout(() => { expect(tooltip.showPopper).to.be.false; expect(tooltip.focusing).to.be.false; done(); }, 300); }, 100); }); }); it('custom tabindex', () => { vm = createVue(` `, true); expect(vm.$el.getAttribute('tabindex')).to.be.equal('-1'); }); });