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

Commit 90855b9

Browse files
committed
test(select): add tests for form control interpolation in selectDirective
1 parent 1b59793 commit 90855b9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/ng/directive/selectSpec.js

+41
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,47 @@ describe('select', function() {
148148
});
149149

150150

151+
it('should interpolate select names (number)', function() {
152+
scope.robots = ['c3p0', 'r2d2'];
153+
scope.name = 'r2d2';
154+
scope.nameID = 47;
155+
compile('<select ng-model="name" name="name{{nameID}}">' +
156+
'<option ng-repeat="r in robots">{{r}}</option>' +
157+
'</select>');
158+
expect(scope.form.name47.$pristine).toBeTruthy();
159+
browserTrigger(element.find('option').eq(0));
160+
expect(scope.form.name47.$dirty).toBeTruthy();
161+
expect(scope.name).toBe('c3p0');
162+
});
163+
164+
165+
it('should interpolate select names (undefined)', function() {
166+
scope.robots = ['c3p0', 'r2d2'];
167+
scope.name = 'r2d2';
168+
scope.nameID = undefined;
169+
compile('<select ng-model="name" name="name{{nameID}}">' +
170+
'<option ng-repeat="r in robots">{{r}}</option>' +
171+
'</select>');
172+
expect(scope.form.name.$pristine).toBeTruthy();
173+
browserTrigger(element.find('option').eq(0));
174+
expect(scope.form.name.$dirty).toBeTruthy();
175+
expect(scope.name).toBe('c3p0');
176+
});
177+
178+
179+
it('should rename select controls in form when interpolated name changes', function() {
180+
scope.nameID = "A";
181+
compile('<select ng-model="name" name="name{{nameID}}"></select>');
182+
expect(scope.form.nameA.$name).toBe('nameA');
183+
var oldModel = scope.form.nameA;
184+
scope.nameID = "B";
185+
scope.$digest();
186+
expect(scope.form.nameA).toBeUndefined();
187+
expect(scope.form.nameB).toBe(oldModel);
188+
expect(scope.form.nameB.$name).toBe('nameB');
189+
});
190+
191+
151192
describe('empty option', function() {
152193

153194
it('should select the empty option when model is undefined', function() {

0 commit comments

Comments
 (0)