diff --git a/docs/src/components/page-header.vue b/docs/src/components/page-header.vue index c61b15fdd..901c4e78e 100644 --- a/docs/src/components/page-header.vue +++ b/docs/src/components/page-header.vue @@ -51,7 +51,7 @@ export default { window.addEventListener('scroll', () => { clearTimeout(timer); const scrollTop = document.body.scrollTop || document.documentElement.scrollTop; - let timer = setTimeout(() => { + timer = setTimeout(() => { _this.scrollTop = scrollTop; }, 500); }); diff --git a/package.json b/package.json index 5ea301b81..7ef2b5063 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "cp-cli": "^1.0.2", "cross-env": "^3.1.3", "css-loader": "^0.24.0", + "eslint-loader": "^1.7.1", "extract-text-webpack-plugin": "^2.0.0-beta.5", "felint": "^0.5.0-alpha.3", "file-loader": "^0.9.0", diff --git a/test/unit/specs/quantity.spec.js b/test/unit/specs/quantity.spec.js index 1a77ade48..43168f6d9 100644 --- a/test/unit/specs/quantity.spec.js +++ b/test/unit/specs/quantity.spec.js @@ -9,8 +9,108 @@ describe('Quantity', () => { }); it('create a quantity', () => { - wrapper = mount(Quantity); + wrapper = mount(Quantity, { + propsData: { + defaultValue: 1 + } + }); expect(wrapper.hasClass('zan-quantity')).to.be.true; + expect(wrapper.data().currentValue).to.equal(1); + + const plusButton = wrapper.find('.zan-quantity__plus')[0]; + plusButton.simulate('click'); + + expect(wrapper.data().currentValue).to.equal(2); + + const minusButton = wrapper.find('.zan-quantity__minus')[0]; + minusButton.simulate('click'); + expect(wrapper.data().currentValue).to.equal(1); + }); + + it('create a disabled quantity', (done) => { + wrapper = mount(Quantity, { + propsData: { + disabled: true + } + }); + + expect(wrapper.hasClass('zan-quantity')).to.be.true; + const minusButton = wrapper.find('.zan-quantity__minus')[0]; + expect(minusButton.hasClass('zan-quantity__minus--disabled')).to.be.true; + + const eventStub = sinon.stub(wrapper.vm, '$emit'); + minusButton.simulate('click'); + + wrapper.update(); + wrapper.vm.$nextTick(() => { + expect(eventStub.calledWith('overlimit')); + done(); + }); + + const plusButton = wrapper.find('.zan-quantity__plus')[0]; + expect(plusButton.hasClass('zan-quantity__plus--disabled')).to.be.true; + + plusButton.simulate('click'); + + wrapper.update(); + wrapper.vm.$nextTick(() => { + expect(eventStub.calledWith('overlimit')); + done(); + }); + }); + + it('update quantity value use v-model', (done) => { + wrapper = mount(Quantity, { + propsData: { + value: 1 + } + }); + + expect(wrapper.hasClass('zan-quantity')).to.be.true; + const eventStub = sinon.stub(wrapper.vm, '$emit'); + + wrapper.vm.value = 2; + wrapper.update(); + wrapper.vm.$nextTick(() => { + expect(eventStub.calledWith('input')); + expect(eventStub.calledWith('change')); + done(); + }); + }); + + it('correct value when value is not correct', (done) => { + wrapper = mount(Quantity, { + propsData: { + value: 50, + max: 30 + } + }); + + expect(wrapper.hasClass('zan-quantity')).to.be.true; + const eventStub = sinon.stub(wrapper.vm, '$emit'); + wrapper.update(); + wrapper.vm.$nextTick(() => { + expect(eventStub.calledWith('input')); + done(); + }); + }); + + it('handle when input change', (done) => { + wrapper = mount(Quantity, { + propsData: { + value: 1 + } + }); + + const input = wrapper.find('.zan-quantity__input')[0]; + input.element.value = 2; + input.simulate('input'); + + wrapper.update(); + wrapper.vm.$nextTick(() => { + expect(wrapper.data().currentValue).to.equal(2); + done(); + }); }); });