support focus and blur event for some form component

This commit is contained in:
Dreamacro
2017-07-17 18:24:24 +08:00
committed by 杨奕
parent 67188f45b6
commit c1829e69f1
15 changed files with 184 additions and 15 deletions

View File

@@ -384,4 +384,60 @@ describe('Autocomplete', () => {
done();
}, 500);
});
it('event:focus & blur', done => {
vm = createVue({
template: `
<el-autocomplete
ref="input"
v-model="state"
:fetch-suggestions="querySearch"
:trigger-on-focus="false"
placeholder="请输入内容autocomplete1"
></el-autocomplete>
`,
data() {
return {
restaurants: [],
state: ''
};
},
methods: {
querySearch(queryString, cb) {
var restaurants = this.restaurants;
var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
cb(results);
},
createFilter(queryString) {
return (restaurant) => {
return (restaurant.value.indexOf(queryString.toLowerCase()) === 0);
};
},
loadAll() {
return [
{ 'value': '三全鲜食(北新泾店)', 'address': '长宁区新渔路144号' },
{ 'value': 'Hot honey 首尔炸鸡(仙霞路)', 'address': '上海市长宁区淞虹路661号' },
{ 'value': '新旺角茶餐厅', 'address': '上海市普陀区真北路988号创邑金沙谷6号楼113' },
{ 'value': '泷千家(天山西路店)', 'address': '天山西路438号' }
];
}
},
mounted() {
this.restaurants = this.loadAll();
}
}, true);
const spyFocus = sinon.spy();
const spyBlur = sinon.spy();
vm.$refs.input.$on('focus', spyFocus);
vm.$refs.input.$on('blur', spyBlur);
vm.$el.querySelector('input').focus();
vm.$el.querySelector('input').blur();
vm.$nextTick(_ => {
expect(spyFocus.calledOnce).to.be.true;
expect(spyBlur.calledOnce).to.be.true;
done();
});
});
});