Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngScenario): select(...).option(val) should select exact value match #2856

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ngScenario/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 16 additions & 4 deletions test/ngScenario/dslSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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">' +
Expand All @@ -238,14 +239,25 @@ describe("angular.scenario.dsl", function() {
expect(doc.find('[x-ng-model="test"]').val()).toEqual('A');
});

it('should select option by exact name', 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>' +
' <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', function() {
it('should select option by name if no exact match and name contains value', 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>' +
'</select>'
);
$root.dsl.select('test').option('one');
Expand Down