Merge branch 'master' of gitlab.qima-inc.com:fe/zanui-vue

This commit is contained in:
pangxie1991 2017-04-17 11:03:19 +08:00
commit f42ea02337
5 changed files with 150 additions and 115 deletions

View File

@ -70,10 +70,7 @@ export default {
cols: [String, Number], cols: [String, Number],
autosize: { autosize: {
type: Boolean, type: Boolean,
default: false, default: false
validator(value) {
if (value && this.type !== 'textarea') return false;
}
} }
}, },

View File

@ -0,0 +1,24 @@
<template>
<zan-badge-group>
<zan-badge title="热销榜" info="8" @click="onItemClick"></zan-badge>
<zan-badge title="手握寿司" info="199" @click="onItemClick"></zan-badge>
</zan-badge-group>
</template>
<script>
import Badge from 'packages/badge';
import BadgeGroup from 'packages/badge-group';
export default {
components: {
'zan-badge': Badge,
'zan-badge-group': BadgeGroup
},
methods: {
onItemClick() {
console.log('click');
}
}
};
</script>

View File

@ -1,6 +1,5 @@
// import Badge from 'packages/badge';
import BadgeGroup from 'packages/badge-group';
import { mount } from 'avoriaz'; import { mount } from 'avoriaz';
import BadgeTestComponent from '../components/badge';
describe('BadgeGroup', () => { describe('BadgeGroup', () => {
let wrapper; let wrapper;
@ -9,10 +8,22 @@ describe('BadgeGroup', () => {
}); });
it('create a badge-group', () => { it('create a badge-group', () => {
wrapper = mount(BadgeGroup); wrapper = mount(BadgeTestComponent);
expect(wrapper.hasClass('zan-badge-group')).to.be.true; expect(wrapper.hasClass('zan-badge-group')).to.be.true;
expect(wrapper.instance().activeKey).to.equal(0);
expect(wrapper.data().badges.length).to.equal(0); expect(wrapper.vNode.child.activeKey).to.equal(0);
expect(wrapper.vNode.child.badges.length).to.equal(2);
});
it('emit a click event when click badge', () => {
wrapper = mount(BadgeTestComponent);
const badge = wrapper.find('.zan-badge')[0];
const eventStub = sinon.stub(badge.vNode.child, '$emit');
badge.simulate('click');
expect(eventStub.calledWith('click')).to.be.true;
}); });
}); });

View File

@ -1,51 +1,51 @@
import Checkbox from 'packages/checkbox'; // import Checkbox from 'packages/checkbox';
import CheckboxGroup from 'packages/checkbox-group'; // import CheckboxGroup from 'packages/checkbox-group';
import { mount } from 'avoriaz'; // import { mount } from 'avoriaz';
describe('Checkbox', () => { // describe('Checkbox', () => {
let wrapper; // let wrapper;
afterEach(() => { // afterEach(() => {
wrapper && wrapper.destroy(); // wrapper && wrapper.destroy();
}); // });
it('create a checkbox', () => { // it('create a checkbox', () => {
wrapper = mount(Checkbox, { // wrapper = mount(Checkbox, {
propsData: {} // propsData: {}
}); // });
expect(wrapper.hasClass('zan-checkbox')).to.be.true; // expect(wrapper.hasClass('zan-checkbox')).to.be.true;
}); // });
}); // });
describe('CheckboxGroup', () => { // describe('CheckboxGroup', () => {
let wrapper; // let wrapper;
afterEach(() => { // afterEach(() => {
wrapper && wrapper.destroy(); // wrapper && wrapper.destroy();
}); // });
it('create a checkbox-group', () => { // it('create a checkbox-group', () => {
wrapper = mount(CheckboxGroup, { // wrapper = mount(CheckboxGroup, {
propsData: {} // propsData: {}
}); // });
expect(wrapper.hasClass('zan-checkbox-group')).to.be.true; // expect(wrapper.hasClass('zan-checkbox-group')).to.be.true;
}); // });
// it('emit a change event', () => { // // it('emit a change event', () => {
// wrapper = mount(CheckboxGroup, { // // wrapper = mount(CheckboxGroup, {
// propsData: { // // propsData: {
// value: false // // value: false
// } // // }
// }); // // });
// const eventStub = sinon.stub(wrapper.vm, '$emit'); // // const eventStub = sinon.stub(wrapper.vm, '$emit');
// wrapper.vm.value = true; // // wrapper.vm.value = true;
// wrapper.update(); // // wrapper.update();
// Vue.nextTick(() => { // // Vue.nextTick(() => {
// expect(eventStub.calledOnce).to.be.true; // // expect(eventStub.calledOnce).to.be.true;
// expect(eventStub.calledWith('change')); // // expect(eventStub.calledWith('change'));
// done(); // // done();
// }); // // });
// }); // // });
}); // });

View File

@ -1,80 +1,83 @@
// import Vue from 'vue'; import Field from 'packages/field';
// import Field from 'packages/field'; import { mount } from 'avoriaz';
// import { mount } from 'avoriaz';
// describe('Field', () => { describe('Field', () => {
// let wrapper; let wrapper;
// afterEach(() => { afterEach(() => {
// wrapper && wrapper.destroy(); wrapper && wrapper.destroy();
// }); });
// it('create a text field', () => { it('create a text field', () => {
// wrapper = mount(Field, { wrapper = mount(Field, {
// propsData: {} propsData: {
// }); type: 'text',
autosize: false
}
});
// expect(wrapper.hasClass('zan-field')).to.be.true; expect(wrapper.hasClass('zan-field')).to.be.true;
// }); expect(wrapper.propsData().type).to.equal('text');
});
// it('create a text field with initialize value', (done) => { it('create a text field with initialize value', () => {
// wrapper = mount(Field, { // wrapper = mount(Field, {
// propsData: { // propsData: {
// value: 'test' // value: 'test'
// } // }
// }); // });
// expect(wrapper.hasClass('zan-field')).to.be.true; // expect(wrapper.hasClass('zan-field')).to.be.true;
// expect(wrapper.data().currentValue).to.equal('test'); // expect(wrapper.data().currentValue).to.equal('test');
// const eventStub = sinon.stub(wrapper.vm, '$emit'); // const eventStub = sinon.stub(wrapper.vm, '$emit');
// wrapper.vm.value = 'test2'; // wrapper.vm.value = 'test2';
// wrapper.update(); // wrapper.update();
// Vue.nextTick(() => { // wrapper.vm.$nextTick(() => {
// expect(wrapper.data().currentValue).to.equal('test2'); // expect(wrapper.data().currentValue).to.equal('test2');
// expect(eventStub.calledOnce).to.be.true; // expect(eventStub.calledOnce).to.be.true;
// expect(eventStub.calledWith('input')); // expect(eventStub.calledWith('input'));
// done(); // done();
// }); // });
// }); });
// it('emit a focus event', () => { it('emit a focus event', () => {
// wrapper = mount(Field, { // wrapper = mount(Field, {
// propsData: {} // propsData: {}
// }); // });
// const input = wrapper.find('.zan-field__control')[0]; // const input = wrapper.find('.zan-field__control')[0];
// const eventStub = sinon.stub(wrapper.vm, '$emit'); // const eventStub = sinon.stub(wrapper.vm, '$emit');
// input.simulate('focus'); // input.simulate('focus');
// expect(eventStub.calledOnce).to.be.true; // expect(eventStub.calledOnce).to.be.true;
// expect(eventStub.calledWith('focus')).to.be.true; // expect(eventStub.calledWith('focus')).to.be.true;
// }); });
// it('input some value to filed', () => { it('input some value to filed', () => {
// // wrapper = mount(Field, { // wrapper = mount(Field, {
// // propsData: {} // propsData: {}
// // }); // });
// // const input = wrapper.find('.zan-field__control')[0]; // const input = wrapper.find('.zan-field__control')[0];
// // input.element.value = 'test'; // input.element.value = 'test';
// // wrapper.update(); // wrapper.update();
// // Vue.nextTick(() => { // wrapper.vm.$nextTick(() => {
// // expect(wrapper.data().currentValue).to.equal('test'); // expect(wrapper.data().currentValue).to.equal('test');
// // done(); // done();
// // }); // });
// }); });
// it('create a textarea field', () => { it('create a textarea field', () => {
// wrapper = mount(Field, { // wrapper = mount(Field, {
// propsData: { // propsData: {
// type: 'textarea', // type: 'textarea',
// autosize: false // autosize: false
// } // }
// }); // });
// expect(wrapper.hasClass('zan-field--hastextarea')).to.be.true; // expect(wrapper.hasClass('zan-field--hastextarea')).to.be.true;
// }); });
// }); });