Skip to content

Commit

Permalink
add unit test for select
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbingchang committed Mar 23, 2017
1 parent c6c1446 commit bdaa06a
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions lib/Select/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,30 @@ describe('Select', () => {
activeItem.triggerHandler('click');
//高亮item
expect(activeItem.hasClass('active')).to.be.true;
//测试ngmodel
//expect($rootScope.city).to.equal($rootScope.data[index]);
})

it('可以设置ngModel的值,来改变view',()=>{
/**
* 模拟打开,并且选中一个选项
*/
let index = 2;
let items = finder.items();
finder.find('.f-input').triggerHandler('click');
expect(finder.find('.f-select').hasClass('active')).to.be.true;
let activeItem = angular.element(items[index]);
activeItem.triggerHandler('click');

/**
* 选中一个“上海周浦万达广场”
*/
expect(finder.find('.f-input_inner').val()).to.equal($rootScope.data[index].name);

/**
* 设置city.id =1001, name=北京通州万达广场;
*/
$rootScope.city = $rootScope.data[0];
$rootScope.$digest()
expect(finder.find('.f-input_inner').val()).to.equal($rootScope.data[0].name);
})

})
Expand Down Expand Up @@ -277,7 +299,6 @@ describe('Select', () => {
* 点击组件,会再次关闭菜单
*/
finder.find('.f-input').triggerHandler('click');
console.log(selectElement.hasClass('active'))
expect(selectElement.hasClass('active')).to.be.false;

/**
Expand All @@ -297,8 +318,8 @@ describe('Select', () => {
let activeItem = angular.element(items[0]);
activeItem.triggerHandler('click');
expect(activeItem.hasClass('active')).to.be.false;
}));

}))
})

describe('测试 is-multiple', () => {
Expand Down

0 comments on commit bdaa06a

Please sign in to comment.