quantity test

This commit is contained in:
cookfront 2017-04-18 14:58:54 +08:00
parent f9847b2558
commit a5721be72f
3 changed files with 103 additions and 2 deletions

View File

@ -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);
});

View File

@ -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",

View File

@ -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();
});
});
});