mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 11:37:38 +08:00
fix(select): make ctrl.hasOption method consistent
Prior to this fix, options added to a select by ngOptions would not cause `selectCtrl.hasOption` to return `true` Closes #8761
This commit is contained in:
@@ -405,6 +405,39 @@ describe('select', function() {
|
||||
expect(element).toEqualSelect(['? string:r2d2 ?']);
|
||||
expect(scope.robot).toBe('r2d2');
|
||||
});
|
||||
|
||||
describe('selectController.hasOption', function() {
|
||||
it('should return true for options added via ngOptions', function() {
|
||||
scope.robots = [
|
||||
{key: 1, value: 'c3p0'},
|
||||
{key: 2, value: 'r2d2'}
|
||||
];
|
||||
scope.robot = 'r2d2';
|
||||
|
||||
compile('<select ng-model="robot" ' +
|
||||
'ng-options="item.key as item.value for item in robots">' +
|
||||
'</select>');
|
||||
|
||||
var selectCtrl = element.data().$selectController;
|
||||
|
||||
expect(selectCtrl.hasOption('c3p0')).toBe(true);
|
||||
expect(selectCtrl.hasOption('r2d2')).toBe(true);
|
||||
|
||||
scope.$apply(function() {
|
||||
scope.robots.pop();
|
||||
});
|
||||
|
||||
expect(selectCtrl.hasOption('c3p0')).toBe(true);
|
||||
expect(selectCtrl.hasOption('r2d2')).toBe(false);
|
||||
|
||||
scope.$apply(function() {
|
||||
scope.robots.push({key: 2, value: 'r2d2'});
|
||||
});
|
||||
|
||||
expect(selectCtrl.hasOption('c3p0')).toBe(true);
|
||||
expect(selectCtrl.hasOption('r2d2')).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -481,6 +514,39 @@ describe('select', function() {
|
||||
expect(element).toBeValid();
|
||||
expect(element).toBeDirty();
|
||||
});
|
||||
|
||||
describe('selectController.hasOption', function() {
|
||||
it('should return true for options added via ngOptions', function() {
|
||||
scope.robots = [
|
||||
{key: 1, value: 'c3p0'},
|
||||
{key: 2, value: 'r2d2'}
|
||||
];
|
||||
scope.robot = 'r2d2';
|
||||
|
||||
compile('<select ng-model="robot" multiple ' +
|
||||
'ng-options="item.key as item.value for item in robots">' +
|
||||
'</select>');
|
||||
|
||||
var selectCtrl = element.data().$selectController;
|
||||
|
||||
expect(selectCtrl.hasOption('c3p0')).toBe(true);
|
||||
expect(selectCtrl.hasOption('r2d2')).toBe(true);
|
||||
|
||||
scope.$apply(function() {
|
||||
scope.robots.pop();
|
||||
});
|
||||
|
||||
expect(selectCtrl.hasOption('c3p0')).toBe(true);
|
||||
expect(selectCtrl.hasOption('r2d2')).toBe(false);
|
||||
|
||||
scope.$apply(function() {
|
||||
scope.robots.push({key: 2, value: 'r2d2'});
|
||||
});
|
||||
|
||||
expect(selectCtrl.hasOption('c3p0')).toBe(true);
|
||||
expect(selectCtrl.hasOption('r2d2')).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user