mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix(ngScenario): select().option(val) should prefer exact value match
With select(...).option(val) it previously would select the first node which contains the value, even if an exact match was available. This fix prefers exact matches if available, otherwise it reverts to the previous 'contains' behaviour for backwards compatibility. Closes #2856
This commit is contained in:
parent
7fef06fef9
commit
22a9b1ac07
2 changed files with 23 additions and 6 deletions
|
|
@ -295,7 +295,12 @@ angular.scenario.dsl('select', function() {
|
|||
if (option.length) {
|
||||
select.val(value);
|
||||
} else {
|
||||
option = select.find('option:contains("' + value + '")');
|
||||
option = select.find('option').filter(function(){
|
||||
return _jQuery(this).text() === value;
|
||||
});
|
||||
if (!option.length) {
|
||||
option = select.find('option:contains("' + value + '")');
|
||||
}
|
||||
if (option.length) {
|
||||
select.val(option.val());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -227,6 +227,7 @@ describe("angular.scenario.dsl", function() {
|
|||
$root.dsl.select('test').option('A');
|
||||
expect(doc.find('[data-ng-model="test"]').val()).toEqual('A');
|
||||
});
|
||||
|
||||
it('should select single option using x-ng', function() {
|
||||
doc.append(
|
||||
'<select x-ng-model="test">' +
|
||||
|
|
@ -238,14 +239,25 @@ describe("angular.scenario.dsl", function() {
|
|||
expect(doc.find('[x-ng-model="test"]').val()).toEqual('A');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
it('should select option by name', function() {
|
||||
it('should select option by exact name', function() {
|
||||
doc.append(
|
||||
'<select ng-model="test">' +
|
||||
' <option value=A>one</option>' +
|
||||
' <option value=A>twenty one</option>' +
|
||||
' <option value=B selected>two</option>' +
|
||||
' <option value=C>thirty one</option>' +
|
||||
' <option value=D>one</option>' +
|
||||
'</select>'
|
||||
);
|
||||
$root.dsl.select('test').option('one');
|
||||
expect(doc.find('[ng-model="test"]').val()).toEqual('D');
|
||||
});
|
||||
|
||||
it('should select option by name if no exact match and name contains value', function() {
|
||||
doc.append(
|
||||
'<select ng-model="test">' +
|
||||
' <option value=A>twenty one</option>' +
|
||||
' <option value=B selected>two</option>' +
|
||||
' <option value=C>thirty one</option>' +
|
||||
'</select>'
|
||||
);
|
||||
$root.dsl.select('test').option('one');
|
||||
|
|
|
|||
Loading…
Reference in a new issue