diff --git a/packages/actionsheet/src/actionsheet.vue b/packages/actionsheet/src/actionsheet.vue index a29ad121f..ea99cd0f1 100644 --- a/packages/actionsheet/src/actionsheet.vue +++ b/packages/actionsheet/src/actionsheet.vue @@ -56,6 +56,7 @@ export default { title: String, cancelText: String, overlay: { + type: Boolean, default: true }, closeOnClickOverlay: { diff --git a/packages/dialog/src/dialog.js b/packages/dialog/src/dialog.js index fa295ac15..5c13346cd 100644 --- a/packages/dialog/src/dialog.js +++ b/packages/dialog/src/dialog.js @@ -10,7 +10,7 @@ let dialogQueue = []; const defaultCallback = action => { if (currentDialog) { - let callback = currentDialog.callback; + const callback = currentDialog.callback; if (typeof callback === 'function') { callback(action); @@ -40,9 +40,9 @@ const showNextDialog = () => { if (!instance.value && dialogQueue.length > 0) { currentDialog = dialogQueue.shift(); - let options = currentDialog.options; + const options = currentDialog.options; - for (let prop in options) { + for (const prop in options) { if (options.hasOwnProperty(prop)) { instance[prop] = options[prop]; } diff --git a/packages/image-preview/src/image-preview.js b/packages/image-preview/src/image-preview.js index 93c62f354..5840d8d5e 100644 --- a/packages/image-preview/src/image-preview.js +++ b/packages/image-preview/src/image-preview.js @@ -1,6 +1,5 @@ import Vue from 'vue'; import ImagePreview from './image-preview.vue'; -import merge from 'src/utils/merge'; let instance; diff --git a/packages/swipe/src/input.js b/packages/swipe/src/input.js index 065ea6dd2..5fac0da18 100755 --- a/packages/swipe/src/input.js +++ b/packages/swipe/src/input.js @@ -24,7 +24,6 @@ Input.prototype = Object.create(new EventEmitter()); extend(Input.prototype, { bind: function(host) { - bindEvents(host, 'touchstart mousedown', this.onTouchStart); if (this.options.listenMoving) { bindEvents(window, 'touchmove mousemove', this.onTouchMove); @@ -74,11 +73,11 @@ extend(Input.prototype, { this.orgDirection = Math.abs(distX) > Math.abs(distY); } - this.emit('move', {x: distX, y: distY}, isEnd, e, {orgDirection: this.orgDirection}); + this.emit('move', { x: distX, y: distY }, isEnd, e, { orgDirection: this.orgDirection }); }, pointerEventToXY: function(e) { - var out = {x: 0, y: 0}; + var out = { x: 0, y: 0 }; var type = e.type; if (e.originalEvent) { e = e.originalEvent; diff --git a/packages/swipe/src/scroll.js b/packages/swipe/src/scroll.js index 94b325178..b42e60398 100755 --- a/packages/swipe/src/scroll.js +++ b/packages/swipe/src/scroll.js @@ -1,10 +1,10 @@ -import { EventEmitter, extend } from './utils' +import { EventEmitter, extend } from './utils'; const setElementsStyles = (elems, styles) => { Array.prototype.forEach.call(elems, item => { - extend(item.style, styles) - }) -} + extend(item.style, styles); + }); +}; function Scroll(wrapElem, options) { EventEmitter.apply(this, arguments); @@ -33,14 +33,14 @@ extend(Scroll.prototype, { }, update: function() { - const oldPages = this.pages + const oldPages = this.pages; this.pages = this.wrapElem.querySelectorAll('.zan-swipe-item'); if (oldPages && oldPages.length === this.pages.length) { const isSame = Array.prototype.every.call(this.pages, (elem, index) => { - return this.pages[index] === oldPages[index] - }) + return this.pages[index] === oldPages[index]; + }); if (isSame) { - return + return; } } var defaultStyle = { diff --git a/packages/swipe/src/spring_dummy.js b/packages/swipe/src/spring_dummy.js index 9d68751d6..c9d2ff9d2 100755 --- a/packages/swipe/src/spring_dummy.js +++ b/packages/swipe/src/spring_dummy.js @@ -1,4 +1,4 @@ -import { requestAnimationFrame, cancelAnimationFrame, EventEmitter, extend } from './utils' +import { requestAnimationFrame, cancelAnimationFrame, EventEmitter, extend } from './utils'; function SpringDummy(scroll, input, options) { var wrapElem = scroll.wrapElem; @@ -31,7 +31,6 @@ function SpringDummy(scroll, input, options) { }).on('bounceStart', function() { self.input.deaf(); }); - } SpringDummy.prototype = Object.create(new EventEmitter()); @@ -85,7 +84,6 @@ extend(SpringDummy.prototype, { addition = w * (tempOffsetPage - offsetPage + this.scroll.pages.length - 1); } } - } this.initTween(addition - dist, 150, 'bounce'); @@ -105,12 +103,12 @@ extend(SpringDummy.prototype, { function round() { elapse = new Date() - startTime; if (elapse > duration) { - self.emit(eventName, {x: dist}, true); + self.emit(eventName, { x: dist }, true); self.emit(eventName + 'End'); return; } - self.emit(eventName, {x: dist / duration * elapse}, false); + self.emit(eventName, { x: dist / duration * elapse }, false); self.tweenRid = requestAnimationFrame(round); } round(); diff --git a/packages/swipe/src/utils.js b/packages/swipe/src/utils.js index 1bcbebaf2..7ff020a59 100755 --- a/packages/swipe/src/utils.js +++ b/packages/swipe/src/utils.js @@ -18,11 +18,11 @@ EventEmitter.prototype = { if (arr) { arr.forEach(function(cb) { cb.apply(self, argus); - }) + }); } }, removeListener: function(name, fn) { - if (this.__events[name] == undefined) { + if (!this.__events[name]) { return; } let index; @@ -50,14 +50,14 @@ const cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnim }; const bindEvents = (elem, eventNames, fn) => { - eventNames = eventNames.split(/\s+/) - eventNames.forEach(eventName => elem.addEventListener(eventName, fn)) -} + eventNames = eventNames.split(/\s+/); + eventNames.forEach(eventName => elem.addEventListener(eventName, fn)); +}; const removeEvents = (elem, eventNames, fn) => { - eventNames = eventNames.split(/\s+/) - eventNames.forEach(eventName => elem.removeEventListener(eventName, fn)) -} + eventNames = eventNames.split(/\s+/); + eventNames.forEach(eventName => elem.removeEventListener(eventName, fn)); +}; export { extend, diff --git a/packages/toast/src/toast.js b/packages/toast/src/toast.js index eba907550..d5e1d39d8 100644 --- a/packages/toast/src/toast.js +++ b/packages/toast/src/toast.js @@ -13,7 +13,6 @@ const getInstance = () => { return instance; }; - const removeDom = event => { if (event.target.parentNode) { event.target.parentNode.removeChild(event.target); @@ -23,7 +22,7 @@ const removeDom = event => { var Toast = (options = {}) => { const duration = options.duration || 3000; - let instance = getInstance(); + const instance = getInstance(); instance.closed = false; clearTimeout(instance.timer); instance.type = options.type ? options.type : 'text'; @@ -71,6 +70,6 @@ Toast.fail = (options) => { Toast.clear = () => { if (instance) instance.clear(); -} +}; export default Toast; diff --git a/src/mixins/popup/popup-context.js b/src/mixins/popup/popup-context.js index 4c6fe55eb..a4cccf692 100644 --- a/src/mixins/popup/popup-context.js +++ b/src/mixins/popup/popup-context.js @@ -2,7 +2,7 @@ import merge from 'src/utils/merge'; let context; if (window && window.popupContext) { - context = window.popupContext + context = window.popupContext; } const DEFAULT_CONTEXT = { @@ -11,7 +11,7 @@ const DEFAULT_CONTEXT = { hasModal: false, instances: {}, modalStack: [] -} +}; context = window.popupContext = merge({}, DEFAULT_CONTEXT, context); diff --git a/src/mixins/popup/popup-manager.js b/src/mixins/popup/popup-manager.js index 90d0bc05d..eb33ecab9 100644 --- a/src/mixins/popup/popup-manager.js +++ b/src/mixins/popup/popup-manager.js @@ -36,14 +36,14 @@ const PopupManager = { register(id, instance) { if (id && instance) { - let instances = PopupContext.getContext('instances'); + const instances = PopupContext.getContext('instances'); instances[id] = instance; } }, deregister(id) { if (id) { - let instances = PopupContext.getContext('instances'); + const instances = PopupContext.getContext('instances'); instances[id] = null; delete instances[id]; } diff --git a/test/unit/specs/actionsheet.spec.js b/test/unit/specs/actionsheet.spec.js index dcf387fb8..ca4e28ae1 100644 --- a/test/unit/specs/actionsheet.spec.js +++ b/test/unit/specs/actionsheet.spec.js @@ -1,3 +1,4 @@ +import Vue from 'vue'; import ActionSheet from 'packages/actionsheet'; import { mount } from 'avoriaz'; @@ -13,5 +14,103 @@ describe('ActionSheet', () => { }); expect(wrapper.hasClass('zan-actionsheet')).to.be.true; + expect(wrapper.contains('.zan-actionsheet__list')).to.be.true; + expect(wrapper.instance().actions.length).to.equal(0); + expect(wrapper.instance().overlay).to.be.true; + expect(wrapper.instance().closeOnClickOverlay).to.be.true; + }); + + it('create displayed actionsheet', () => { + wrapper = mount(ActionSheet, { + propsData: { + value: true + } + }); + + expect(wrapper.instance().currentValue).to.be.true; + }); + + it('create title type actionsheet', () => { + wrapper = mount(ActionSheet, { + propsData: { + title: 'test' + } + }); + + expect(wrapper.hasClass('zan-actionsheet--withtitle')).to.be.true; + expect(wrapper.contains('.zan-actionsheet__header')).to.be.true; + expect(wrapper.contains('.zan-actionsheet__content')).to.be.true; + }); + + it('create actions actionsheet', () => { + wrapper = mount(ActionSheet, { + propsData: { + actions: [ + { + name: '有赞E卡', + subname: '(剩余260.50元)' + }, + { + name: '信用卡支付', + loading: true + } + ] + } + }); + + const actionItems = wrapper.find('.zan-actionsheet__item'); + + expect(actionItems.length).to.equal(2); + expect(actionItems[0].contains('.zan-actionsheet__name')).to.be.true; + expect(actionItems[0].contains('.zan-actionsheet__subname')).to.be.true; + expect(actionItems[1].contains('.zan-actionsheet__loading')).to.be.true; + }); + + it('handle actionsheet item click with callback', () => { + let called = false; + wrapper = mount(ActionSheet, { + propsData: { + actions: [ + { + name: '有赞E卡', + callback: () => { + called = true; + } + } + ] + } + }); + + const actionItem = wrapper.find('.zan-actionsheet__item')[0]; + actionItem.simulate('click'); + expect(called).to.be.true; + }); + + it('create actionsheet with cancel button', () => { + wrapper = mount(ActionSheet, { + propsData: { + cancelText: 'cancel' + } + }); + + const cancelButton = wrapper.find('.zan-actionsheet__button')[0]; + expect(wrapper.contains('.zan-actionsheet__button')).to.be.true; + expect(cancelButton.text()).to.equal('cancel'); + }); + + it('toggle actionsheet value', () => { + wrapper = mount(ActionSheet, { + propsData: { + value: false + } + }); + + expect(wrapper.data().currentValue).to.be.false; + wrapper.vm.value = true; + wrapper.update(); + Vue.nextTick(() => { + expect(wrapper.data().currentValue).to.be.true; + done(); + }); }); }); diff --git a/test/unit/specs/switch.spec.js b/test/unit/specs/switch.spec.js index 66ebe95f9..8477da46b 100644 --- a/test/unit/specs/switch.spec.js +++ b/test/unit/specs/switch.spec.js @@ -110,7 +110,6 @@ describe('Switch', () => { }); it('toggle switch value from v-model', function(done) { - let checked = false; wrapper = mount(Switch, { propsData: { value: false