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/field.spec.js b/test/unit/specs/field.spec.js index 2c6342f3f..a41a2f2fc 100644 --- a/test/unit/specs/field.spec.js +++ b/test/unit/specs/field.spec.js @@ -40,14 +40,16 @@ describe('Field', () => { }); }); - it('input some value to filed', (done) => { + it('focus on input', (done) => { wrapper = mount(Field, { - propsData: {} + propsData: { + value: '' + } }); const eventStub = sinon.stub(wrapper.vm, '$emit'); const input = wrapper.find('.zan-field__control')[0]; - input.element.focus(); + input.simulate('focus'); wrapper.update(); wrapper.vm.$nextTick(() => { @@ -56,6 +58,25 @@ describe('Field', () => { }); }); + it('input something to field', (done) => { + wrapper = mount(Field, { + propsData: { + value: '' + } + }); + + const input = wrapper.find('.zan-field__control')[0]; + + input.element.value = 'test'; + input.simulate('input'); + + wrapper.update(); + wrapper.vm.$nextTick(() => { + expect(wrapper.data().currentValue).to.equal('test'); + done(); + }); + }); + it('create a textarea field', () => { wrapper = mount(Field, { propsData: { @@ -68,7 +89,7 @@ describe('Field', () => { expect(wrapper.hasClass('zan-field--hastextarea')).to.be.true; }); - it('create a autosize textarea field', () => { + it('create a autosize textarea field', (done) => { wrapper = mount(Field, { propsData: { type: 'textarea', @@ -78,5 +99,20 @@ describe('Field', () => { expect(wrapper.hasClass('zan-field')).to.be.true; expect(wrapper.hasClass('zan-field--autosize')).to.be.true; + + const textarea = wrapper.find('.zan-field__control')[0]; + const textareaElement = textarea.element; + const textAreaDiff = (parseInt(textareaElement.style.paddingBottom, 10) + + parseInt(textareaElement.style.paddingTop, 10)) || 0; + + textareaElement.value = 'test'; + textarea.simulate('input'); + + wrapper.update(); + wrapper.vm.$nextTick(() => { + expect(wrapper.data().currentValue).to.equal('test'); + expect(textareaElement.style.height).to.equal((textareaElement.scrollHeight - textAreaDiff) + 'px'); + done(); + }); }); }); 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(); + }); }); });