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

Commit bb7209d

Browse files
committed
fix jquery tests and add missing test for multiple
1 parent 61e9d47 commit bb7209d

File tree

1 file changed

+72
-6
lines changed

1 file changed

+72
-6
lines changed

test/ng/directive/selectSpec.js

+72-6
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ describe('select', function() {
15921592
});
15931593

15941594

1595-
they('should select a disabled option when the model is set to the matching value',
1595+
they('should select a disabled option with $prop when the model is set to the matching value',
15961596
[
15971597
'ngValue',
15981598
'interpolatedValue',
@@ -1628,20 +1628,23 @@ describe('select', function() {
16281628
expect(optionElements.length).toEqual(4);
16291629
expect(optionElements[0].value).toEqual(unknownValue(undefined));
16301630

1631-
A.disabled = true;
1631+
B.disabled = true;
16321632
scope.$digest();
16331633

16341634
var optionElements = element.find('option');
16351635
expect(optionElements.length).toEqual(4);
16361636
expect(optionElements[0].value).toEqual(unknownValue(undefined));
16371637

1638-
scope.obj.value = 'A';
1638+
scope.obj.value = 'B';
16391639
scope.$digest();
16401640

16411641
optionElements = element.find('option');
16421642
expect(optionElements.length).toEqual(3);
1643-
expect(scope.obj.value).toBe('A');
1644-
expect(element.val()).toBe(prop === 'ngValue' ? 'string:A' : 'A');
1643+
expect(scope.obj.value).toBe('B');
1644+
// jQuery returns null for val() when the option is disabled, see
1645+
// https://bugs.jquery.com/ticket/13097
1646+
expect(element[0].value).toBe(prop === 'ngValue' ? 'string:B' : 'B');
1647+
expect(optionElements.eq(1).prop('selected')).toBe(true);
16451648
});
16461649

16471650

@@ -1931,7 +1934,7 @@ describe('select', function() {
19311934

19321935
});
19331936

1934-
they('should set the model to null when the currently selected option with $prop is disabled',
1937+
they('should set the model to null when the currently selected option with $prop becomes disabled',
19351938
[
19361939
'ngValue',
19371940
'interpolatedValue',
@@ -1991,6 +1994,69 @@ describe('select', function() {
19911994
});
19921995

19931996

1997+
they('should select disabled options with $prop when the model is set to matching values',
1998+
[
1999+
'ngValue',
2000+
'interpolatedValue',
2001+
'interpolatedText'
2002+
], function(prop) {
2003+
2004+
var A = { name: 'A'}, B = { name: 'B'}, C = { name: 'C'}, D = {name: 'D'};
2005+
2006+
scope.options = [A, B, C, D];
2007+
scope.obj = {};
2008+
2009+
var optionString = '';
2010+
2011+
switch (prop) {
2012+
case 'ngValue':
2013+
optionString = '<option ng-repeat="option in options" ng-disabled="option.disabled" ng-value="option">{{$index}}</option>';
2014+
break;
2015+
case 'interpolatedValue':
2016+
optionString = '<option ng-repeat="option in options" ng-disabled="option.disabled" value="{{option.name}}">{{$index}}</option>';
2017+
break;
2018+
case 'interpolatedText':
2019+
optionString = '<option ng-repeat="option in options" ng-disabled="option.disabled">{{option.name}}</option>';
2020+
break;
2021+
}
2022+
2023+
compile(
2024+
'<select ng-model="obj.value" multiple>' +
2025+
optionString +
2026+
'</select>'
2027+
);
2028+
2029+
var optionElements = element.find('option');
2030+
expect(optionElements.length).toEqual(4);
2031+
expect(element[0].value).toBe('');
2032+
2033+
A.disabled = true;
2034+
D.disabled = true;
2035+
scope.$digest();
2036+
2037+
var optionElements = element.find('option');
2038+
expect(optionElements.length).toEqual(4);
2039+
expect(element[0].value).toBe('');
2040+
2041+
scope.obj.value = prop === 'ngValue' ? [A, C, D] : ['A', 'C', 'D'];
2042+
scope.$digest();
2043+
2044+
optionElements = element.find('option');
2045+
expect(optionElements.length).toEqual(4);
2046+
expect(scope.obj.value).toEqual(prop === 'ngValue' ?
2047+
[
2048+
{name: 'A', $$hashKey: 'object:4', disabled: true},
2049+
{name: 'C', $$hashKey: 'object:6'},
2050+
{name: 'D', $$hashKey: 'object:7', disabled: true}
2051+
] :
2052+
['A', 'C', 'D']
2053+
);
2054+
2055+
expect(optionElements.eq(0).prop('selected')).toBe(true);
2056+
expect(optionElements.eq(2).prop('selected')).toBe(true);
2057+
expect(optionElements.eq(3).prop('selected')).toBe(true);
2058+
});
2059+
19942060
they('should select a newly added option with $prop when it matches the current model',
19952061
[
19962062
'ngValue',

0 commit comments

Comments
 (0)