From e20e9a795cb5cc208d938ca8e94b5ef8219c0fda Mon Sep 17 00:00:00 2001 From: Stephen Merity Date: Mon, 3 Jun 2013 18:09:36 +1000 Subject: [PATCH] fix(ngScenario): select(...).option(val) should select 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. --- src/ngScenario/dsl.js | 7 ++++++- test/ngScenario/dslSpec.js | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/ngScenario/dsl.js b/src/ngScenario/dsl.js index 67a56af90b9d..becd13a5fc2c 100644 --- a/src/ngScenario/dsl.js +++ b/src/ngScenario/dsl.js @@ -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 { diff --git a/test/ngScenario/dslSpec.js b/test/ngScenario/dslSpec.js index d89d6ebf78c5..7796be702d65 100644 --- a/test/ngScenario/dslSpec.js +++ b/test/ngScenario/dslSpec.js @@ -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( '' + + ' ' + + ' ' + + ' ' + + ' ' + + '' + ); + $root.dsl.select('test').option('one'); + expect(doc.find('[ng-model="test"]').val()).toEqual('D'); + }); - - - it('should select option by name', function() { + it('should select option by name if no exact match and name contains value', function() { doc.append( '' ); $root.dsl.select('test').option('one');